From d14bd162caa82030a9dee28ec2f063215bd64dce Mon Sep 17 00:00:00 2001 From: vahidrezanezhad Date: Sun, 1 Jun 2025 22:10:13 +0200 Subject: [PATCH] saving enhanced image in org or scaled resolution --- src/eynollah/cli.py | 9 ++++++++- src/eynollah/eynollah.py | 5 ++--- src/eynollah/image_enhancer.py | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/eynollah/cli.py b/src/eynollah/cli.py index 840bc4b..9398c47 100644 --- a/src/eynollah/cli.py +++ b/src/eynollah/cli.py @@ -116,6 +116,12 @@ def binarization(patches, model_dir, input_image, output_image, dir_in, dir_out) "-ncl", help="upper limit of columns in document image", ) +@click.option( + "--save_org_scale/--no_save_org_scale", + "-sos/-nosos", + is_flag=True, + help="if this parameter set to true, this tool will save the enhanced image in org scale.", +) @click.option( "--log_level", "-l", @@ -123,7 +129,7 @@ def binarization(patches, model_dir, input_image, output_image, dir_in, dir_out) help="Override log level globally to this", ) -def enhancement(image, out, overwrite, dir_in, model, num_col_upper, num_col_lower, log_level): +def enhancement(image, out, overwrite, dir_in, model, num_col_upper, num_col_lower, save_org_scale, log_level): initLogging() if log_level: getLogger('enhancement').setLevel(getLevelName(log_level)) @@ -134,6 +140,7 @@ def enhancement(image, out, overwrite, dir_in, model, num_col_upper, num_col_low dir_out=out, num_col_upper=num_col_upper, num_col_lower=num_col_lower, + save_org_scale=save_org_scale, ) if dir_in: enhancer_object.run(dir_in=dir_in, overwrite=overwrite) diff --git a/src/eynollah/eynollah.py b/src/eynollah/eynollah.py index cf540d3..9c834e2 100644 --- a/src/eynollah/eynollah.py +++ b/src/eynollah/eynollah.py @@ -5434,10 +5434,9 @@ class Eynollah_ocr: 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 > 15: + if angle_degrees > 3: better_des_slope = get_orientation_moments(textline_coords) img_crop = rotate_image_with_padding(img_crop, better_des_slope ) @@ -5484,7 +5483,7 @@ class Eynollah_ocr: if not self.export_textline_images_and_text: - if w_scaled < 530:#640:#1.5*image_width: + if w_scaled < 640:#1.5*image_width: img_fin = preprocess_and_resize_image_for_ocrcnn_model(img_crop, image_height, image_width) cropped_lines.append(img_fin) if angle_degrees > 15: diff --git a/src/eynollah/image_enhancer.py b/src/eynollah/image_enhancer.py index 71445f7..c89f532 100644 --- a/src/eynollah/image_enhancer.py +++ b/src/eynollah/image_enhancer.py @@ -41,11 +41,13 @@ class Enhancer: dir_out : Optional[str] = None, num_col_upper : Optional[int] = None, num_col_lower : Optional[int] = None, + save_org_scale : bool = False, logger : Optional[Logger] = None, ): self.dir_out = dir_out self.input_binary = False self.light_version = False + self.save_org_scale = save_org_scale if num_col_upper: self.num_col_upper = int(num_col_upper) else: @@ -750,7 +752,8 @@ class Enhancer: continue image_enhanced = self.run_single() - img_enhanced_org_scale = resize_image(image_enhanced, self.h_org, self.w_org) + if self.save_org_scale: + image_enhanced = resize_image(image_enhanced, self.h_org, self.w_org) - cv2.imwrite(self.output_filename, img_enhanced_org_scale) + cv2.imwrite(self.output_filename, image_enhanced)