ocr: make sure that image height or width is not zero

This commit is contained in:
vahidrezanezhad 2025-07-03 15:24:52 +02:00
parent 59ea493803
commit e54ebaa23e
2 changed files with 20 additions and 18 deletions

View file

@ -5436,7 +5436,6 @@ class Eynollah_ocr:
mask_poly = mask_poly[y:y+h, x:x+w, :]
img_crop = img_poly_on_img[y:y+h, x:x+w, :]
#print(file_name, angle_degrees,w*h , mask_poly[:,:,0].sum(), mask_poly[:,:,0].sum() /float(w*h) , 'didi')
if not self.do_not_mask_with_textline_contour:
if angle_degrees > 3:
@ -5483,9 +5482,6 @@ class Eynollah_ocr:
else:
img_crop, _ = break_curved_line_into_small_pieces_and_then_merge(img_crop, mask_poly)
if not self.export_textline_images_and_text:
if w_scaled < 750:#1.5*image_width:
img_fin = preprocess_and_resize_image_for_ocrcnn_model(img_crop, image_height, image_width)

View file

@ -124,6 +124,9 @@ def return_textlines_split_if_needed(textline_image, textline_image_bin, predict
else:
return None, None
def preprocess_and_resize_image_for_ocrcnn_model(img, image_height, image_width):
if img.shape[0]==0 or img.shape[1]==0:
img_fin = np.ones((image_height, image_width, 3))
else:
ratio = image_height /float(img.shape[0])
w_ratio = int(ratio * img.shape[1])
@ -188,7 +191,10 @@ def rotate_image_with_padding(image, angle, border_value=(0,0,0)):
rotation_matrix[1, 2] += (new_h / 2) - center[1]
# Perform the rotation
try:
rotated_image = cv2.warpAffine(image, rotation_matrix, (new_w, new_h), borderValue=border_value)
except:
rotated_image = np.copy(image)
return rotated_image