🔥 manually merge 58ecb57

pull/8/head
Konstantin Baierer 4 years ago
parent 145b2fcd98
commit 6ab7abdfcd

@ -1239,8 +1239,14 @@ class eynollah:
# all_box_coord.append(crop_coor) # all_box_coord.append(crop_coor)
mask_textline=np.zeros((textline_mask_tot_ea.shape))
mask_textline=cv2.fillPoly(mask_textline,pts=[contours_per_process[mv]],color=(1,1,1))
denoised = None denoised = None
all_text_region_raw = textline_mask_tot_ea[boxes_text[mv][1] : boxes_text[mv][1] + boxes_text[mv][3], boxes_text[mv][0] : boxes_text[mv][0] + boxes_text[mv][2]] all_text_region_raw=(textline_mask_tot_ea*mask_textline[:,:])[boxes_text[mv][1]:boxes_text[mv][1]+boxes_text[mv][3] , boxes_text[mv][0]:boxes_text[mv][0]+boxes_text[mv][2] ]
all_text_region_raw = all_text_region_raw.astype(np.uint8) all_text_region_raw = all_text_region_raw.astype(np.uint8)
img_int_p = all_text_region_raw[:, :] # self.all_text_region_raw[mv] img_int_p = all_text_region_raw[:, :] # self.all_text_region_raw[mv]
@ -2750,74 +2756,83 @@ class eynollah:
tree.write(os.path.join(dir_of_image, self.f_name) + ".xml") tree.write(os.path.join(dir_of_image, self.f_name) + ".xml")
# cv2.imwrite(os.path.join(dir_of_image, self.f_name) + ".tif",self.image_org) # cv2.imwrite(os.path.join(dir_of_image, self.f_name) + ".tif",self.image_org)
def get_regions_from_xy_2models(self, img, is_image_enhanced): def get_regions_from_xy_2models(self,img,is_image_enhanced):
img_org = np.copy(img) img_org=np.copy(img)
img_height_h = img_org.shape[0] img_height_h=img_org.shape[0]
img_width_h = img_org.shape[1] img_width_h=img_org.shape[1]
model_region, session_region = self.start_new_session_and_model(self.model_region_dir_p_ens) model_region, session_region = self.start_new_session_and_model(self.model_region_dir_p_ens)
gaussian_filter = False gaussian_filter=False
patches = True patches=True
binary = False binary=False
ratio_y = 1.3
ratio_x = 1
median_blur = False
img = resize_image(img_org, int(img_org.shape[0] * ratio_y), int(img_org.shape[1] * ratio_x))
ratio_y=1.3
ratio_x=1
median_blur=False
img= self.resize_image(img_org, int(img_org.shape[0]*ratio_y), int(img_org.shape[1]*ratio_x))
if binary: if binary:
img = otsu_copy_binary(img) # otsu_copy(img) img = self.otsu_copy_binary(img)#self.otsu_copy(img)
img = img.astype(np.uint16) img = img.astype(np.uint16)
if median_blur: if median_blur:
img = cv2.medianBlur(img, 5) img=cv2.medianBlur(img,5)
if gaussian_filter: if gaussian_filter:
img = cv2.GaussianBlur(img, (5, 5), 0) img= cv2.GaussianBlur(img,(5,5),0)
img = img.astype(np.uint16) img = img.astype(np.uint16)
prediction_regions_org_y = self.do_prediction(patches, img, model_region) prediction_regions_org_y=self.do_prediction(patches,img,model_region)
prediction_regions_org_y=self.resize_image(prediction_regions_org_y, img_height_h, img_width_h )
#plt.imshow(prediction_regions_org_y[:,:,0])
#plt.show()
#sys.exit()
prediction_regions_org_y=prediction_regions_org_y[:,:,0]
mask_zeros_y=(prediction_regions_org_y[:,:]==0)*1
prediction_regions_org_y = resize_image(prediction_regions_org_y, img_height_h, img_width_h)
# plt.imshow(prediction_regions_org_y[:,:,0])
# plt.show()
# sys.exit()
prediction_regions_org_y = prediction_regions_org_y[:, :, 0]
mask_zeros_y = (prediction_regions_org_y[:, :] == 0) * 1
if is_image_enhanced: if is_image_enhanced:
ratio_x = 1.2 ratio_x=1.2
else: else:
ratio_x = 1 ratio_x=1
ratio_y = 1 ratio_y=1
median_blur = False median_blur=False
img = resize_image(img_org, int(img_org.shape[0] * ratio_y), int(img_org.shape[1] * ratio_x)) img= self.resize_image(img_org, int(img_org.shape[0]*ratio_y), int(img_org.shape[1]*ratio_x))
if binary: if binary:
img = otsu_copy_binary(img) # otsu_copy(img) img = self.otsu_copy_binary(img)#self.otsu_copy(img)
img = img.astype(np.uint16) img = img.astype(np.uint16)
if median_blur: if median_blur:
img = cv2.medianBlur(img, 5) img=cv2.medianBlur(img,5)
if gaussian_filter: if gaussian_filter:
img = cv2.GaussianBlur(img, (5, 5), 0) img= cv2.GaussianBlur(img,(5,5),0)
img = img.astype(np.uint16) img = img.astype(np.uint16)
prediction_regions_org = self.do_prediction(patches, img, model_region) prediction_regions_org=self.do_prediction(patches,img,model_region)
prediction_regions_org = resize_image(prediction_regions_org, img_height_h, img_width_h) prediction_regions_org=self.resize_image(prediction_regions_org, img_height_h, img_width_h )
##plt.imshow(prediction_regions_org[:,:,0]) ##plt.imshow(prediction_regions_org[:,:,0])
##plt.show() ##plt.show()
##sys.exit() ##sys.exit()
prediction_regions_org = prediction_regions_org[:, :, 0] prediction_regions_org=prediction_regions_org[:,:,0]
prediction_regions_org[(prediction_regions_org[:, :] == 1) & (mask_zeros_y[:, :] == 1)] = 0 prediction_regions_org[(prediction_regions_org[:,:]==1) & (mask_zeros_y[:,:]==1)]=0
session_region.close() session_region.close()
del model_region del model_region
del session_region del session_region
@ -2826,32 +2841,37 @@ class eynollah:
model_region, session_region = self.start_new_session_and_model(self.model_region_dir_p2) model_region, session_region = self.start_new_session_and_model(self.model_region_dir_p2)
gaussian_filter = False gaussian_filter=False
patches = True patches=True
binary = False binary=False
ratio_x = 1
ratio_y = 1
median_blur = False
img = resize_image(img_org, int(img_org.shape[0] * ratio_y), int(img_org.shape[1] * ratio_x)) ratio_x=1
ratio_y=1
median_blur=False
img= self.resize_image(img_org, int(img_org.shape[0]*ratio_y), int(img_org.shape[1]*ratio_x))
if binary: if binary:
img = otsu_copy_binary(img) # otsu_copy(img) img = self.otsu_copy_binary(img)#self.otsu_copy(img)
img = img.astype(np.uint16) img = img.astype(np.uint16)
if median_blur: if median_blur:
img = cv2.medianBlur(img, 5) img=cv2.medianBlur(img,5)
if gaussian_filter: if gaussian_filter:
img = cv2.GaussianBlur(img, (5, 5), 0) img= cv2.GaussianBlur(img,(5,5),0)
img = img.astype(np.uint16) img = img.astype(np.uint16)
prediction_regions_org2 = self.do_prediction(patches, img, model_region)
prediction_regions_org2 = resize_image(prediction_regions_org2, img_height_h, img_width_h) marginal_patch=0.2
prediction_regions_org2=self.do_prediction(patches,img,model_region,marginal_patch)
# plt.imshow(prediction_regions_org2[:,:,0]) prediction_regions_org2=self.resize_image(prediction_regions_org2, img_height_h, img_width_h )
# plt.show()
# sys.exit() #plt.imshow(prediction_regions_org2[:,:,0])
#plt.show()
#sys.exit()
##prediction_regions_org=prediction_regions_org[:,:,0] ##prediction_regions_org=prediction_regions_org[:,:,0]
session_region.close() session_region.close()
@ -2860,124 +2880,135 @@ class eynollah:
gc.collect() gc.collect()
###K.clear_session() ###K.clear_session()
mask_zeros2 = (prediction_regions_org2[:, :, 0] == 0) * 1 mask_zeros2=(prediction_regions_org2[:,:,0]==0)*1
mask_lines2 = (prediction_regions_org2[:, :, 0] == 3) * 1 mask_lines2=(prediction_regions_org2[:,:,0]==3)*1
text_sume_early=( (prediction_regions_org[:,:]==1)*1 ).sum()
text_sume_early = ((prediction_regions_org[:, :] == 1) * 1).sum() prediction_regions_org_copy=np.copy(prediction_regions_org)
prediction_regions_org_copy = np.copy(prediction_regions_org)
prediction_regions_org_copy[(prediction_regions_org_copy[:, :] == 1) & (mask_zeros2[:, :] == 1)] = 0 prediction_regions_org_copy[(prediction_regions_org_copy[:,:]==1) & (mask_zeros2[:,:]==1)]=0
text_sume_second = ((prediction_regions_org_copy[:, :] == 1) * 1).sum() text_sume_second=( (prediction_regions_org_copy[:,:]==1)*1 ).sum()
rate_two_models = text_sume_second / float(text_sume_early) * 100 rate_two_models=text_sume_second/float(text_sume_early)*100
print(rate_two_models, "ratio_of_two_models") print(rate_two_models,'ratio_of_two_models')
if is_image_enhanced and rate_two_models < 95.50: # 98.45: if is_image_enhanced and rate_two_models<95.50:#98.45:
pass pass
else: else:
prediction_regions_org = np.copy(prediction_regions_org_copy) prediction_regions_org=np.copy(prediction_regions_org_copy)
##prediction_regions_org[mask_lines2[:,:]==1]=3 ##prediction_regions_org[mask_lines2[:,:]==1]=3
prediction_regions_org[(mask_lines2[:, :] == 1) & (prediction_regions_org[:, :] == 0)] = 3 prediction_regions_org[(mask_lines2[:,:]==1) & (prediction_regions_org[:,:]==0)]=3
del mask_lines2 del mask_lines2
del mask_zeros2 del mask_zeros2
del prediction_regions_org2 del prediction_regions_org2
# if is_image_enhanced: #if is_image_enhanced:
# pass #pass
# else: #else:
# model_region, session_region = self.start_new_session_and_model(self.model_region_dir_p2) #model_region, session_region = self.start_new_session_and_model(self.model_region_dir_p2)
# gaussian_filter=False #gaussian_filter=False
# patches=True #patches=True
# binary=False #binary=False
# ratio_x=1
# ratio_y=1
# median_blur=False
# img= resize_image(img_org, int(img_org.shape[0]*ratio_y), int(img_org.shape[1]*ratio_x))
# if binary:
# img = otsu_copy_binary(img)#otsu_copy(img)
# img = img.astype(np.uint16)
# if median_blur: #ratio_x=1
# img=cv2.medianBlur(img,5) #ratio_y=1
# if gaussian_filter: #median_blur=False
# img= cv2.GaussianBlur(img,(5,5),0)
# img = img.astype(np.uint16)
# prediction_regions_org2=self.do_prediction(patches,img,model_region)
# prediction_regions_org2=resize_image(prediction_regions_org2, img_height_h, img_width_h ) #img= self.resize_image(img_org, int(img_org.shape[0]*ratio_y), int(img_org.shape[1]*ratio_x))
##plt.imshow(prediction_regions_org2[:,:,0]) #if binary:
##plt.show() #img = self.otsu_copy_binary(img)#self.otsu_copy(img)
##sys.exit() #img = img.astype(np.uint16)
###prediction_regions_org=prediction_regions_org[:,:,0]
# session_region.close() #if median_blur:
# del model_region #img=cv2.medianBlur(img,5)
# del session_region #if gaussian_filter:
# gc.collect() #img= cv2.GaussianBlur(img,(5,5),0)
####K.clear_session() #img = img.astype(np.uint16)
#prediction_regions_org2=self.do_prediction(patches,img,model_region)
# mask_zeros2=(prediction_regions_org2[:,:,0]==0)*1 #prediction_regions_org2=self.resize_image(prediction_regions_org2, img_height_h, img_width_h )
# mask_lines2=(prediction_regions_org2[:,:,0]==3)*1
# text_sume_early=( (prediction_regions_org[:,:]==1)*1 ).sum() ##plt.imshow(prediction_regions_org2[:,:,0])
##plt.show()
##sys.exit()
###prediction_regions_org=prediction_regions_org[:,:,0]
# prediction_regions_org[(prediction_regions_org[:,:]==1) & (mask_zeros2[:,:]==1)]=0 #session_region.close()
#del model_region
#del session_region
#gc.collect()
####K.clear_session()
###prediction_regions_org[mask_lines2[:,:]==1]=3 #mask_zeros2=(prediction_regions_org2[:,:,0]==0)*1
# prediction_regions_org[(mask_lines2[:,:]==1) & (prediction_regions_org[:,:]==0)]=3 #mask_lines2=(prediction_regions_org2[:,:,0]==3)*1
# text_sume_second=( (prediction_regions_org[:,:]==1)*1 ).sum() #text_sume_early=( (prediction_regions_org[:,:]==1)*1 ).sum()
# print(text_sume_second/float(text_sume_early)*100,'twomodelsratio')
# del mask_lines2 #prediction_regions_org[(prediction_regions_org[:,:]==1) & (mask_zeros2[:,:]==1)]=0
# del mask_zeros2
# del prediction_regions_org2
mask_lines_only = (prediction_regions_org[:, :] == 3) * 1 ###prediction_regions_org[mask_lines2[:,:]==1]=3
#prediction_regions_org[(mask_lines2[:,:]==1) & (prediction_regions_org[:,:]==0)]=3
prediction_regions_org = cv2.erode(prediction_regions_org[:, :], self.kernel, iterations=2) #text_sume_second=( (prediction_regions_org[:,:]==1)*1 ).sum()
# plt.imshow(text_region2_1st_channel) #print(text_sume_second/float(text_sume_early)*100,'twomodelsratio')
# plt.show()
#del mask_lines2
#del mask_zeros2
#del prediction_regions_org2
mask_lines_only=(prediction_regions_org[:,:]==3)*1
prediction_regions_org = cv2.erode(prediction_regions_org[:,:], self.kernel, iterations=2)
#plt.imshow(text_region2_1st_channel)
#plt.show()
prediction_regions_org = cv2.dilate(prediction_regions_org[:,:], self.kernel, iterations=2)
mask_texts_only=(prediction_regions_org[:,:]==1)*1
mask_images_only=(prediction_regions_org[:,:]==2)*1
prediction_regions_org = cv2.dilate(prediction_regions_org[:, :], self.kernel, iterations=2)
mask_texts_only = (prediction_regions_org[:, :] == 1) * 1
mask_images_only = (prediction_regions_org[:, :] == 2) * 1 pixel_img=1
min_area_text=0.00001
polygons_of_only_texts=self.return_contours_of_interested_region(mask_texts_only,pixel_img,min_area_text)
pixel_img = 1 polygons_of_only_images=self.return_contours_of_interested_region(mask_images_only,pixel_img)
min_area_text = 0.00001
polygons_of_only_texts = return_contours_of_interested_region(mask_texts_only, pixel_img, min_area_text)
polygons_of_only_images = return_contours_of_interested_region(mask_images_only, pixel_img) polygons_of_only_lines=self.return_contours_of_interested_region(mask_lines_only,pixel_img,min_area_text)
polygons_of_only_lines = return_contours_of_interested_region(mask_lines_only, pixel_img, min_area_text)
text_regions_p_true = np.zeros(prediction_regions_org.shape) text_regions_p_true=np.zeros(prediction_regions_org.shape)
# text_regions_p_true[:,:]=text_regions_p_1[:,:] #text_regions_p_true[:,:]=text_regions_p_1[:,:]
text_regions_p_true = cv2.fillPoly(text_regions_p_true, pts=polygons_of_only_lines, color=(3, 3, 3)) text_regions_p_true=cv2.fillPoly(text_regions_p_true,pts=polygons_of_only_lines, color=(3,3,3))
##text_regions_p_true=cv2.fillPoly(text_regions_p_true,pts=polygons_of_only_images, color=(2,2,2)) ##text_regions_p_true=cv2.fillPoly(text_regions_p_true,pts=polygons_of_only_images, color=(2,2,2))
text_regions_p_true[:, :][mask_images_only[:, :] == 1] = 2 text_regions_p_true[:,:][mask_images_only[:,:]==1]=2
text_regions_p_true = cv2.fillPoly(text_regions_p_true, pts=polygons_of_only_texts, color=(1, 1, 1)) text_regions_p_true=cv2.fillPoly(text_regions_p_true,pts=polygons_of_only_texts, color=(1,1,1))
##print(np.unique(text_regions_p_true)) ##print(np.unique(text_regions_p_true))
# text_regions_p_true_3d=np.repeat(text_regions_p_1[:, :, np.newaxis], 3, axis=2)
# text_regions_p_true_3d=text_regions_p_true_3d.astype(np.uint8) #text_regions_p_true_3d=np.repeat(text_regions_p_1[:, :, np.newaxis], 3, axis=2)
#text_regions_p_true_3d=text_regions_p_true_3d.astype(np.uint8)
del polygons_of_only_texts del polygons_of_only_texts
del polygons_of_only_images del polygons_of_only_images
@ -2993,6 +3024,7 @@ class eynollah:
return text_regions_p_true return text_regions_p_true
def write_images_into_directory(self, img_contoures, dir_of_cropped_imgs, image_page): def write_images_into_directory(self, img_contoures, dir_of_cropped_imgs, image_page):
index = 0 index = 0
for cont_ind in img_contoures: for cont_ind in img_contoures:
@ -3009,215 +3041,245 @@ class eynollah:
cv2.imwrite(path, croped_page) cv2.imwrite(path, croped_page)
index += 1 index += 1
def get_marginals(self, text_with_lines, text_regions, num_col, slope_deskew): def get_marginals(self,text_with_lines,text_regions,num_col,slope_deskew):
mask_marginals = np.zeros((text_with_lines.shape[0], text_with_lines.shape[1])) mask_marginals=np.zeros((text_with_lines.shape[0],text_with_lines.shape[1]))
mask_marginals = mask_marginals.astype(np.uint8) mask_marginals=mask_marginals.astype(np.uint8)
text_with_lines = text_with_lines.astype(np.uint8) text_with_lines=text_with_lines.astype(np.uint8)
##text_with_lines=cv2.erode(text_with_lines,self.kernel,iterations=3) ##text_with_lines=cv2.erode(text_with_lines,self.kernel,iterations=3)
text_with_lines_eroded = cv2.erode(text_with_lines, self.kernel, iterations=5) text_with_lines_eroded=cv2.erode(text_with_lines,self.kernel,iterations=5)
if text_with_lines.shape[0] <= 1500: if text_with_lines.shape[0]<=1500:
pass pass
elif text_with_lines.shape[0] > 1500 and text_with_lines.shape[0] <= 1800: elif text_with_lines.shape[0]>1500 and text_with_lines.shape[0]<=1800:
text_with_lines = resize_image(text_with_lines, int(text_with_lines.shape[0] * 1.5), text_with_lines.shape[1]) text_with_lines=self.resize_image(text_with_lines,int(text_with_lines.shape[0]*1.5),text_with_lines.shape[1])
text_with_lines = cv2.erode(text_with_lines, self.kernel, iterations=5) text_with_lines=cv2.erode(text_with_lines,self.kernel,iterations=5)
text_with_lines = resize_image(text_with_lines, text_with_lines_eroded.shape[0], text_with_lines_eroded.shape[1]) text_with_lines=self.resize_image(text_with_lines,text_with_lines_eroded.shape[0],text_with_lines_eroded.shape[1])
else: else:
text_with_lines = resize_image(text_with_lines, int(text_with_lines.shape[0] * 1.8), text_with_lines.shape[1]) text_with_lines=self.resize_image(text_with_lines,int(text_with_lines.shape[0]*1.8),text_with_lines.shape[1])
text_with_lines = cv2.erode(text_with_lines, self.kernel, iterations=7) text_with_lines=cv2.erode(text_with_lines,self.kernel,iterations=7)
text_with_lines = resize_image(text_with_lines, text_with_lines_eroded.shape[0], text_with_lines_eroded.shape[1]) text_with_lines=self.resize_image(text_with_lines,text_with_lines_eroded.shape[0],text_with_lines_eroded.shape[1])
text_with_lines_y = text_with_lines.sum(axis=0)
text_with_lines_y_eroded = text_with_lines_eroded.sum(axis=0)
thickness_along_y_percent = text_with_lines_y_eroded.max() / (float(text_with_lines.shape[0])) * 100 text_with_lines_y=text_with_lines.sum(axis=0)
text_with_lines_y_eroded=text_with_lines_eroded.sum(axis=0)
# print(thickness_along_y_percent,'thickness_along_y_percent') thickness_along_y_percent=text_with_lines_y_eroded.max()/(float(text_with_lines.shape[0]))*100
if thickness_along_y_percent < 30: #print(thickness_along_y_percent,'thickness_along_y_percent')
min_textline_thickness = 8
elif thickness_along_y_percent >= 30 and thickness_along_y_percent < 50: if thickness_along_y_percent<30:
min_textline_thickness = 20 min_textline_thickness=8
elif thickness_along_y_percent>=30 and thickness_along_y_percent<50:
min_textline_thickness=20
else: else:
min_textline_thickness = 40 min_textline_thickness=40
if thickness_along_y_percent >= 14:
text_with_lines_y_rev = -1 * text_with_lines_y[:]
# print(text_with_lines_y)
# print(text_with_lines_y_rev)
# plt.plot(text_with_lines_y) if thickness_along_y_percent>=14:
# plt.show()
text_with_lines_y_rev = text_with_lines_y_rev - np.min(text_with_lines_y_rev) text_with_lines_y_rev=-1*text_with_lines_y[:]
#print(text_with_lines_y)
#print(text_with_lines_y_rev)
# plt.plot(text_with_lines_y_rev)
# plt.show()
sigma_gaus = 1
region_sum_0 = gaussian_filter1d(text_with_lines_y, sigma_gaus)
region_sum_0_rev = gaussian_filter1d(text_with_lines_y_rev, sigma_gaus)
# plt.plot(region_sum_0_rev)
# plt.show()
region_sum_0_updown = region_sum_0[len(region_sum_0) :: -1]
first_nonzero = next((i for i, x in enumerate(region_sum_0) if x), None) #plt.plot(text_with_lines_y)
last_nonzero = next((i for i, x in enumerate(region_sum_0_updown) if x), None) #plt.show()
text_with_lines_y_rev=text_with_lines_y_rev-np.min(text_with_lines_y_rev)
#plt.plot(text_with_lines_y_rev)
#plt.show()
sigma_gaus=1
region_sum_0= gaussian_filter1d(text_with_lines_y, sigma_gaus)
last_nonzero = len(region_sum_0) - last_nonzero region_sum_0_rev=gaussian_filter1d(text_with_lines_y_rev, sigma_gaus)
#plt.plot(region_sum_0_rev)
#plt.show()
region_sum_0_updown=region_sum_0[len(region_sum_0)::-1]
first_nonzero=(next((i for i, x in enumerate(region_sum_0) if x), None))
last_nonzero=(next((i for i, x in enumerate(region_sum_0_updown) if x), None))
last_nonzero=len(region_sum_0)-last_nonzero
##img_sum_0_smooth_rev=-region_sum_0 ##img_sum_0_smooth_rev=-region_sum_0
mid_point = (last_nonzero + first_nonzero) / 2.0
one_third_right = (last_nonzero - mid_point) / 3.0 mid_point=(last_nonzero+first_nonzero)/2.
one_third_left = (mid_point - first_nonzero) / 3.0
one_third_right=(last_nonzero-mid_point)/3.0
one_third_left=(mid_point-first_nonzero)/3.0
#img_sum_0_smooth_rev=img_sum_0_smooth_rev-np.min(img_sum_0_smooth_rev)
# img_sum_0_smooth_rev=img_sum_0_smooth_rev-np.min(img_sum_0_smooth_rev)
peaks, _ = find_peaks(text_with_lines_y_rev, height=0) peaks, _ = find_peaks(text_with_lines_y_rev, height=0)
peaks = np.array(peaks)
# print(region_sum_0[peaks]) peaks=np.array(peaks)
#print(region_sum_0[peaks])
##plt.plot(region_sum_0) ##plt.plot(region_sum_0)
##plt.plot(peaks,region_sum_0[peaks],'*') ##plt.plot(peaks,region_sum_0[peaks],'*')
##plt.show() ##plt.show()
# print(first_nonzero,last_nonzero,peaks) #print(first_nonzero,last_nonzero,peaks)
peaks = peaks[(peaks > first_nonzero) & ((peaks < last_nonzero))] peaks=peaks[(peaks>first_nonzero) & ((peaks<last_nonzero))]
#print(first_nonzero,last_nonzero,peaks)
# print(first_nonzero,last_nonzero,peaks)
# print(region_sum_0[peaks]<10) #print(region_sum_0[peaks]<10)
####peaks=peaks[region_sum_0[peaks]<25 ] ####peaks=peaks[region_sum_0[peaks]<25 ]
# print(region_sum_0[peaks]) #print(region_sum_0[peaks])
peaks = peaks[region_sum_0[peaks] < min_textline_thickness] peaks=peaks[region_sum_0[peaks]<min_textline_thickness ]
# print(peaks) #print(peaks)
# print(first_nonzero,last_nonzero,one_third_right,one_third_left) #print(first_nonzero,last_nonzero,one_third_right,one_third_left)
if num_col==1:
peaks_right=peaks[peaks>mid_point]
peaks_left=peaks[peaks<mid_point]
if num_col==2:
peaks_right=peaks[peaks>(mid_point+one_third_right)]
peaks_left=peaks[peaks<(mid_point-one_third_left)]
if num_col == 1:
peaks_right = peaks[peaks > mid_point]
peaks_left = peaks[peaks < mid_point]
if num_col == 2:
peaks_right = peaks[peaks > (mid_point + one_third_right)]
peaks_left = peaks[peaks < (mid_point - one_third_left)]
try: try:
point_right = np.min(peaks_right) point_right=np.min(peaks_right)
except: except:
point_right = last_nonzero point_right=last_nonzero
try: try:
point_left = np.max(peaks_left) point_left=np.max(peaks_left)
except: except:
point_left = first_nonzero point_left=first_nonzero
# print(point_left,point_right)
# print(text_regions.shape) #print(point_left,point_right)
if point_right >= mask_marginals.shape[1]: #print(text_regions.shape)
point_right = mask_marginals.shape[1] - 1 if point_right>=mask_marginals.shape[1]:
point_right=mask_marginals.shape[1]-1
try: try:
mask_marginals[:, point_left:point_right] = 1 mask_marginals[:,point_left:point_right]=1
except: except:
mask_marginals[:, :] = 1 mask_marginals[:,:]=1
# print(mask_marginals.shape,point_left,point_right,'nadosh') #print(mask_marginals.shape,point_left,point_right,'nadosh')
mask_marginals_rotated = rotate_image(mask_marginals, -slope_deskew) mask_marginals_rotated=self.rotate_image(mask_marginals,-slope_deskew)
# print(mask_marginals_rotated.shape,'nadosh') #print(mask_marginals_rotated.shape,'nadosh')
mask_marginals_rotated_sum = mask_marginals_rotated.sum(axis=0) mask_marginals_rotated_sum=mask_marginals_rotated.sum(axis=0)
mask_marginals_rotated_sum[mask_marginals_rotated_sum != 0] = 1 mask_marginals_rotated_sum[mask_marginals_rotated_sum!=0]=1
index_x = np.array(range(len(mask_marginals_rotated_sum))) + 1 index_x=np.array(range(len(mask_marginals_rotated_sum)))+1
index_x_interest = index_x[mask_marginals_rotated_sum == 1] index_x_interest=index_x[mask_marginals_rotated_sum==1]
min_point_of_left_marginal = np.min(index_x_interest) - 16 min_point_of_left_marginal=np.min(index_x_interest)-16
max_point_of_right_marginal = np.max(index_x_interest) + 16 max_point_of_right_marginal=np.max(index_x_interest)+16
if min_point_of_left_marginal < 0: if min_point_of_left_marginal<0:
min_point_of_left_marginal = 0 min_point_of_left_marginal=0
if max_point_of_right_marginal >= text_regions.shape[1]: if max_point_of_right_marginal>=text_regions.shape[1]:
max_point_of_right_marginal = text_regions.shape[1] - 1 max_point_of_right_marginal=text_regions.shape[1]-1
# print(np.min(index_x_interest) ,np.max(index_x_interest),'minmaxnew')
# print(mask_marginals_rotated.shape,text_regions.shape,'mask_marginals_rotated')
# plt.imshow(mask_marginals)
# plt.show()
# plt.imshow(mask_marginals_rotated) #print(np.min(index_x_interest) ,np.max(index_x_interest),'minmaxnew')
# plt.show() #print(mask_marginals_rotated.shape,text_regions.shape,'mask_marginals_rotated')
#plt.imshow(mask_marginals)
#plt.show()
text_regions[(mask_marginals_rotated[:, :] != 1) & (text_regions[:, :] == 1)] = 4 #plt.imshow(mask_marginals_rotated)
#plt.show()
pixel_img = 4 text_regions[(mask_marginals_rotated[:,:]!=1) & (text_regions[:,:]==1)]=4
min_area_text = 0.00001
polygons_of_marginals = return_contours_of_interested_region(text_regions, pixel_img, min_area_text)
cx_text_only, cy_text_only, x_min_text_only, x_max_text_only, y_min_text_only, y_max_text_only, y_cor_x_min_main = find_new_features_of_contoures(polygons_of_marginals) #plt.imshow(text_regions)
#plt.show()
text_regions[(text_regions[:, :] == 4)] = 1 pixel_img=4
min_area_text=0.00001
polygons_of_marginals=self.return_contours_of_interested_region(text_regions,pixel_img,min_area_text)
marginlas_should_be_main_text = [] cx_text_only,cy_text_only ,x_min_text_only,x_max_text_only, y_min_text_only ,y_max_text_only,y_cor_x_min_main=self.find_new_features_of_contoures(polygons_of_marginals)
x_min_marginals_left = [] text_regions[(text_regions[:,:]==4)]=1
x_min_marginals_right = []
marginlas_should_be_main_text=[]
x_min_marginals_left=[]
x_min_marginals_right=[]
for i in range(len(cx_text_only)): for i in range(len(cx_text_only)):
x_width_mar = abs(x_min_text_only[i] - x_max_text_only[i]) x_width_mar=abs(x_min_text_only[i]-x_max_text_only[i])
y_height_mar = abs(y_min_text_only[i] - y_max_text_only[i]) y_height_mar=abs(y_min_text_only[i]-y_max_text_only[i])
# print(x_width_mar,y_height_mar,'y_height_mar') #print(x_width_mar,y_height_mar,y_height_mar/x_width_mar,'y_height_mar')
if x_width_mar > 16 and y_height_mar / x_width_mar < 10: if x_width_mar>16 and y_height_mar/x_width_mar<18:
marginlas_should_be_main_text.append(polygons_of_marginals[i]) marginlas_should_be_main_text.append(polygons_of_marginals[i])
if x_min_text_only[i] < (mid_point - one_third_left): if x_min_text_only[i]<(mid_point-one_third_left):
x_min_marginals_left_new = x_min_text_only[i] x_min_marginals_left_new=x_min_text_only[i]
if len(x_min_marginals_left) == 0: if len(x_min_marginals_left)==0:
x_min_marginals_left.append(x_min_marginals_left_new) x_min_marginals_left.append(x_min_marginals_left_new)
else: else:
x_min_marginals_left[0] = min(x_min_marginals_left[0], x_min_marginals_left_new) x_min_marginals_left[0]=min(x_min_marginals_left[0],x_min_marginals_left_new)
else: else:
x_min_marginals_right_new = x_min_text_only[i] x_min_marginals_right_new=x_min_text_only[i]
if len(x_min_marginals_right) == 0: if len(x_min_marginals_right)==0:
x_min_marginals_right.append(x_min_marginals_right_new) x_min_marginals_right.append(x_min_marginals_right_new)
else: else:
x_min_marginals_right[0] = min(x_min_marginals_right[0], x_min_marginals_right_new) x_min_marginals_right[0]=min(x_min_marginals_right[0],x_min_marginals_right_new)
if len(x_min_marginals_left)==0:
x_min_marginals_left=[0]
if len(x_min_marginals_right)==0:
x_min_marginals_right=[text_regions.shape[1]-1]
if len(x_min_marginals_left) == 0:
x_min_marginals_left = [0]
if len(x_min_marginals_right) == 0:
x_min_marginals_right = [text_regions.shape[1] - 1]
# print(x_min_marginals_left[0],x_min_marginals_right[0],'margo')
# print(marginlas_should_be_main_text,'marginlas_should_be_main_text')
text_regions = cv2.fillPoly(text_regions, pts=marginlas_should_be_main_text, color=(4, 4))
# print(np.unique(text_regions)) #print(x_min_marginals_left[0],x_min_marginals_right[0],'margo')
# text_regions[:,:int(x_min_marginals_left[0])][text_regions[:,:int(x_min_marginals_left[0])]==1]=0 #print(marginlas_should_be_main_text,'marginlas_should_be_main_text')
# text_regions[:,int(x_min_marginals_right[0]):][text_regions[:,int(x_min_marginals_right[0]):]==1]=0 text_regions=cv2.fillPoly(text_regions, pts =marginlas_should_be_main_text, color=(4,4))
text_regions[:, : int(min_point_of_left_marginal)][text_regions[:, : int(min_point_of_left_marginal)] == 1] = 0 #print(np.unique(text_regions))
text_regions[:, int(max_point_of_right_marginal) :][text_regions[:, int(max_point_of_right_marginal) :] == 1] = 0
#text_regions[:,:int(x_min_marginals_left[0])][text_regions[:,:int(x_min_marginals_left[0])]==1]=0
#text_regions[:,int(x_min_marginals_right[0]):][text_regions[:,int(x_min_marginals_right[0]):]==1]=0
text_regions[:,:int(min_point_of_left_marginal)][text_regions[:,:int(min_point_of_left_marginal)]==1]=0
text_regions[:,int(max_point_of_right_marginal):][text_regions[:,int(max_point_of_right_marginal):]==1]=0
###text_regions[:,0:point_left][text_regions[:,0:point_left]==1]=4 ###text_regions[:,0:point_left][text_regions[:,0:point_left]==1]=4
###text_regions[:,point_right:][ text_regions[:,point_right:]==1]=4 ###text_regions[:,point_right:][ text_regions[:,point_right:]==1]=4
# plt.plot(region_sum_0) #plt.plot(region_sum_0)
# plt.plot(peaks,region_sum_0[peaks],'*') #plt.plot(peaks,region_sum_0[peaks],'*')
# plt.show() #plt.show()
# plt.imshow(text_regions)
# plt.show()
# sys.exit() #plt.imshow(text_regions)
#plt.show()
#sys.exit()
else: else:
pass pass
return text_regions return text_regions
@ -4119,7 +4181,7 @@ class eynollah:
num_col = None num_col = None
peaks_neg_fin = [] peaks_neg_fin = []
print(num_col, "num_colnum_col") #print(num_col, "num_colnum_col")
if num_col is None: if num_col is None:
txt_con_org = [] txt_con_org = []
order_text_new = [] order_text_new = []
@ -4144,7 +4206,7 @@ class eynollah:
K.clear_session() K.clear_session()
gc.collect() gc.collect()
print(np.unique(textline_mask_tot_ea[:, :]), "textline") #print(np.unique(textline_mask_tot_ea[:, :]), "textline")
if self.dir_of_all is not None: if self.dir_of_all is not None:

