debugging issues

pull/142/head
vahidrezanezhad 1 week ago
parent e9c0d716f6
commit 0e8c561618

@ -195,6 +195,8 @@ class Eynollah:
logger=None,
pcgts=None,
):
if skip_layout_and_reading_order:
textline_light = True
self.light_version = light_version
if not dir_in:
if image_pil:
@ -1512,7 +1514,7 @@ class Eynollah:
textlines_ins = [polygons_of_textlines[ind] for ind in indexes_in]
all_found_textline_polygons.append(textlines_ins)
slopes.append(0)
slopes.append(slope_deskew)
_, crop_coor = crop_image_inside_box(boxes[index],image_page_rotated)
@ -1527,11 +1529,8 @@ class Eynollah:
results = self.executor.map(partial(do_work_of_slopes_new_light,
textline_mask_tot_ea=textline_mask_tot,
image_page_rotated=image_page_rotated,
slope_deskew=slope_deskew,
MAX_SLOPE=MAX_SLOPE,
KERNEL=KERNEL,
logger=self.logger,
plotter=self.plotter,),
slope_deskew=slope_deskew,textline_light=self.textline_light,
logger=self.logger,),
boxes, contours, contours_par, range(len(contours_par)))
#textline_polygons, boxes, text_regions, text_regions_par, box_coord, index_text_con, slopes = zip(*results)
self.logger.debug("exit get_slopes_and_deskew_new_light")
@ -4245,7 +4244,7 @@ class Eynollah:
def filter_contours_without_textline_inside(self,contours,text_con_org, contours_textline):
def filter_contours_without_textline_inside(self,contours,text_con_org, contours_textline, contours_only_text_parent_d_ordered):
###contours_txtline_of_all_textregions = []
@ -4282,8 +4281,9 @@ class Eynollah:
contours.pop(ind_u_a_trs)
contours_textline.pop(ind_u_a_trs)
text_con_org.pop(ind_u_a_trs)
contours_only_text_parent_d_ordered.pop(ind_u_a_trs)
return contours, text_con_org, contours_textline
return contours, text_con_org, contours_textline, contours_only_text_parent_d_ordered, np.array(range(len(contours)))
def dilate_textlines(self,all_found_textline_polygons):
for j in range(len(all_found_textline_polygons)):
@ -4487,12 +4487,9 @@ class Eynollah:
continue
else:
return pcgts
if self.skip_layout_and_reading_order:
img_res, is_image_enhanced, num_col_classifier, num_column_is_classified = self.run_enhancement(self.light_version)
self.logger.info("Enhancing took %.1fs ", time.time() - t0)
#print("text region early -1 in %.1fs", time.time() - t0)
t1 = time.time()
if self.skip_layout_and_reading_order:
_ ,_, _, textline_mask_tot_ea, img_bin_light = self.get_regions_light_v(img_res, is_image_enhanced, num_col_classifier,
skip_layout_and_reading_order=self.skip_layout_and_reading_order)
@ -4522,16 +4519,20 @@ class Eynollah:
polygons_lines_xml = []
contours_tables = []
ocr_all_textlines = None
pcgts = self.writer.build_pagexml_no_full_layout(cont_page, page_coord, order_text_new, id_of_texts_tot,
all_found_textline_polygons, page_coord, polygons_of_images, polygons_of_marginals,
all_found_textline_polygons_marginals, all_box_coord_marginals, slopes, slopes_marginals,
cont_page, polygons_lines_xml, contours_tables, ocr_all_textlines)
if self.dir_in:
self.writer.write_pagexml(pcgts)
continue
else:
return pcgts
if not self.extract_only_images and not self.skip_layout_and_reading_order:
img_res, is_image_enhanced, num_col_classifier, num_column_is_classified = self.run_enhancement(self.light_version)
self.logger.info("Enhancing took %.1fs ", time.time() - t0)
#print("text region early -1 in %.1fs", time.time() - t0)
t1 = time.time()
if self.light_version:
text_regions_p_1 ,erosion_hurts, polygons_lines_xml, textline_mask_tot_ea, img_bin_light = self.get_regions_light_v(img_res, is_image_enhanced, num_col_classifier)
#print("text region early -2 in %.1fs", time.time() - t0)
@ -4770,7 +4771,7 @@ class Eynollah:
all_found_textline_polygons, boxes_text, txt_con_org, contours_only_text_parent, all_box_coord, index_by_text_par_con, slopes = \
self.get_slopes_and_deskew_new_light2(txt_con_org, contours_only_text_parent, textline_mask_tot_ea_org, image_page_rotated, boxes_text, slope_deskew)
all_found_textline_polygons_marginals, boxes_marginals, _, polygons_of_marginals, all_box_coord_marginals, _, slopes_marginals = \
self.get_slopes_and_deskew_new_light(polygons_of_marginals, polygons_of_marginals, textline_mask_tot_ea_org, image_page_rotated, boxes_marginals, slope_deskew)
self.get_slopes_and_deskew_new_light2(polygons_of_marginals, polygons_of_marginals, textline_mask_tot_ea_org, image_page_rotated, boxes_marginals, slope_deskew)
#slopes, all_found_textline_polygons, boxes_text, txt_con_org, contours_only_text_parent, index_by_text_par_con = \
# self.delete_regions_without_textlines(slopes, all_found_textline_polygons, boxes_text, txt_con_org, contours_only_text_parent, index_by_text_par_con)
@ -4783,7 +4784,7 @@ class Eynollah:
all_found_textline_polygons = self.filter_contours_inside_a_bigger_one(all_found_textline_polygons, textline_mask_tot_ea_org, type_contour="textline")
all_found_textline_polygons_marginals = self.dilate_textregions_contours_textline_version(all_found_textline_polygons_marginals)
contours_only_text_parent, txt_con_org, all_found_textline_polygons = self.filter_contours_without_textline_inside(contours_only_text_parent,txt_con_org, all_found_textline_polygons)
contours_only_text_parent, txt_con_org, all_found_textline_polygons, contours_only_text_parent_d_ordered, index_by_text_par_con = self.filter_contours_without_textline_inside(contours_only_text_parent,txt_con_org, all_found_textline_polygons, contours_only_text_parent_d_ordered)
else:
textline_mask_tot_ea = cv2.erode(textline_mask_tot_ea, kernel=KERNEL, iterations=1)
@ -4885,12 +4886,12 @@ class Eynollah:
ocr_all_textlines = []
else:
ocr_all_textlines = None
pcgts = self.writer.build_pagexml_full_layout(contours_only_text_parent, contours_only_text_parent_h, page_coord, order_text_new, id_of_texts_tot,
all_found_textline_polygons, all_found_textline_polygons_h, all_box_coord, all_box_coord_h, polygons_of_images, contours_tables, polygons_of_drop_capitals, polygons_of_marginals,
all_found_textline_polygons_marginals, all_box_coord_marginals, slopes, slopes_h, slopes_marginals,
cont_page, polygons_lines_xml, ocr_all_textlines)
self.logger.info("Job done in %.1fs", time.time() - t0)
print("Job done in %.1fs", time.time() - t0)
if self.dir_in:
self.writer.write_pagexml(pcgts)
continue

