|
|
|
@ -2212,16 +2212,7 @@ class eynollah:
|
|
|
|
|
self.logger.info("slope_deskew: %s", slope_deskew)
|
|
|
|
|
return slope_deskew, slope_first
|
|
|
|
|
|
|
|
|
|
def run_marginals(
|
|
|
|
|
self,
|
|
|
|
|
image_page,
|
|
|
|
|
textline_mask_tot_ea,
|
|
|
|
|
mask_images,
|
|
|
|
|
mask_lines,
|
|
|
|
|
num_col_classifier,
|
|
|
|
|
slope_deskew,
|
|
|
|
|
text_regions_p_1
|
|
|
|
|
):
|
|
|
|
|
def run_marginals(self, image_page, textline_mask_tot_ea, mask_images, mask_lines, num_col_classifier, slope_deskew, text_regions_p_1):
|
|
|
|
|
image_page_rotated, textline_mask_tot = image_page[:, :], textline_mask_tot_ea[:, :]
|
|
|
|
|
textline_mask_tot[mask_images[:, :] == 1] = 0
|
|
|
|
|
|
|
|
|
@ -2249,47 +2240,8 @@ class eynollah:
|
|
|
|
|
self.plotter.save_plot_of_layout_main(text_regions_p, image_page)
|
|
|
|
|
return textline_mask_tot, text_regions_p, image_page_rotated
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
|
"""
|
|
|
|
|
Get image and scales, then extract the page of scanned image
|
|
|
|
|
"""
|
|
|
|
|
self.logger.debug("enter run")
|
|
|
|
|
is_image_enhanced = False
|
|
|
|
|
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
img_res, is_image_enhanced, num_column_is_classified = self.run_enhancement()
|
|
|
|
|
self.logger.info("Enhancing took %ss ", str(time.time() - t1))
|
|
|
|
|
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
text_regions_p_1 = self.get_regions_from_xy_2models(img_res, is_image_enhanced)
|
|
|
|
|
self.logger.info("Textregion detection took %ss ", str(time.time() - t1))
|
|
|
|
|
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
num_col, num_col_classifier, img_only_regions, page_coord, image_page, mask_images, mask_lines = \
|
|
|
|
|
self.run_graphics_and_columns(text_regions_p_1, num_column_is_classified)
|
|
|
|
|
self.logger.info("Graphics detection took %ss ", str(time.time() - t1))
|
|
|
|
|
|
|
|
|
|
if not num_col:
|
|
|
|
|
self.logger.info("No columns detected, outputting an empty PAGE-XML")
|
|
|
|
|
self.write_into_page_xml([], page_coord, self.dir_out, [], [], [], [], [], [], [], [], self.curved_line, [], [])
|
|
|
|
|
self.logger.info("Job done in %ss", str(time.time() - t1))
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
textline_mask_tot_ea, textline_mask_tot_long_shot = self.run_textline(image_page)
|
|
|
|
|
self.logger.info("textline detection took %ss", str(time.time() - t1))
|
|
|
|
|
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
slope_deskew, slope_first = self.run_deskew(textline_mask_tot_ea)
|
|
|
|
|
self.logger.info("deskewing took %ss", str(time.time() - t1))
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
|
|
|
|
|
textline_mask_tot, text_regions_p, image_page_rotated = self.run_marginals(image_page, textline_mask_tot_ea, mask_images, mask_lines, num_col_classifier, slope_deskew, text_regions_p_1)
|
|
|
|
|
self.logger.info("detection of marginals took %ss", str(time.time() - t1))
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
|
|
|
|
|
if not self.full_layout:
|
|
|
|
|
|
|
|
|
|
def run_boxes_no_full_layout(self, image_page, textline_mask_tot, text_regions_p, slope_deskew, num_col_classifier):
|
|
|
|
|
self.logger.debug('enter run_boxes_no_full_layout')
|
|
|
|
|
if np.abs(slope_deskew) >= SLOPE_THRESHOLD:
|
|
|
|
|
image_page_rotated_n, textline_mask_tot_d, text_regions_p_1_n = rotation_not_90_func(image_page, textline_mask_tot, text_regions_p, slope_deskew)
|
|
|
|
|
text_regions_p_1_n = resize_image(text_regions_p_1_n, text_regions_p.shape[0], text_regions_p.shape[1])
|
|
|
|
@ -2325,27 +2277,24 @@ class eynollah:
|
|
|
|
|
|
|
|
|
|
#regions_without_seperators_d[(random_pixels_for_image[:, :] == 1) & (text_regions_p_1_n[:, :] == 2)] = 1
|
|
|
|
|
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
if np.abs(slope_deskew) < SLOPE_THRESHOLD:
|
|
|
|
|
boxes = return_boxes_of_images_by_order_of_reading_new(spliter_y_new, regions_without_seperators, matrix_of_lines_ch, num_col_classifier)
|
|
|
|
|
else:
|
|
|
|
|
boxes_d = return_boxes_of_images_by_order_of_reading_new(spliter_y_new_d, regions_without_seperators_d, matrix_of_lines_ch_d, num_col_classifier)
|
|
|
|
|
|
|
|
|
|
self.logger.debug("len(boxes): %s", len(boxes))
|
|
|
|
|
self.logger.info("detecting boxes took %ss", str(time.time() - t1))
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
img_revised_tab = text_regions_p[:, :]
|
|
|
|
|
pixel_img = 2
|
|
|
|
|
polygons_of_images = return_contours_of_interested_region(img_revised_tab, pixel_img)
|
|
|
|
|
polygons_of_images = return_contours_of_interested_region(img_revised_tab, 2)
|
|
|
|
|
|
|
|
|
|
# plt.imshow(img_revised_tab)
|
|
|
|
|
# plt.show()
|
|
|
|
|
K.clear_session()
|
|
|
|
|
self.logger.debug('exit run_boxes_no_full_layout')
|
|
|
|
|
return polygons_of_images, img_revised_tab, text_regions_p_1_n, textline_mask_tot_d, regions_without_seperators_d
|
|
|
|
|
|
|
|
|
|
pixel_img = 4
|
|
|
|
|
min_area_mar = 0.00001
|
|
|
|
|
polygons_of_marginals = return_contours_of_interested_region(text_regions_p, pixel_img, min_area_mar)
|
|
|
|
|
|
|
|
|
|
if self.full_layout:
|
|
|
|
|
def run_boxes_full_layout(self, image_page, textline_mask_tot, text_regions_p, slope_deskew, num_col_classifier, img_only_regions):
|
|
|
|
|
self.logger.debug('enter run_boxes_full_layout')
|
|
|
|
|
# set first model with second model
|
|
|
|
|
text_regions_p[:, :][text_regions_p[:, :] == 2] = 5
|
|
|
|
|
text_regions_p[:, :][text_regions_p[:, :] == 3] = 6
|
|
|
|
@ -2417,11 +2366,58 @@ class eynollah:
|
|
|
|
|
K.clear_session()
|
|
|
|
|
gc.collect()
|
|
|
|
|
img_revised_tab = np.copy(text_regions_p[:, :])
|
|
|
|
|
self.logger.info("detection of full layout took %ss", str(time.time() - t1))
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
pixel_img = 5
|
|
|
|
|
polygons_of_images = return_contours_of_interested_region(img_revised_tab, pixel_img)
|
|
|
|
|
self.logger.debug('exit run_boxes_full_layout')
|
|
|
|
|
return polygons_of_images, img_revised_tab, text_regions_p_1_n, textline_mask_tot_d, regions_without_seperators_d, regions_fully
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
|
"""
|
|
|
|
|
Get image and scales, then extract the page of scanned image
|
|
|
|
|
"""
|
|
|
|
|
self.logger.debug("enter run")
|
|
|
|
|
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
img_res, is_image_enhanced, num_column_is_classified = self.run_enhancement()
|
|
|
|
|
self.logger.info("Enhancing took %ss ", str(time.time() - t1))
|
|
|
|
|
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
text_regions_p_1 = self.get_regions_from_xy_2models(img_res, is_image_enhanced)
|
|
|
|
|
self.logger.info("Textregion detection took %ss ", str(time.time() - t1))
|
|
|
|
|
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
num_col, num_col_classifier, img_only_regions, page_coord, image_page, mask_images, mask_lines = \
|
|
|
|
|
self.run_graphics_and_columns(text_regions_p_1, num_column_is_classified)
|
|
|
|
|
self.logger.info("Graphics detection took %ss ", str(time.time() - t1))
|
|
|
|
|
|
|
|
|
|
if not num_col:
|
|
|
|
|
self.logger.info("No columns detected, outputting an empty PAGE-XML")
|
|
|
|
|
self.write_into_page_xml([], page_coord, self.dir_out, [], [], [], [], [], [], [], [], self.curved_line, [], [])
|
|
|
|
|
self.logger.info("Job done in %ss", str(time.time() - t1))
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
textline_mask_tot_ea, textline_mask_tot_long_shot = self.run_textline(image_page)
|
|
|
|
|
self.logger.info("textline detection took %ss", str(time.time() - t1))
|
|
|
|
|
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
slope_deskew, slope_first = self.run_deskew(textline_mask_tot_ea)
|
|
|
|
|
self.logger.info("deskewing took %ss", str(time.time() - t1))
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
|
|
|
|
|
textline_mask_tot, text_regions_p, image_page_rotated = self.run_marginals(image_page, textline_mask_tot_ea, mask_images, mask_lines, num_col_classifier, slope_deskew, text_regions_p_1)
|
|
|
|
|
self.logger.info("detection of marginals took %ss", str(time.time() - t1))
|
|
|
|
|
t1 = time.time()
|
|
|
|
|
|
|
|
|
|
if not self.full_layout:
|
|
|
|
|
polygons_of_images, img_revised_tab, text_regions_p_1_n, textline_mask_tot_d, regions_without_seperators_d = self.run_boxes_no_full_layout(image_page, textline_mask_tot, text_regions_p, slope_deskew, num_col_classifier)
|
|
|
|
|
|
|
|
|
|
pixel_img = 4
|
|
|
|
|
min_area_mar = 0.00001
|
|
|
|
|
polygons_of_marginals = return_contours_of_interested_region(text_regions_p, pixel_img, min_area_mar)
|
|
|
|
|
|
|
|
|
|
if self.full_layout:
|
|
|
|
|
polygons_of_images, img_revised_tab, text_regions_p_1_n, textline_mask_tot_d, regions_without_seperators_d, regions_fully = self.run_boxes_full_layout(image_page, textline_mask_tot, text_regions_p, slope_deskew, num_col_classifier, img_only_regions)
|
|
|
|
|
# plt.imshow(img_revised_tab)
|
|
|
|
|
# plt.show()
|
|
|
|
|
|
|
|
|
|