@ -1491,101 +1491,108 @@ def filter_small_drop_capitals_from_no_patch_layout(layout_no_patch, layout1):
def find_num_col_deskew(regions_without_seperators, sigma_, multiplier=3.8): def find_num_col_deskew(regions_without_seperators, sigma_, multiplier=3.8):
regions_without_seperators_0 = regions_without_seperators[:, :].sum(axis=1) regions_without_seperators_0=regions_without_seperators[:,:].sum(axis=1)
meda_n_updown = regions_without_seperators_0[len(regions_without_seperators_0) :: -1] ##meda_n_updown=regions_without_seperators_0[len(regions_without_seperators_0)::-1]
first_nonzero = next((i for i, x in enumerate(regions_without_seperators_0) if x), 0) ##first_nonzero=(next((i for i, x in enumerate(regions_without_seperators_0) if x), 0))
last_nonzero = next((i for i, x in enumerate(meda_n_updown) if x), 0) ##last_nonzero=(next((i for i, x in enumerate(meda_n_updown) if x), 0))
last_nonzero = len(regions_without_seperators_0) - last_nonzero ##last_nonzero=len(regions_without_seperators_0)-last_nonzero
y = regions_without_seperators_0 # [first_nonzero:last_nonzero]
y_help = np.zeros(len(y) + 20) y=regions_without_seperators_0#[first_nonzero:last_nonzero]
y_help[10 : len(y) + 10] = y ##y_help=np.zeros(len(y)+20)
x = np.array(range(len(y))) ##y_help[10:len(y)+10]=y
zneg_rev = -y_help + np.max(y_help) ##x=np.array( range(len(y)) )
zneg = np.zeros(len(zneg_rev) + 20)
zneg[10 : len(zneg_rev) + 10] = zneg_rev
z = gaussian_filter1d(y, sigma_)
zneg = gaussian_filter1d(zneg, sigma_)
peaks_neg, _ = find_peaks(zneg, height=0) ##zneg_rev=-y_help+np.max(y_help)
peaks, _ = find_peaks(z, height=0)
peaks_neg = peaks_neg - 10 - 10 ##zneg=np.zeros(len(zneg_rev)+20)
# print(np.std(z),'np.std(z)np.std(z)np.std(z)') ##zneg[10:len(zneg_rev)+10]=zneg_rev
##plt.plot(z) z=gaussian_filter1d(y, sigma_)
##plt.show() ###zneg= gaussian_filter1d(zneg, sigma_)
##plt.imshow(regions_without_seperators)
##plt.show()
"""
last_nonzero=last_nonzero-0#100
first_nonzero=first_nonzero+0#+100
peaks_neg=peaks_neg[(peaks_neg>first_nonzero) & (peaks_neg<last_nonzero)] ###peaks_neg, _ = find_peaks(zneg, height=0)
###peaks, _ = find_peaks(z, height=0)
peaks=peaks[(peaks>.06*regions_without_seperators.shape[1]) & (peaks<0.94*regions_without_seperators.shape[1])] ###peaks_neg=peaks_neg-10-10
"""
interest_pos = z[peaks]
interest_pos = interest_pos[interest_pos > 10] ####print(np.std(z),'np.std(z)np.std(z)np.std(z)')
interest_neg = z[peaks_neg] #####plt.plot(z)
#####plt.show()
min_peaks_pos = np.mean(interest_pos) #####plt.imshow(regions_without_seperators)
min_peaks_neg = 0 # np.min(interest_neg) #####plt.show()
###"""
###last_nonzero=last_nonzero-0#100
###first_nonzero=first_nonzero+0#+100
dis_talaei = (min_peaks_pos - min_peaks_neg) / multiplier ###peaks_neg=peaks_neg[(peaks_neg>first_nonzero) & (peaks_neg<last_nonzero)]
# print(interest_pos)
grenze = min_peaks_pos - dis_talaei # np.mean(y[peaks_neg[0]:peaks_neg[len(peaks_neg)-1]])-np.std(y[peaks_neg[0]:peaks_neg[len(peaks_neg)-1]])/2.0
interest_neg_fin = interest_neg[(interest_neg < grenze)] ###peaks=peaks[(peaks>.06*regions_without_seperators.shape[1]) & (peaks<0.94*regions_without_seperators.shape[1])]
peaks_neg_fin = peaks_neg[(interest_neg < grenze)] ###"""
interest_neg_fin = interest_neg[(interest_neg < grenze)] ###interest_pos=z[peaks]
""" ###interest_pos=interest_pos[interest_pos>10]
if interest_neg[0]<0.1:
interest_neg=interest_neg[1:]
if interest_neg[len(interest_neg)-1]<0.1:
interest_neg=interest_neg[:len(interest_neg)-1]
###interest_neg=z[peaks_neg]
###min_peaks_pos=np.mean(interest_pos)
###min_peaks_neg=0#np.min(interest_neg)
min_peaks_pos=np.min(interest_pos) ###dis_talaei=(min_peaks_pos-min_peaks_neg)/multiplier
min_peaks_neg=0#np.min(interest_neg) ####print(interest_pos)
###grenze=min_peaks_pos-dis_talaei#np.mean(y[peaks_neg[0]:peaks_neg[len(peaks_neg)-1]])-np.std(y[peaks_neg[0]:peaks_neg[len(peaks_neg)-1]])/2.0
###interest_neg_fin=interest_neg[(interest_neg<grenze)]
###peaks_neg_fin=peaks_neg[(interest_neg<grenze)]
###interest_neg_fin=interest_neg[(interest_neg<grenze)]
dis_talaei=(min_peaks_pos-min_peaks_neg)/multiplier ###"""
grenze=min_peaks_pos-dis_talaei#np.mean(y[peaks_neg[0]:peaks_neg[len(peaks_neg)-1]])-np.std(y[peaks_neg[0]:peaks_neg[len(peaks_neg)-1]])/2.0 ###if interest_neg[0]<0.1:
""" ###interest_neg=interest_neg[1:]
# interest_neg_fin=interest_neg#[(interest_neg<grenze)] ###if interest_neg[len(interest_neg)-1]<0.1:
# peaks_neg_fin=peaks_neg#[(interest_neg<grenze)] ###interest_neg=interest_neg[:len(interest_neg)-1]
# interest_neg_fin=interest_neg#[(interest_neg<grenze)]
num_col = (len(interest_neg_fin)) + 1
p_l = 0
p_u = len(y) - 1
p_m = int(len(y) / 2.0)
p_g_l = int(len(y) / 3.0)
p_g_u = len(y) - int(len(y) / 3.0)
diff_peaks = np.abs(np.diff(peaks_neg_fin)) ###min_peaks_pos=np.min(interest_pos)
diff_peaks_annormal = diff_peaks[diff_peaks < 30] ###min_peaks_neg=0#np.min(interest_neg)
# print(len(interest_neg_fin),np.mean(interest_neg_fin))
return interest_neg_fin, np.std(z) ###dis_talaei=(min_peaks_pos-min_peaks_neg)/multiplier
###grenze=min_peaks_pos-dis_talaei#np.mean(y[peaks_neg[0]:peaks_neg[len(peaks_neg)-1]])-np.std(y[peaks_neg[0]:peaks_neg[len(peaks_neg)-1]])/2.0
###"""
####interest_neg_fin=interest_neg#[(interest_neg<grenze)]
####peaks_neg_fin=peaks_neg#[(interest_neg<grenze)]
####interest_neg_fin=interest_neg#[(interest_neg<grenze)]
###num_col=(len(interest_neg_fin))+1
###p_l=0
###p_u=len(y)-1
###p_m=int(len(y)/2.)
###p_g_l=int(len(y)/3.)
###p_g_u=len(y)-int(len(y)/3.)
###diff_peaks=np.abs( np.diff(peaks_neg_fin) )
###diff_peaks_annormal=diff_peaks[diff_peaks<30]
#print(len(interest_neg_fin),np.mean(interest_neg_fin))
return np.std(z)#interest_neg_fin,np.std(z)
def return_hor_spliter_by_index_for_without_verticals(peaks_neg_fin_t, x_min_hor_some, x_max_hor_some): def return_hor_spliter_by_index_for_without_verticals(peaks_neg_fin_t, x_min_hor_some, x_max_hor_some):
# print(peaks_neg_fin_t,x_min_hor_some,x_max_hor_some) # print(peaks_neg_fin_t,x_min_hor_some,x_max_hor_some)
@ -2343,436 +2350,350 @@ def return_regions_without_seperators(regions_pre):
def return_deskew_slop(img_patch_org, sigma_des, main_page=False, dir_of_all=None, f_name=None): def return_deskew_slop(img_patch_org, sigma_des, main_page=False, dir_of_all=None, f_name=None):
if main_page and dir_of_all is not None: if main_page and dir_of_all is not None:
plt.figure(figsize=(70, 40))
plt.rcParams["font.size"] = "50" plt.figure(figsize=(70,40))
plt.subplot(1, 2, 1) plt.rcParams['font.size']='50'
plt.subplot(1,2,1)
plt.imshow(img_patch_org) plt.imshow(img_patch_org)
plt.subplot(1, 2, 2) plt.subplot(1,2,2)
plt.plot(gaussian_filter1d(img_patch_org.sum(axis=1), 3), np.array(range(len(gaussian_filter1d(img_patch_org.sum(axis=1), 3)))), linewidth=8) plt.plot(gaussian_filter1d(img_patch_org.sum(axis=1), 3),np.array(range(len(gaussian_filter1d(img_patch_org.sum(axis=1), 3)))),linewidth=8)
plt.xlabel("Density of textline prediction in direction of X axis", fontsize=60) plt.xlabel('Density of textline prediction in direction of X axis',fontsize=60)
plt.ylabel("Height", fontsize=60) plt.ylabel('Height',fontsize=60)
plt.yticks([0, len(gaussian_filter1d(img_patch_org.sum(axis=1), 3))]) plt.yticks([0,len(gaussian_filter1d(img_patch_org.sum(axis=1), 3))])
plt.gca().invert_yaxis() plt.gca().invert_yaxis()
plt.savefig(os.path.join(dir_of_all, f_name + "_density_of_textline.png")) plt.savefig(os.path.join(dir_of_all, f_name+'_density_of_textline.png'))
# print(np.max(img_patch_org.sum(axis=0)) ,np.max(img_patch_org.sum(axis=1)),'axislar') #print(np.max(img_patch_org.sum(axis=0)) ,np.max(img_patch_org.sum(axis=1)),'axislar')
# img_patch_org=resize_image(img_patch_org,int(img_patch_org.shape[0]*2.5),int(img_patch_org.shape[1]/2.5)) #img_patch_org=resize_image(img_patch_org,int(img_patch_org.shape[0]*2.5),int(img_patch_org.shape[1]/2.5))
# print(np.max(img_patch_org.sum(axis=0)) ,np.max(img_patch_org.sum(axis=1)),'axislar2') #print(np.max(img_patch_org.sum(axis=0)) ,np.max(img_patch_org.sum(axis=1)),'axislar2')
img_int = np.zeros((img_patch_org.shape[0], img_patch_org.shape[1])) img_int=np.zeros((img_patch_org.shape[0],img_patch_org.shape[1]))
img_int[:, :] = img_patch_org[:, :] # img_patch_org[:,:,0] img_int[:,:]=img_patch_org[:,:]#img_patch_org[:,:,0]
img_resized = np.zeros((int(img_int.shape[0] * (1.8)), int(img_int.shape[1] * (2.6))))
img_resized[int(img_int.shape[0] * (0.4)) : int(img_int.shape[0] * (0.4)) + img_int.shape[0], int(img_int.shape[1] * (0.8)) : int(img_int.shape[1] * (0.8)) + img_int.shape[1]] = img_int[:, :]
if main_page and img_patch_org.shape[1] > img_patch_org.shape[0]: max_shape=np.max(img_int.shape)
img_resized=np.zeros((int( max_shape*(1.1) ) , int( max_shape*(1.1) ) ))
# plt.imshow(img_resized)
# plt.show() onset_x=int((img_resized.shape[1]-img_int.shape[1])/2.)
angels = np.array( onset_y=int((img_resized.shape[0]-img_int.shape[0])/2.)
[
-45,
0, #img_resized=np.zeros((int( img_int.shape[0]*(1.8) ) , int( img_int.shape[1]*(2.6) ) ))
45,
90,
]
) # np.linspace(-12,12,100)#np.array([0 , 45 , 90 , -45]) #img_resized[ int( img_int.shape[0]*(.4)):int( img_int.shape[0]*(.4))+img_int.shape[0] , int( img_int.shape[1]*(.8)):int( img_int.shape[1]*(.8))+img_int.shape[1] ]=img_int[:,:]
img_resized[ onset_y:onset_y+img_int.shape[0] , onset_x:onset_x+img_int.shape[1] ]=img_int[:,:]
res = []
num_of_peaks = [] #print(img_resized.shape,'img_resizedshape')
index_cor = [] #plt.imshow(img_resized)
var_res = [] #plt.show()
indexer = 0 if main_page and img_patch_org.shape[1]>img_patch_org.shape[0]:
#plt.imshow(img_resized)
#plt.show()
angels=np.array([-45, 0 , 45 , 90 , ])#np.linspace(-12,12,100)#np.array([0 , 45 , 90 , -45])
#res=[]
#num_of_peaks=[]
#index_cor=[]
var_res=[]
#indexer=0
for rot in angels: for rot in angels:
img_rot = rotate_image(img_resized, rot) img_rot=self.rotate_image(img_resized,rot)
# plt.imshow(img_rot) #plt.imshow(img_rot)
# plt.show() #plt.show()
img_rot[img_rot != 0] = 1 img_rot[img_rot!=0]=1
# res_me=np.mean(find_num_col_deskew(img_rot,sigma_des,2.0 )) #res_me=np.mean(self.find_num_col_deskew(img_rot,sigma_des,2.0 ))
# neg_peaks,var_spectrum=find_num_col_deskew(img_rot,sigma_des,20.3 )
# print(var_spectrum,'var_spectrum')
try:
neg_peaks, var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3)
# print(rot,var_spectrum,'var_spectrum')
res_me = np.mean(neg_peaks)
if res_me == 0:
res_me = VERY_LARGE_NUMBER
else:
pass
res_num = len(neg_peaks) #neg_peaks,var_spectrum=self.find_num_col_deskew(img_rot,sigma_des,20.3 )
#print(var_spectrum,'var_spectrum')
try:
var_spectrum=self.find_num_col_deskew(img_rot,sigma_des,20.3 )
##print(rot,var_spectrum,'var_spectrum')
#res_me=np.mean(neg_peaks)
#if res_me==0:
#res_me=1000000000000000000000
#else:
#pass
#res_num=len(neg_peaks)
except: except:
res_me = VERY_LARGE_NUMBER #res_me=1000000000000000000000
res_num = 0 #res_num=0
var_spectrum = 0 var_spectrum=0
if isNaN(res_me): #if self.isNaN(res_me):
pass #pass
else: #else:
res.append(res_me) #res.append( res_me )
var_res.append(var_spectrum) #var_res.append(var_spectrum)
num_of_peaks.append(res_num) #num_of_peaks.append( res_num )
index_cor.append(indexer) #index_cor.append(indexer)
indexer = indexer + 1 #indexer=indexer+1
var_res.append(var_spectrum)
#index_cor.append(indexer)
#indexer=indexer+1
try: try:
var_res = np.array(var_res) var_res=np.array(var_res)
ang_int = angels[np.argmax(var_res)] # angels_sorted[arg_final]#angels[arg_sort_early[arg_sort[arg_final]]]#angels[arg_fin] ang_int=angels[np.argmax(var_res)]#angels_sorted[arg_final]#angels[arg_sort_early[arg_sort[arg_final]]]#angels[arg_fin]
except: except:
ang_int = 0 ang_int=0
angels = np.linspace(ang_int - 22.5, ang_int + 22.5, 100) angels=np.linspace(ang_int-22.5,ang_int+22.5,100)
#res=[]
#num_of_peaks=[]
#index_cor=[]
var_res=[]
res = []
num_of_peaks = []
index_cor = []
var_res = []
indexer = 0
for rot in angels: for rot in angels:
img_rot = rotate_image(img_resized, rot) img_rot=self.rotate_image(img_resized,rot)
##plt.imshow(img_rot) ##plt.imshow(img_rot)
##plt.show() ##plt.show()
img_rot[img_rot != 0] = 1 img_rot[img_rot!=0]=1
# res_me=np.mean(find_num_col_deskew(img_rot,sigma_des,2.0 )) #res_me=np.mean(self.find_num_col_deskew(img_rot,sigma_des,2.0 ))
try: try:
neg_peaks, var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3) var_spectrum=self.find_num_col_deskew(img_rot,sigma_des,20.3 )
# print(indexer,'indexer')
res_me = np.mean(neg_peaks)
if res_me == 0:
res_me = VERY_LARGE_NUMBER
else:
pass
res_num = len(neg_peaks)
except: except:
res_me = VERY_LARGE_NUMBER var_spectrum=0
res_num = 0
var_spectrum = 0 var_res.append(var_spectrum)
if isNaN(res_me):
pass
else:
res.append(res_me)
var_res.append(var_spectrum)
num_of_peaks.append(res_num)
index_cor.append(indexer)
indexer = indexer + 1
try: try:
var_res = np.array(var_res) var_res=np.array(var_res)
ang_int = angels[np.argmax(var_res)] # angels_sorted[arg_final]#angels[arg_sort_early[arg_sort[arg_final]]]#angels[arg_fin] ang_int=angels[np.argmax(var_res)]#angels_sorted[arg_final]#angels[arg_sort_early[arg_sort[arg_final]]]#angels[arg_fin]
except: except:
ang_int = 0 ang_int=0
elif main_page and img_patch_org.shape[1] <= img_patch_org.shape[0]: elif main_page and img_patch_org.shape[1]<=img_patch_org.shape[0]:
# plt.imshow(img_resized) #plt.imshow(img_resized)
# plt.show() #plt.show()
angels = np.linspace(-12, 12, 100) # np.array([0 , 45 , 90 , -45]) angels=np.linspace(-12,12,100)#np.array([0 , 45 , 90 , -45])
res = []
num_of_peaks = []
index_cor = []
var_res = []
indexer = 0 var_res=[]
for rot in angels: for rot in angels:
img_rot = rotate_image(img_resized, rot) img_rot=self.rotate_image(img_resized,rot)
# plt.imshow(img_rot) #plt.imshow(img_rot)
# plt.show() #plt.show()
img_rot[img_rot != 0] = 1 img_rot[img_rot!=0]=1
# res_me=np.mean(find_num_col_deskew(img_rot,sigma_des,2.0 )) #res_me=np.mean(self.find_num_col_deskew(img_rot,sigma_des,2.0 ))
# neg_peaks,var_spectrum=find_num_col_deskew(img_rot,sigma_des,20.3 )
# print(var_spectrum,'var_spectrum') #neg_peaks,var_spectrum=self.find_num_col_deskew(img_rot,sigma_des,20.3 )
#print(var_spectrum,'var_spectrum')
try: try:
neg_peaks, var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3) var_spectrum=self.find_num_col_deskew(img_rot,sigma_des,20.3 )
# print(rot,var_spectrum,'var_spectrum')
res_me = np.mean(neg_peaks)
if res_me == 0:
res_me = VERY_LARGE_NUMBER
else:
pass
res_num = len(neg_peaks)
except: except:
res_me = VERY_LARGE_NUMBER var_spectrum=0
res_num = 0
var_spectrum = 0 var_res.append(var_spectrum)
if isNaN(res_me):
pass
else: if self.dir_of_all is not None:
res.append(res_me) #print('galdi?')
var_res.append(var_spectrum) plt.figure(figsize=(60,30))
num_of_peaks.append(res_num) plt.rcParams['font.size']='50'
index_cor.append(indexer) plt.plot(angels,np.array(var_res),'-o',markersize=25,linewidth=4)
indexer = indexer + 1 plt.xlabel('angle',fontsize=50)
plt.ylabel('variance of sum of rotated textline in direction of x axis',fontsize=50)
if dir_of_all is not None:
print("galdi?") plt.plot(angels[np.argmax(var_res)],var_res[np.argmax(np.array(var_res))] ,'*',markersize=50,label='Angle of deskewing=' +str("{:.2f}".format(angels[np.argmax(var_res)]))+r'$\degree$')
plt.figure(figsize=(60, 30)) plt.legend(loc='best')
plt.rcParams["font.size"] = "50" plt.savefig(os.path.join(self.dir_of_all,self.f_name+'_rotation_angle.png'))
plt.plot(angels, np.array(var_res), "-o", markersize=25, linewidth=4)
plt.xlabel("angle", fontsize=50)
plt.ylabel("variance of sum of rotated textline in direction of x axis", fontsize=50)
plt.plot(angels[np.argmax(var_res)], var_res[np.argmax(np.array(var_res))], "*", markersize=50, label="Angle of deskewing=" + str("{:.2f}".format(angels[np.argmax(var_res)])) + r"$\degree$")
plt.legend(loc="best")
plt.savefig(os.path.join(dir_of_all, f_name + "_rotation_angle.png"))
try: try:
var_res = np.array(var_res) var_res=np.array(var_res)
ang_int = angels[np.argmax(var_res)] # angels_sorted[arg_final]#angels[arg_sort_early[arg_sort[arg_final]]]#angels[arg_fin] ang_int=angels[np.argmax(var_res)]#angels_sorted[arg_final]#angels[arg_sort_early[arg_sort[arg_final]]]#angels[arg_fin]
except: except:
ang_int = 0 ang_int=0
early_slope_edge = 11 early_slope_edge=11
if abs(ang_int) > early_slope_edge and ang_int < 0: if abs(ang_int)>early_slope_edge and ang_int<0:
angels = np.linspace(-90, -12, 100) angels=np.linspace(-90,-12,100)
res = [] var_res=[]
num_of_peaks = []
index_cor = []
var_res = []
indexer = 0
for rot in angels: for rot in angels:
img_rot = rotate_image(img_resized, rot) img_rot=self.rotate_image(img_resized,rot)
##plt.imshow(img_rot) ##plt.imshow(img_rot)
##plt.show() ##plt.show()
img_rot[img_rot != 0] = 1 img_rot[img_rot!=0]=1
# res_me=np.mean(find_num_col_deskew(img_rot,sigma_des,2.0 )) #res_me=np.mean(self.find_num_col_deskew(img_rot,sigma_des,2.0 ))
try: try:
neg_peaks, var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3) var_spectrum=self.find_num_col_deskew(img_rot,sigma_des,20.3 )
# print(indexer,'indexer')
res_me = np.mean(neg_peaks)
if res_me == 0:
res_me = VERY_LARGE_NUMBER
else:
pass
res_num = len(neg_peaks)
except: except:
res_me = VERY_LARGE_NUMBER var_spectrum=0
res_num = 0
var_spectrum = 0 var_res.append(var_spectrum)
if isNaN(res_me):
pass
else:
res.append(res_me)
var_res.append(var_spectrum)
num_of_peaks.append(res_num)
index_cor.append(indexer)
indexer = indexer + 1
try: try:
var_res = np.array(var_res) var_res=np.array(var_res)
ang_int = angels[np.argmax(var_res)] # angels_sorted[arg_final]#angels[arg_sort_early[arg_sort[arg_final]]]#angels[arg_fin] ang_int=angels[np.argmax(var_res)]#angels_sorted[arg_final]#angels[arg_sort_early[arg_sort[arg_final]]]#angels[arg_fin]
except: except:
ang_int = 0 ang_int=0
elif abs(ang_int) > early_slope_edge and ang_int > 0: elif abs(ang_int)>early_slope_edge and ang_int>0:
angels = np.linspace(90, 12, 100) angels=np.linspace(90,12,100)
res = []
num_of_peaks = []
index_cor = []
var_res = []
indexer = 0 var_res=[]
for rot in angels: for rot in angels:
img_rot = rotate_image(img_resized, rot) img_rot=self.rotate_image(img_resized,rot)
##plt.imshow(img_rot) ##plt.imshow(img_rot)
##plt.show() ##plt.show()
img_rot[img_rot != 0] = 1 img_rot[img_rot!=0]=1
# res_me=np.mean(find_num_col_deskew(img_rot,sigma_des,2.0 )) #res_me=np.mean(self.find_num_col_deskew(img_rot,sigma_des,2.0 ))
try: try:
neg_peaks, var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3) var_spectrum=self.find_num_col_deskew(img_rot,sigma_des,20.3 )
# print(indexer,'indexer') #print(indexer,'indexer')
res_me = np.mean(neg_peaks)
if res_me == 0:
res_me = VERY_LARGE_NUMBER
else:
pass
res_num = len(neg_peaks)
except: except:
res_me = VERY_LARGE_NUMBER var_spectrum=0
res_num = 0
var_spectrum = 0 var_res.append(var_spectrum)
if isNaN(res_me):
pass
else:
res.append(res_me)
var_res.append(var_spectrum)
num_of_peaks.append(res_num)
index_cor.append(indexer)
indexer = indexer + 1
try: try:
var_res = np.array(var_res) var_res=np.array(var_res)
ang_int = angels[np.argmax(var_res)] # angels_sorted[arg_final]#angels[arg_sort_early[arg_sort[arg_final]]]#angels[arg_fin] ang_int=angels[np.argmax(var_res)]#angels_sorted[arg_final]#angels[arg_sort_early[arg_sort[arg_final]]]#angels[arg_fin]
except: except:
ang_int = 0 ang_int=0
else: else:
angels = np.linspace(-25, 25, 60)
res = [] angels=np.linspace(-25,25,60)
num_of_peaks = []
index_cor = [] var_res=[]
var_res = []
indexer = 0 indexer=0
for rot in angels: for rot in angels:
img_rot = rotate_image(img_resized, rot) img_rot=self.rotate_image(img_resized,rot)
# plt.imshow(img_rot) #plt.imshow(img_rot)
# plt.show() #plt.show()
img_rot[img_rot != 0] = 1 img_rot[img_rot!=0]=1
# res_me=np.mean(find_num_col_deskew(img_rot,sigma_des,2.0 )) #res_me=np.mean(self.find_num_col_deskew(img_rot,sigma_des,2.0 ))
# neg_peaks,var_spectrum=find_num_col_deskew(img_rot,sigma_des,20.3 )
# print(var_spectrum,'var_spectrum')
try:
neg_peaks, var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3)
# print(rot,var_spectrum,'var_spectrum')
res_me = np.mean(neg_peaks)
if res_me == 0:
res_me = VERY_LARGE_NUMBER
else:
pass
res_num = len(neg_peaks) #neg_peaks,var_spectrum=self.find_num_col_deskew(img_rot,sigma_des,20.3 )
#print(var_spectrum,'var_spectrum')
try:
var_spectrum=self.find_num_col_deskew(img_rot,sigma_des,20.3 )
except: except:
res_me = VERY_LARGE_NUMBER var_spectrum=0
res_num = 0
var_spectrum = 0 var_res.append(var_spectrum)
if isNaN(res_me):
pass
else:
res.append(res_me)
var_res.append(var_spectrum)
num_of_peaks.append(res_num)
index_cor.append(indexer)
indexer = indexer + 1
try: try:
var_res = np.array(var_res) var_res=np.array(var_res)
ang_int = angels[np.argmax(var_res)] # angels_sorted[arg_final]#angels[arg_sort_early[arg_sort[arg_final]]]#angels[arg_fin] ang_int=angels[np.argmax(var_res)]#angels_sorted[arg_final]#angels[arg_sort_early[arg_sort[arg_final]]]#angels[arg_fin]
except: except:
ang_int = 0 ang_int=0
#plt.plot(var_res)
#plt.show()
# print(ang_int,'ang_int') ##plt.plot(mom3_res)
##plt.show()
#print(ang_int,'ang_int111')
early_slope_edge = 22 early_slope_edge=22
if abs(ang_int) > early_slope_edge and ang_int < 0: if abs(ang_int)>early_slope_edge and ang_int<0:
angels = np.linspace(-90, -25, 60) angels=np.linspace(-90,-25,60)
res = [] var_res=[]
num_of_peaks = []
index_cor = []
var_res = []
indexer = 0
for rot in angels: for rot in angels:
img_rot = rotate_image(img_resized, rot) img_rot=self.rotate_image(img_resized,rot)
##plt.imshow(img_rot) ##plt.imshow(img_rot)
##plt.show() ##plt.show()
img_rot[img_rot != 0] = 1 img_rot[img_rot!=0]=1
# res_me=np.mean(find_num_col_deskew(img_rot,sigma_des,2.0 )) #res_me=np.mean(self.find_num_col_deskew(img_rot,sigma_des,2.0 ))
try: try:
neg_peaks, var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3) var_spectrum=self.find_num_col_deskew(img_rot,sigma_des,20.3 )
# print(indexer,'indexer')
res_me = np.mean(neg_peaks)
if res_me == 0:
res_me = VERY_LARGE_NUMBER
else:
pass
res_num = len(neg_peaks)
except: except:
res_me = VERY_LARGE_NUMBER var_spectrum=0
res_num = 0
var_spectrum = 0 var_res.append(var_spectrum)
if isNaN(res_me):
pass
else:
res.append(res_me)
var_res.append(var_spectrum)
num_of_peaks.append(res_num)
index_cor.append(indexer)
indexer = indexer + 1
try: try:
var_res = np.array(var_res) var_res=np.array(var_res)
ang_int = angels[np.argmax(var_res)] # angels_sorted[arg_final]#angels[arg_sort_early[arg_sort[arg_final]]]#angels[arg_fin] ang_int=angels[np.argmax(var_res)]#angels_sorted[arg_final]#angels[arg_sort_early[arg_sort[arg_final]]]#angels[arg_fin]
except: except:
ang_int = 0 ang_int=0
elif abs(ang_int) > early_slope_edge and ang_int > 0: elif abs(ang_int)>early_slope_edge and ang_int>0:
angels = np.linspace(90, 25, 60) angels=np.linspace(90,25,60)
res = [] var_res=[]
num_of_peaks = []
index_cor = []
var_res = []
indexer = 0 indexer=0
for rot in angels: for rot in angels:
img_rot = rotate_image(img_resized, rot) img_rot=self.rotate_image(img_resized,rot)
##plt.imshow(img_rot) ##plt.imshow(img_rot)
##plt.show() ##plt.show()
img_rot[img_rot != 0] = 1 img_rot[img_rot!=0]=1
# res_me=np.mean(find_num_col_deskew(img_rot,sigma_des,2.0 )) #res_me=np.mean(self.find_num_col_deskew(img_rot,sigma_des,2.0 ))
try: try:
neg_peaks, var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3) var_spectrum=self.find_num_col_deskew(img_rot,sigma_des,20.3 )
# print(indexer,'indexer') #print(indexer,'indexer')
res_me = np.mean(neg_peaks)
if res_me == 0:
res_me = VERY_LARGE_NUMBER
else:
pass
res_num = len(neg_peaks)
except: except:
res_me = VERY_LARGE_NUMBER var_spectrum=0
res_num = 0
var_spectrum = 0 var_res.append(var_spectrum)
if isNaN(res_me):
pass
else:
res.append(res_me)
var_res.append(var_spectrum)
num_of_peaks.append(res_num)
index_cor.append(indexer)
indexer = indexer + 1
try: try:
var_res = np.array(var_res) var_res=np.array(var_res)
ang_int = angels[np.argmax(var_res)] # angels_sorted[arg_final]#angels[arg_sort_early[arg_sort[arg_final]]]#angels[arg_fin] ang_int=angels[np.argmax(var_res)]#angels_sorted[arg_final]#angels[arg_sort_early[arg_sort[arg_final]]]#angels[arg_fin]
except: except:
ang_int = 0 ang_int=0
return ang_int return ang_int
def put_drop_out_from_only_drop_model(layout_no_patch, layout1): def put_drop_out_from_only_drop_model(layout_no_patch, layout1):
drop_only = (layout_no_patch[:, :, 0] == 4) * 1 drop_only = (layout_no_patch[:, :, 0] == 4) * 1
@ -2825,12 +2746,12 @@ def putt_bb_of_drop_capitals_of_model_in_patches_in_layout(layout_in_patch):
return layout_in_patch return layout_in_patch
def check_any_text_region_in_model_one_is_main_or_header(regions_model_1, regions_model_full, contours_only_text_parent, all_box_coord, all_found_texline_polygons, slopes, contours_only_text_parent_d_ordered): def check_any_text_region_in_model_one_is_main_or_header(regions_model_1,regions_model_full,contours_only_text_parent,all_box_coord,all_found_texline_polygons,slopes,contours_only_text_parent_d_ordered):
text_only = (regions_model_1[:, :] == 1) * 1 #text_only=(regions_model_1[:,:]==1)*1
contours_only_text, hir_on_text = return_contours_of_image(text_only) #contours_only_text,hir_on_text=self.return_contours_of_image(text_only)
""" """
contours_only_text_parent=return_parent_contours( contours_only_text,hir_on_text) contours_only_text_parent=self.return_parent_contours( contours_only_text,hir_on_text)
areas_cnt_text=np.array([cv2.contourArea(contours_only_text_parent[j]) for j in range(len(contours_only_text_parent))]) areas_cnt_text=np.array([cv2.contourArea(contours_only_text_parent[j]) for j in range(len(contours_only_text_parent))])
areas_cnt_text=areas_cnt_text/float(text_only.shape[0]*text_only.shape[1]) areas_cnt_text=areas_cnt_text/float(text_only.shape[0]*text_only.shape[1])
@ -2842,38 +2763,43 @@ def check_any_text_region_in_model_one_is_main_or_header(regions_model_1, region
contours_only_text_parent=[contours_only_text_parent[jz] for jz in range(len(contours_only_text_parent)) if areas_cnt_text[jz]>0.00001] contours_only_text_parent=[contours_only_text_parent[jz] for jz in range(len(contours_only_text_parent)) if areas_cnt_text[jz]>0.00001]
""" """
cx_main, cy_main, x_min_main, x_max_main, y_min_main, y_max_main, y_corr_x_min_from_argmin = find_new_features_of_contoures(contours_only_text_parent) cx_main,cy_main ,x_min_main , x_max_main, y_min_main ,y_max_main,y_corr_x_min_from_argmin=self.find_new_features_of_contoures(contours_only_text_parent)
length_con = x_max_main - x_min_main length_con=x_max_main-x_min_main
height_con = y_max_main - y_min_main height_con=y_max_main-y_min_main
all_found_texline_polygons_main = []
all_found_texline_polygons_head = []
all_box_coord_main = []
all_box_coord_head = []
slopes_main = [] all_found_texline_polygons_main=[]
slopes_head = [] all_found_texline_polygons_head=[]
contours_only_text_parent_main = [] all_box_coord_main=[]
contours_only_text_parent_head = [] all_box_coord_head=[]
contours_only_text_parent_main_d = [] slopes_main=[]
contours_only_text_parent_head_d = [] slopes_head=[]
contours_only_text_parent_main=[]
contours_only_text_parent_head=[]
contours_only_text_parent_main_d=[]
contours_only_text_parent_head_d=[]
for ii in range(len(contours_only_text_parent)): for ii in range(len(contours_only_text_parent)):
con = contours_only_text_parent[ii] con=contours_only_text_parent[ii]
img = np.zeros((regions_model_1.shape[0], regions_model_1.shape[1], 3)) img=np.zeros((regions_model_1.shape[0],regions_model_1.shape[1],3))
img = cv2.fillPoly(img, pts=[con], color=(255, 255, 255)) img = cv2.fillPoly(img, pts=[con], color=(255, 255, 255))
all_pixels = ((img[:, :, 0] == 255) * 1).sum()
pixels_header = (((img[:, :, 0] == 255) & (regions_model_full[:, :, 0] == 2)) * 1).sum()
pixels_main = all_pixels - pixels_header
if (pixels_header >= pixels_main) and ((length_con[ii] / float(height_con[ii])) >= 1.3): all_pixels=((img[:,:,0]==255)*1).sum()
regions_model_1[:, :][(regions_model_1[:, :] == 1) & (img[:, :, 0] == 255)] = 2
pixels_header=( ( (img[:,:,0]==255) & (regions_model_full[:,:,0]==2) )*1 ).sum()
pixels_main=all_pixels-pixels_header
if (pixels_header>=pixels_main) and ( (length_con[ii]/float(height_con[ii]) )>=1.3 ):
regions_model_1[:,:][(regions_model_1[:,:]==1) & (img[:,:,0]==255) ]=2
contours_only_text_parent_head.append(con) contours_only_text_parent_head.append(con)
if contours_only_text_parent_d_ordered is not None: if contours_only_text_parent_d_ordered is not None:
contours_only_text_parent_head_d.append(contours_only_text_parent_d_ordered[ii]) contours_only_text_parent_head_d.append(contours_only_text_parent_d_ordered[ii])
@ -2881,7 +2807,7 @@ def check_any_text_region_in_model_one_is_main_or_header(regions_model_1, region
slopes_head.append(slopes[ii]) slopes_head.append(slopes[ii])
all_found_texline_polygons_head.append(all_found_texline_polygons[ii]) all_found_texline_polygons_head.append(all_found_texline_polygons[ii])
else: else:
regions_model_1[:, :][(regions_model_1[:, :] == 1) & (img[:, :, 0] == 255)] = 1 regions_model_1[:,:][(regions_model_1[:,:]==1) & (img[:,:,0]==255) ]=1
contours_only_text_parent_main.append(con) contours_only_text_parent_main.append(con)
if contours_only_text_parent_d_ordered is not None: if contours_only_text_parent_d_ordered is not None:
contours_only_text_parent_main_d.append(contours_only_text_parent_d_ordered[ii]) contours_only_text_parent_main_d.append(contours_only_text_parent_d_ordered[ii])
@ -2889,11 +2815,13 @@ def check_any_text_region_in_model_one_is_main_or_header(regions_model_1, region
slopes_main.append(slopes[ii]) slopes_main.append(slopes[ii])
all_found_texline_polygons_main.append(all_found_texline_polygons[ii]) all_found_texline_polygons_main.append(all_found_texline_polygons[ii])
# print(all_pixels,pixels_main,pixels_header) #print(all_pixels,pixels_main,pixels_header)
# plt.imshow(img[:,:,0])
# plt.show()
return regions_model_1, contours_only_text_parent_main, contours_only_text_parent_head, all_box_coord_main, all_box_coord_head, all_found_texline_polygons_main, all_found_texline_polygons_head, slopes_main, slopes_head, contours_only_text_parent_main_d, contours_only_text_parent_head_d #plt.imshow(img[:,:,0])
#plt.show()
return regions_model_1,contours_only_text_parent_main,contours_only_text_parent_head,all_box_coord_main,all_box_coord_head,all_found_texline_polygons_main,all_found_texline_polygons_head,slopes_main,slopes_head,contours_only_text_parent_main_d,contours_only_text_parent_head_d
def small_textlines_to_parent_adherence2(textlines_con, textline_iamge, num_col): def small_textlines_to_parent_adherence2(textlines_con, textline_iamge, num_col):
# print(textlines_con) # print(textlines_con)

Loading…
Cancel
Save