diff --git a/src/eynollah/eynollah.py b/src/eynollah/eynollah.py index 431d8a5..24e859b 100644 --- a/src/eynollah/eynollah.py +++ b/src/eynollah/eynollah.py @@ -982,7 +982,7 @@ class Eynollah: return sorted_textlines - def get_slopes_and_deskew_new_light2(self, contours_par, textline_mask_tot, boxes, slope_deskew): + def get_slopes_and_deskew_new_light2(self, contours_par, textline_mask_tot, slope_deskew): polygons_of_textlines = return_contours_of_interested_region(textline_mask_tot, 1, 0.00001) cx_textlines, cy_textlines = find_center_of_contours(polygons_of_textlines) @@ -1014,7 +1014,7 @@ class Eynollah: return all_found_textline_polygons, slopes - def get_slopes_and_deskew_new_curved(self, contours_par, textline_mask_tot, boxes, + def get_slopes_and_deskew_new_curved(self, contours_par, textline_mask_tot, num_col, slope_deskew, name): if not len(contours_par): return [], [] @@ -1028,7 +1028,7 @@ class Eynollah: logger=self.logger, plotter=self.plotter, name=name), - boxes, contours_par) + contours_par) results = list(results) # exhaust prior to release #textline_polygons, slopes = zip(*results) self.logger.debug("exit get_slopes_and_deskew_new_curved") @@ -2429,20 +2429,16 @@ class Eynollah: conf_textregions = conf_marginals conf_marginals = [] - #print("text region early 4 in %.1fs", time.time() - t0) - boxes_text = get_text_region_boxes_by_given_contours(polygons_of_textregions) - boxes_marginals = get_text_region_boxes_by_given_contours(polygons_of_marginals) - #print("text region early 5 in %.1fs", time.time() - t0) - ## birdan sora chock chakir if not self.curved_line: + self.logger.info("Mode: Light line detection") all_found_textline_polygons, slopes = \ self.get_slopes_and_deskew_new_light2( polygons_of_textregions, textline_mask_tot_ea_org, - boxes_text, slope_deskew) + slope_deskew) all_found_textline_polygons_marginals, slopes_marginals = \ self.get_slopes_and_deskew_new_light2( polygons_of_marginals, textline_mask_tot_ea_org, - boxes_marginals, slope_deskew) + slope_deskew) all_found_textline_polygons = dilate_textline_contours( all_found_textline_polygons) @@ -2457,14 +2453,12 @@ class Eynollah: all_found_textline_polygons, slopes = \ self.get_slopes_and_deskew_new_curved( polygons_of_textregions, textline_mask_tot_ea_erode, - boxes_text, num_col_classifier, slope_deskew, image['name']) all_found_textline_polygons = small_textlines_to_parent_adherence2( all_found_textline_polygons, textline_mask_tot_ea, num_col_classifier) all_found_textline_polygons_marginals, slopes_marginals = \ self.get_slopes_and_deskew_new_curved( polygons_of_marginals, textline_mask_tot_ea_erode, - boxes_marginals, num_col_classifier, slope_deskew, image['name']) all_found_textline_polygons_marginals = small_textlines_to_parent_adherence2( all_found_textline_polygons_marginals, textline_mask_tot_ea, num_col_classifier) @@ -2496,8 +2490,6 @@ class Eynollah: 0.5 * text_regions_p.shape[1]) # FIXME: get_region_confidences w/ textline_confidence on all types of textlines... - #print(len(polygons_of_marginals), len(ordered_left_marginals), len(ordered_right_marginals), 'marginals ordred') - if self.full_layout: (text_regions_p, polygons_of_textregions, diff --git a/src/eynollah/utils/separate_lines.py b/src/eynollah/utils/separate_lines.py index b173d32..4d3f18b 100644 --- a/src/eynollah/utils/separate_lines.py +++ b/src/eynollah/utils/separate_lines.py @@ -1328,8 +1328,8 @@ def separate_lines_vertical_cont(textline_mask, box_ind): return None, contours_final -def textline_contours_postprocessing(textline_mask, angle, contour_parent, box_ind): - x, y, w, h = box_ind +def textline_contours_postprocessing(textline_mask, angle, contour_parent): + x, y, w, h = cv2.boundingRect(contour_parent) label = 255 textline_mask = textline_mask * label kernel = np.ones((5, 5), np.uint8) @@ -1569,7 +1569,7 @@ def get_smallest_skew(img, sigma_des, angles, logger=None, plotter=None, name=No return angle, var def do_work_of_slopes_new_curved( - box_text, contour_par, + contour_par, textline_mask_tot_ea=None, num_col=1, slope_deskew=0.0, logger=None, MAX_SLOPE=999, @@ -1582,7 +1582,7 @@ def do_work_of_slopes_new_curved( logger = getLogger(__package__) logger.debug("enter do_work_of_slopes_new_curved") - x, y, w, h = box_text + x, y, w, h = cv2.boundingRect(contour_par) mask_parent = np.zeros((h, w), dtype=np.uint8) mask_parent = cv2.fillPoly(mask_parent, pts=[contour_par - [x, y]], color=1) @@ -1672,8 +1672,7 @@ def do_work_of_slopes_new_curved( logger.error(why) else: textlines_cnt_per_region = textline_contours_postprocessing(all_text_region_raw, - slope, contour_par, - box_text) + slope, contour_par) return textlines_cnt_per_region[::-1], slope