Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -31,6 +31,7 @@ def draw_boxes(image, bounds, color='yellow', width=2):
|
|
31 |
|
32 |
def inference(filepath, lang):
|
33 |
img = cv2.imread(filepath)
|
|
|
34 |
reader = easyocr.Reader(lang)
|
35 |
bounds = reader.readtext(filepath)
|
36 |
new_bounds=[]
|
@@ -42,9 +43,13 @@ def inference(filepath, lang):
|
|
42 |
bl = (int(bl[0]), int(bl[1]))
|
43 |
|
44 |
min_x = min(tl[0], tr[0], br[0], bl[0])
|
|
|
45 |
max_x = max(tl[0], tr[0], br[0], bl[0])
|
|
|
46 |
min_y = min(tl[1], tr[1], br[1], bl[1])
|
|
|
47 |
max_y = max(tl[1], tr[1], br[1], bl[1])
|
|
|
48 |
# crop the region of interest (ROI)
|
49 |
|
50 |
cropped_image = img[min_y:max_y,min_x:max_x] # crop the image
|
|
|
31 |
|
32 |
def inference(filepath, lang):
|
33 |
img = cv2.imread(filepath)
|
34 |
+
width, height = img.size
|
35 |
reader = easyocr.Reader(lang)
|
36 |
bounds = reader.readtext(filepath)
|
37 |
new_bounds=[]
|
|
|
43 |
bl = (int(bl[0]), int(bl[1]))
|
44 |
|
45 |
min_x = min(tl[0], tr[0], br[0], bl[0])
|
46 |
+
min_x = max(0, min_x)
|
47 |
max_x = max(tl[0], tr[0], br[0], bl[0])
|
48 |
+
max_x = min(width-1, max_x)
|
49 |
min_y = min(tl[1], tr[1], br[1], bl[1])
|
50 |
+
min_y = max(0, min_y)
|
51 |
max_y = max(tl[1], tr[1], br[1], bl[1])
|
52 |
+
max_y = min(height-1, max_y)
|
53 |
# crop the region of interest (ROI)
|
54 |
|
55 |
cropped_image = img[min_y:max_y,min_x:max_x] # crop the image
|