pull/42/head
vahid 4 years ago
parent c4b2c71e68
commit 799a7c7632

@ -159,6 +159,9 @@ class Eynollah:
key += '_uint8' key += '_uint8'
return self._imgs[key].copy() return self._imgs[key].copy()
def isNaN(self, num):
return num != num
def predict_enhancement(self, img): def predict_enhancement(self, img):
self.logger.debug("enter predict_enhancement") self.logger.debug("enter predict_enhancement")
@ -920,16 +923,16 @@ class Eynollah:
textline_con, hierarchy = return_contours_of_image(img_int_p) textline_con, hierarchy = return_contours_of_image(img_int_p)
textline_con_fil = filter_contours_area_of_image(img_int_p, textline_con, hierarchy, max_area=1, min_area=0.0008) textline_con_fil = filter_contours_area_of_image(img_int_p, textline_con, hierarchy, max_area=1, min_area=0.0008)
y_diff_mean = find_contours_mean_y_diff(textline_con_fil) y_diff_mean = find_contours_mean_y_diff(textline_con_fil)
if self.isNaN(y_diff_mean):
slope_for_all = MAX_SLOPE
else:
sigma_des = max(1, int(y_diff_mean * (4.0 / 40.0))) sigma_des = max(1, int(y_diff_mean * (4.0 / 40.0)))
img_int_p[img_int_p > 0] = 1 img_int_p[img_int_p > 0] = 1
slope_for_all = return_deskew_slop(img_int_p, sigma_des, plotter=self.plotter) slope_for_all = return_deskew_slop(img_int_p, sigma_des, plotter=self.plotter)
if abs(slope_for_all) < 0.5: if abs(slope_for_all) < 0.5:
slope_for_all = [slope_deskew][0] slope_for_all = [slope_deskew][0]
# old method
# slope_for_all=self.textline_contours_to_get_slope_correctly(self.all_text_region_raw[mv],denoised,contours[mv])
# text_patch_processed=textline_contours_postprocessing(gada)
except Exception as why: except Exception as why:
self.logger.error(why) self.logger.error(why)
slope_for_all = MAX_SLOPE slope_for_all = MAX_SLOPE
@ -1031,6 +1034,9 @@ class Eynollah:
textline_con, hierarchy = return_contours_of_image(img_int_p) textline_con, hierarchy = return_contours_of_image(img_int_p)
textline_con_fil = filter_contours_area_of_image(img_int_p, textline_con, hierarchy, max_area=1, min_area=0.00008) textline_con_fil = filter_contours_area_of_image(img_int_p, textline_con, hierarchy, max_area=1, min_area=0.00008)
y_diff_mean = find_contours_mean_y_diff(textline_con_fil) y_diff_mean = find_contours_mean_y_diff(textline_con_fil)
if self.isNaN(y_diff_mean):
slope_for_all = MAX_SLOPE
else:
sigma_des = int(y_diff_mean * (4.0 / 40.0)) sigma_des = int(y_diff_mean * (4.0 / 40.0))
if sigma_des < 1: if sigma_des < 1:
sigma_des = 1 sigma_des = 1
@ -1891,6 +1897,7 @@ class Eynollah:
areas_cnt_text_d = np.array([cv2.contourArea(contours_only_text_parent_d[j]) for j in range(len(contours_only_text_parent_d))]) areas_cnt_text_d = np.array([cv2.contourArea(contours_only_text_parent_d[j]) for j in range(len(contours_only_text_parent_d))])
areas_cnt_text_d = areas_cnt_text_d / float(text_only_d.shape[0] * text_only_d.shape[1]) areas_cnt_text_d = areas_cnt_text_d / float(text_only_d.shape[0] * text_only_d.shape[1])
if len(areas_cnt_text_d)>0:
contours_biggest_d = contours_only_text_parent_d[np.argmax(areas_cnt_text_d)] contours_biggest_d = contours_only_text_parent_d[np.argmax(areas_cnt_text_d)]
index_con_parents_d=np.argsort(areas_cnt_text_d) index_con_parents_d=np.argsort(areas_cnt_text_d)
contours_only_text_parent_d=list(np.array(contours_only_text_parent_d)[index_con_parents_d] ) contours_only_text_parent_d=list(np.array(contours_only_text_parent_d)[index_con_parents_d] )
@ -1937,6 +1944,12 @@ class Eynollah:
else: else:
contours_only_text_parent_d_ordered = [] contours_only_text_parent_d_ordered = []
contours_only_text_parent_d = [] contours_only_text_parent_d = []
contours_only_text_parent = []
else:
contours_only_text_parent_d_ordered = []
contours_only_text_parent_d = []
contours_only_text_parent = []
else: else:
contours_only_text, hir_on_text = return_contours_of_image(text_only) contours_only_text, hir_on_text = return_contours_of_image(text_only)
@ -1968,7 +1981,6 @@ class Eynollah:
if not self.curved_line: if not self.curved_line:
slopes, all_found_texline_polygons, boxes_text, txt_con_org, contours_only_text_parent, all_box_coord, index_by_text_par_con = self.get_slopes_and_deskew_new(txt_con_org, contours_only_text_parent, textline_mask_tot_ea, image_page_rotated, boxes_text, slope_deskew) slopes, all_found_texline_polygons, boxes_text, txt_con_org, contours_only_text_parent, all_box_coord, index_by_text_par_con = self.get_slopes_and_deskew_new(txt_con_org, contours_only_text_parent, textline_mask_tot_ea, image_page_rotated, boxes_text, slope_deskew)
slopes_marginals, all_found_texline_polygons_marginals, boxes_marginals, _, polygons_of_marginals, all_box_coord_marginals, _ = self.get_slopes_and_deskew_new(polygons_of_marginals, polygons_of_marginals, textline_mask_tot_ea, image_page_rotated, boxes_marginals, slope_deskew) slopes_marginals, all_found_texline_polygons_marginals, boxes_marginals, _, polygons_of_marginals, all_box_coord_marginals, _ = self.get_slopes_and_deskew_new(polygons_of_marginals, polygons_of_marginals, textline_mask_tot_ea, image_page_rotated, boxes_marginals, slope_deskew)
else: else:
scale_param = 1 scale_param = 1

Loading…
Cancel
Save