Spaces:
Build error
Build error
napatswift
commited on
Commit
•
2dfefac
1
Parent(s):
0ad5782
Change to cpu
Browse files
main.py
CHANGED
@@ -5,9 +5,24 @@ import cv2
|
|
5 |
model_dir = 'model'
|
6 |
ocr = MMOCR(det_config=f'{model_dir}/config.py',
|
7 |
det_ckpt=f'{model_dir}/epoch_40.pth', device='cpu')
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def run():
|
13 |
demo = gr.Interface(
|
|
|
5 |
model_dir = 'model'
|
6 |
ocr = MMOCR(det_config=f'{model_dir}/config.py',
|
7 |
det_ckpt=f'{model_dir}/epoch_40.pth', device='cpu')
|
8 |
+
def get_rec(points):
|
9 |
+
xs = []
|
10 |
+
ys = []
|
11 |
+
for ix, iv in enumerate(points):
|
12 |
+
if ix % 2:
|
13 |
+
ys.append(iv)
|
14 |
+
else:
|
15 |
+
xs.append(iv)
|
16 |
+
return (min(xs), min(ys)), (max(xs), max(ys))
|
17 |
+
|
18 |
+
|
19 |
+
def predict(image_input):
|
20 |
+
draw_img = image_input.copy()
|
21 |
+
output = ocr.readtext(image_input)
|
22 |
+
for polygon in output['det_poloygons']:
|
23 |
+
p0, p1 = get_rec([int(i) for i in polygon])
|
24 |
+
draw_img = cv2.rectangle(draw_img, p0, p1, (255,255,255))
|
25 |
+
return draw_img
|
26 |
|
27 |
def run():
|
28 |
demo = gr.Interface(
|