Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -34,22 +34,18 @@ def inference(filepath, lang):
|
|
34 |
bounds = reader.readtext(filepath)
|
35 |
new_bounds=[]
|
36 |
for (bbox, text, prob) in bounds:
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
# crop the region of interest (ROI)
|
43 |
-
img = Image.open(filepath)
|
44 |
-
#img = img[y0:y1, x0:x1]
|
45 |
-
width, height =img.size
|
46 |
-
cropped_image = img.crop((max(0,x1-5), max(0,y1-5), min(x3+5,width), min(y3+5, height))) # crop the image
|
47 |
-
try:
|
48 |
-
cropped_image = Image.fromarray(cropped_image)
|
49 |
-
except:
|
50 |
-
print('cropping error')
|
51 |
-
continue
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
out = recognitor.predict(cropped_image)
|
54 |
print(out)
|
55 |
new_bounds.append((bbox,text, out, prob))
|
|
|
34 |
bounds = reader.readtext(filepath)
|
35 |
new_bounds=[]
|
36 |
for (bbox, text, prob) in bounds:
|
37 |
+
(tl, tr, br, bl) = bbox
|
38 |
+
tl = (int(tl[0]), int(tl[1]))
|
39 |
+
tr = (int(tr[0]), int(tr[1]))
|
40 |
+
br = (int(br[0]), int(br[1]))
|
41 |
+
bl = (int(bl[0]), int(bl[1]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
+
min_x = min(tl[0], tr[0], br[0], bl[0])
|
44 |
+
max_x = max(tl[0], tr[0], br[0], bl[0])
|
45 |
+
min_y = min(tl[1], tr[1], br[1], bl[1])
|
46 |
+
max_y = max(tl[1], tr[1], br[1], bl[1])
|
47 |
+
# crop the region of interest (ROI)
|
48 |
+
cropped_image = Image.fromarray(img[min_y:max_y,min_x:max_x]) # crop the image
|
49 |
out = recognitor.predict(cropped_image)
|
50 |
print(out)
|
51 |
new_bounds.append((bbox,text, out, prob))
|