Skip to content

Commit c210572

Browse files
committed
fix bug when text box ratio is too slim
1 parent 079499a commit c210572

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

easyocr/utils.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,14 @@ def get_image_list(horizontal_list, free_list, img, model_height = 64, sort_outp
520520
rect = np.array(box, dtype = "float32")
521521
transformed_img = four_point_transform(img, rect)
522522
ratio = transformed_img.shape[1]/transformed_img.shape[0]
523-
crop_img = cv2.resize(transformed_img, (int(model_height*ratio), model_height), interpolation = Image.ANTIALIAS)
524-
image_list.append( (box,crop_img) ) # box = [[x1,y1],[x2,y2],[x3,y3],[x4,y4]]
525-
max_ratio_free = max(ratio, max_ratio_free)
523+
new_width = int(model_height*ratio)
524+
if new_width == 0:
525+
pass
526+
else:
527+
crop_img = cv2.resize(transformed_img, (new_width, model_height), interpolation = Image.ANTIALIAS)
528+
image_list.append( (box,crop_img) ) # box = [[x1,y1],[x2,y2],[x3,y3],[x4,y4]]
529+
max_ratio_free = max(ratio, max_ratio_free)
530+
526531

527532
max_ratio_free = math.ceil(max_ratio_free)
528533

@@ -535,9 +540,13 @@ def get_image_list(horizontal_list, free_list, img, model_height = 64, sort_outp
535540
width = x_max - x_min
536541
height = y_max - y_min
537542
ratio = width/height
538-
crop_img = cv2.resize(crop_img, (int(model_height*ratio), model_height), interpolation = Image.ANTIALIAS)
539-
image_list.append( ( [[x_min,y_min],[x_max,y_min],[x_max,y_max],[x_min,y_max]] ,crop_img) )
540-
max_ratio_hori = max(ratio, max_ratio_hori)
543+
new_width = int(model_height*ratio)
544+
if new_width == 0:
545+
pass
546+
else:
547+
crop_img = cv2.resize(crop_img, (new_width, model_height), interpolation = Image.ANTIALIAS)
548+
image_list.append( ( [[x_min,y_min],[x_max,y_min],[x_max,y_max],[x_min,y_max]] ,crop_img) )
549+
max_ratio_hori = max(ratio, max_ratio_hori)
541550

542551
max_ratio_hori = math.ceil(max_ratio_hori)
543552
max_ratio = max(max_ratio_hori, max_ratio_free)

0 commit comments

Comments
 (0)