@ -1828,7 +1828,7 @@ def do_work_of_slopes_new_curved(
def do_work_of_slopes_new_light(
box_text, contour, contour_par, index_r_con,
textline_mask_tot_ea, image_page_rotated, slope_deskew,
textline_mask_tot_ea, image_page_rotated, slope_deskew, textline_light,
logger=None
):
if logger is None:
@ -1845,7 +1845,7 @@ def do_work_of_slopes_new_light(
mask_only_con_region = np.zeros(textline_mask_tot_ea.shape)
mask_only_con_region = cv2.fillPoly(mask_only_con_region, pts=[contour_par], color=(1, 1, 1))
if self.textline_light:
if textline_light:
all_text_region_raw = np.copy(textline_mask_tot_ea)
all_text_region_raw[mask_only_con_region == 0] = 0
cnt_clean_rot_raw, hir_on_cnt_clean_rot = return_contours_of_image(all_text_region_raw)
@ -1857,4 +1857,4 @@ def do_work_of_slopes_new_light(
all_text_region_raw[mask_only_con_region == 0] = 0
cnt_clean_rot = textline_contours_postprocessing(all_text_region_raw, slope_deskew, contour_par, box_text)
return cnt_clean_rot, box_text, contour, contour_par, crop_coor, index_r_con, slope
return cnt_clean_rot, box_text, contour, contour_par, crop_coor, index_r_con, slope_deskew

Loading…
Cancel
Save