mirror of
https://github.com/qurator-spk/eynollah.git
synced 2026-04-30 19:22:03 +02:00
get_slopes*(): does not need passing boxes separately
This commit is contained in:
parent
869646cbf5
commit
d88bd485ff
2 changed files with 11 additions and 20 deletions
|
|
@ -982,7 +982,7 @@ class Eynollah:
|
||||||
|
|
||||||
return sorted_textlines
|
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)
|
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)
|
cx_textlines, cy_textlines = find_center_of_contours(polygons_of_textlines)
|
||||||
|
|
@ -1014,7 +1014,7 @@ class Eynollah:
|
||||||
|
|
||||||
return all_found_textline_polygons, slopes
|
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):
|
num_col, slope_deskew, name):
|
||||||
if not len(contours_par):
|
if not len(contours_par):
|
||||||
return [], []
|
return [], []
|
||||||
|
|
@ -1028,7 +1028,7 @@ class Eynollah:
|
||||||
logger=self.logger,
|
logger=self.logger,
|
||||||
plotter=self.plotter,
|
plotter=self.plotter,
|
||||||
name=name),
|
name=name),
|
||||||
boxes, contours_par)
|
contours_par)
|
||||||
results = list(results) # exhaust prior to release
|
results = list(results) # exhaust prior to release
|
||||||
#textline_polygons, slopes = zip(*results)
|
#textline_polygons, slopes = zip(*results)
|
||||||
self.logger.debug("exit get_slopes_and_deskew_new_curved")
|
self.logger.debug("exit get_slopes_and_deskew_new_curved")
|
||||||
|
|
@ -2429,20 +2429,16 @@ class Eynollah:
|
||||||
conf_textregions = conf_marginals
|
conf_textregions = conf_marginals
|
||||||
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:
|
if not self.curved_line:
|
||||||
|
self.logger.info("Mode: Light line detection")
|
||||||
all_found_textline_polygons, slopes = \
|
all_found_textline_polygons, slopes = \
|
||||||
self.get_slopes_and_deskew_new_light2(
|
self.get_slopes_and_deskew_new_light2(
|
||||||
polygons_of_textregions, textline_mask_tot_ea_org,
|
polygons_of_textregions, textline_mask_tot_ea_org,
|
||||||
boxes_text, slope_deskew)
|
slope_deskew)
|
||||||
all_found_textline_polygons_marginals, slopes_marginals = \
|
all_found_textline_polygons_marginals, slopes_marginals = \
|
||||||
self.get_slopes_and_deskew_new_light2(
|
self.get_slopes_and_deskew_new_light2(
|
||||||
polygons_of_marginals, textline_mask_tot_ea_org,
|
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 = dilate_textline_contours(
|
||||||
all_found_textline_polygons)
|
all_found_textline_polygons)
|
||||||
|
|
@ -2457,14 +2453,12 @@ class Eynollah:
|
||||||
all_found_textline_polygons, slopes = \
|
all_found_textline_polygons, slopes = \
|
||||||
self.get_slopes_and_deskew_new_curved(
|
self.get_slopes_and_deskew_new_curved(
|
||||||
polygons_of_textregions, textline_mask_tot_ea_erode,
|
polygons_of_textregions, textline_mask_tot_ea_erode,
|
||||||
boxes_text,
|
|
||||||
num_col_classifier, slope_deskew, image['name'])
|
num_col_classifier, slope_deskew, image['name'])
|
||||||
all_found_textline_polygons = small_textlines_to_parent_adherence2(
|
all_found_textline_polygons = small_textlines_to_parent_adherence2(
|
||||||
all_found_textline_polygons, textline_mask_tot_ea, num_col_classifier)
|
all_found_textline_polygons, textline_mask_tot_ea, num_col_classifier)
|
||||||
all_found_textline_polygons_marginals, slopes_marginals = \
|
all_found_textline_polygons_marginals, slopes_marginals = \
|
||||||
self.get_slopes_and_deskew_new_curved(
|
self.get_slopes_and_deskew_new_curved(
|
||||||
polygons_of_marginals, textline_mask_tot_ea_erode,
|
polygons_of_marginals, textline_mask_tot_ea_erode,
|
||||||
boxes_marginals,
|
|
||||||
num_col_classifier, slope_deskew, image['name'])
|
num_col_classifier, slope_deskew, image['name'])
|
||||||
all_found_textline_polygons_marginals = small_textlines_to_parent_adherence2(
|
all_found_textline_polygons_marginals = small_textlines_to_parent_adherence2(
|
||||||
all_found_textline_polygons_marginals, textline_mask_tot_ea, num_col_classifier)
|
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])
|
0.5 * text_regions_p.shape[1])
|
||||||
# FIXME: get_region_confidences w/ textline_confidence on all types of textlines...
|
# 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:
|
if self.full_layout:
|
||||||
(text_regions_p,
|
(text_regions_p,
|
||||||
polygons_of_textregions,
|
polygons_of_textregions,
|
||||||
|
|
|
||||||
|
|
@ -1328,8 +1328,8 @@ def separate_lines_vertical_cont(textline_mask, box_ind):
|
||||||
|
|
||||||
return None, contours_final
|
return None, contours_final
|
||||||
|
|
||||||
def textline_contours_postprocessing(textline_mask, angle, contour_parent, box_ind):
|
def textline_contours_postprocessing(textline_mask, angle, contour_parent):
|
||||||
x, y, w, h = box_ind
|
x, y, w, h = cv2.boundingRect(contour_parent)
|
||||||
label = 255
|
label = 255
|
||||||
textline_mask = textline_mask * label
|
textline_mask = textline_mask * label
|
||||||
kernel = np.ones((5, 5), np.uint8)
|
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
|
return angle, var
|
||||||
|
|
||||||
def do_work_of_slopes_new_curved(
|
def do_work_of_slopes_new_curved(
|
||||||
box_text, contour_par,
|
contour_par,
|
||||||
textline_mask_tot_ea=None,
|
textline_mask_tot_ea=None,
|
||||||
num_col=1, slope_deskew=0.0,
|
num_col=1, slope_deskew=0.0,
|
||||||
logger=None, MAX_SLOPE=999,
|
logger=None, MAX_SLOPE=999,
|
||||||
|
|
@ -1582,7 +1582,7 @@ def do_work_of_slopes_new_curved(
|
||||||
logger = getLogger(__package__)
|
logger = getLogger(__package__)
|
||||||
logger.debug("enter do_work_of_slopes_new_curved")
|
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 = np.zeros((h, w), dtype=np.uint8)
|
||||||
mask_parent = cv2.fillPoly(mask_parent, pts=[contour_par - [x, y]], color=1)
|
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)
|
logger.error(why)
|
||||||
else:
|
else:
|
||||||
textlines_cnt_per_region = textline_contours_postprocessing(all_text_region_raw,
|
textlines_cnt_per_region = textline_contours_postprocessing(all_text_region_raw,
|
||||||
slope, contour_par,
|
slope, contour_par)
|
||||||
box_text)
|
|
||||||
|
|
||||||
return textlines_cnt_per_region[::-1], slope
|
return textlines_cnt_per_region[::-1], slope
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue