Eynollah_ocr: drop fixed input sizes…

- tr-ocr: no need to resize images in advance (done by model, anyway)
- cnn-rnn-ocr: get model size from model's input shape
This commit is contained in:
Robert Sachunsky 2026-06-03 20:59:00 +02:00
parent 24c7d4c277
commit 348ac95ad3

View file

@ -87,7 +87,6 @@ class Eynollah_ocr(Eynollah):
img: MatLike, img: MatLike,
page_tree: ET.ElementTree, page_tree: ET.ElementTree,
page_ns, page_ns,
tr_ocr_input_height_and_width,
) -> EynollahOcrResult: ) -> EynollahOcrResult:
total_bb_coordinates = [] total_bb_coordinates = []
@ -117,20 +116,14 @@ class Eynollah_ocr(Eynollah):
img_crop[mask_poly == 0] = 255 # FIXME: or median color? img_crop[mask_poly == 0] = 255 # FIXME: or median color?
if h > 0.1 * w: if h > 0.1 * w:
cropped_lines.append(resize_image(img_crop, cropped_lines.append(img_crop)
tr_ocr_input_height_and_width,
tr_ocr_input_height_and_width) )
cropped_lines_meging_indexing.append(0) cropped_lines_meging_indexing.append(0)
else: else:
splited_images, _ = return_textlines_split_if_needed(img_crop, None) splited_images, _ = return_textlines_split_if_needed(img_crop, None)
if splited_images: if splited_images:
cropped_lines.append(resize_image(splited_images[0], cropped_lines.append(splited_images[0])
tr_ocr_input_height_and_width, cropped_lines.append(splited_images[1])
tr_ocr_input_height_and_width))
cropped_lines_meging_indexing.append(1) cropped_lines_meging_indexing.append(1)
cropped_lines.append(resize_image(splited_images[1],
tr_ocr_input_height_and_width,
tr_ocr_input_height_and_width))
cropped_lines_meging_indexing.append(-1) cropped_lines_meging_indexing.append(-1)
else: else:
cropped_lines.append(img_crop) cropped_lines.append(img_crop)
@ -172,9 +165,8 @@ class Eynollah_ocr(Eynollah):
img_bin: Optional[MatLike], img_bin: Optional[MatLike],
page_tree: ET.ElementTree, page_tree: ET.ElementTree,
page_ns, page_ns,
image_width,
image_height,
) -> EynollahOcrResult: ) -> EynollahOcrResult:
_, image_height, image_width, _ = self.model_zoo.get('ocr').input_shape
total_bb_coordinates = [] total_bb_coordinates = []
cropped_lines_rgb = [] cropped_lines_rgb = []
@ -482,18 +474,13 @@ class Eynollah_ocr(Eynollah):
img=img, img=img,
page_tree=page_tree, page_tree=page_tree,
page_ns=page_ns, page_ns=page_ns,
tr_ocr_input_height_and_width = 384
) )
else: else:
result = self.run_cnn( result = self.run_cnn(
img=img, img=img,
page_tree=page_tree, page_tree=page_tree,
page_ns=page_ns, page_ns=page_ns,
img_bin=img_bin, img_bin=img_bin,
image_width=512,
image_height=32,
) )
self.write_ocr( self.write_ocr(