|
|
@ -17,6 +17,7 @@ from . import (
|
|
|
|
isNaN,
|
|
|
|
isNaN,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def dedup_separate_lines(img_patch, contour_text_interest, thetha, axis):
|
|
|
|
def dedup_separate_lines(img_patch, contour_text_interest, thetha, axis):
|
|
|
|
(h, w) = img_patch.shape[:2]
|
|
|
|
(h, w) = img_patch.shape[:2]
|
|
|
|
center = (w // 2, h // 2)
|
|
|
|
center = (w // 2, h // 2)
|
|
|
@ -125,8 +126,8 @@ def dedup_separate_lines(img_patch, contour_text_interest, thetha, axis):
|
|
|
|
|
|
|
|
|
|
|
|
return x, y, x_d, y_d, xv, x_min_cont, y_min_cont, x_max_cont, y_max_cont, first_nonzero, y_padded_up_to_down_padded, y_padded_smoothed, peaks, peaks_neg, rotation_matrix
|
|
|
|
return x, y, x_d, y_d, xv, x_min_cont, y_min_cont, x_max_cont, y_max_cont, first_nonzero, y_padded_up_to_down_padded, y_padded_smoothed, peaks, peaks_neg, rotation_matrix
|
|
|
|
|
|
|
|
|
|
|
|
def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
(h, w) = img_patch.shape[:2]
|
|
|
|
(h, w) = img_patch.shape[:2]
|
|
|
|
center = (w // 2, h // 2)
|
|
|
|
center = (w // 2, h // 2)
|
|
|
|
M = cv2.getRotationMatrix2D(center, -thetha, 1.0)
|
|
|
|
M = cv2.getRotationMatrix2D(center, -thetha, 1.0)
|
|
|
@ -170,20 +171,17 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
y_padded_up_to_down_padded_e[20:len(y_padded_up_to_down_e) + 20] = y_padded_up_to_down_e
|
|
|
|
y_padded_up_to_down_padded_e[20:len(y_padded_up_to_down_e) + 20] = y_padded_up_to_down_e
|
|
|
|
y_padded_up_to_down_padded_e = gaussian_filter1d(y_padded_up_to_down_padded_e, 2)
|
|
|
|
y_padded_up_to_down_padded_e = gaussian_filter1d(y_padded_up_to_down_padded_e, 2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
peaks_e, _ = find_peaks(y_padded_smoothed_e, height=0)
|
|
|
|
peaks_e, _ = find_peaks(y_padded_smoothed_e, height=0)
|
|
|
|
peaks_neg_e, _ = find_peaks(y_padded_up_to_down_padded_e, height=0)
|
|
|
|
peaks_neg_e, _ = find_peaks(y_padded_up_to_down_padded_e, height=0)
|
|
|
|
neg_peaks_max = np.max(y_padded_up_to_down_padded_e[peaks_neg_e])
|
|
|
|
neg_peaks_max = np.max(y_padded_up_to_down_padded_e[peaks_neg_e])
|
|
|
|
|
|
|
|
|
|
|
|
arg_neg_must_be_deleted= np.array(range(len(peaks_neg_e)))[y_padded_up_to_down_padded_e[peaks_neg_e]/float(neg_peaks_max)<0.3 ]
|
|
|
|
arg_neg_must_be_deleted = np.array(range(len(peaks_neg_e)))[
|
|
|
|
|
|
|
|
y_padded_up_to_down_padded_e[peaks_neg_e] / float(neg_peaks_max) < 0.3]
|
|
|
|
diff_arg_neg_must_be_deleted = np.diff(arg_neg_must_be_deleted)
|
|
|
|
diff_arg_neg_must_be_deleted = np.diff(arg_neg_must_be_deleted)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
arg_diff = np.array(range(len(diff_arg_neg_must_be_deleted)))
|
|
|
|
arg_diff = np.array(range(len(diff_arg_neg_must_be_deleted)))
|
|
|
|
arg_diff_cluster = arg_diff[diff_arg_neg_must_be_deleted > 1]
|
|
|
|
arg_diff_cluster = arg_diff[diff_arg_neg_must_be_deleted > 1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
peaks_new = peaks_e[:]
|
|
|
|
peaks_new = peaks_e[:]
|
|
|
|
peaks_neg_new = peaks_neg_e[:]
|
|
|
|
peaks_neg_new = peaks_neg_e[:]
|
|
|
|
|
|
|
|
|
|
|
@ -192,10 +190,10 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
|
|
|
|
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted[0:arg_diff_cluster[0] + 1])
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted[0:arg_diff_cluster[0] + 1])
|
|
|
|
for i in range(len(arg_diff_cluster) - 1):
|
|
|
|
for i in range(len(arg_diff_cluster) - 1):
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted[arg_diff_cluster[i]+1:arg_diff_cluster[i+1]+1])
|
|
|
|
clusters_to_be_deleted.append(
|
|
|
|
|
|
|
|
arg_neg_must_be_deleted[arg_diff_cluster[i] + 1:arg_diff_cluster[i + 1] + 1])
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted[arg_diff_cluster[len(arg_diff_cluster) - 1] + 1:])
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted[arg_diff_cluster[len(arg_diff_cluster) - 1] + 1:])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(clusters_to_be_deleted) > 0:
|
|
|
|
if len(clusters_to_be_deleted) > 0:
|
|
|
|
peaks_new_extra = []
|
|
|
|
peaks_new_extra = []
|
|
|
|
for m in range(len(clusters_to_be_deleted)):
|
|
|
|
for m in range(len(clusters_to_be_deleted)):
|
|
|
@ -214,11 +212,9 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
peaks_new_tot.append(i1)
|
|
|
|
peaks_new_tot.append(i1)
|
|
|
|
peaks_new_tot = np.sort(peaks_new_tot)
|
|
|
|
peaks_new_tot = np.sort(peaks_new_tot)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
peaks_new_tot = peaks_e[:]
|
|
|
|
peaks_new_tot = peaks_e[:]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
textline_con, hierarchy = return_contours_of_image(img_patch)
|
|
|
|
textline_con, hierarchy = return_contours_of_image(img_patch)
|
|
|
|
textline_con_fil = filter_contours_area_of_image(img_patch, textline_con, hierarchy, max_area=1, min_area=0.0008)
|
|
|
|
textline_con_fil = filter_contours_area_of_image(img_patch, textline_con, hierarchy, max_area=1, min_area=0.0008)
|
|
|
|
y_diff_mean = np.mean(np.diff(peaks_new_tot)) # self.find_contours_mean_y_diff(textline_con_fil)
|
|
|
|
y_diff_mean = np.mean(np.diff(peaks_new_tot)) # self.find_contours_mean_y_diff(textline_con_fil)
|
|
|
@ -231,60 +227,46 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
sigma_gaus = 3
|
|
|
|
sigma_gaus = 3
|
|
|
|
# print(sigma_gaus,'sigma')
|
|
|
|
# print(sigma_gaus,'sigma')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
y_padded_smoothed = gaussian_filter1d(y_padded, sigma_gaus)
|
|
|
|
y_padded_smoothed = gaussian_filter1d(y_padded, sigma_gaus)
|
|
|
|
y_padded_up_to_down = -y_padded + np.max(y_padded)
|
|
|
|
y_padded_up_to_down = -y_padded + np.max(y_padded)
|
|
|
|
y_padded_up_to_down_padded = np.zeros(len(y_padded_up_to_down) + 40)
|
|
|
|
y_padded_up_to_down_padded = np.zeros(len(y_padded_up_to_down) + 40)
|
|
|
|
y_padded_up_to_down_padded[20:len(y_padded_up_to_down) + 20] = y_padded_up_to_down
|
|
|
|
y_padded_up_to_down_padded[20:len(y_padded_up_to_down) + 20] = y_padded_up_to_down
|
|
|
|
y_padded_up_to_down_padded = gaussian_filter1d(y_padded_up_to_down_padded, sigma_gaus)
|
|
|
|
y_padded_up_to_down_padded = gaussian_filter1d(y_padded_up_to_down_padded, sigma_gaus)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
peaks, _ = find_peaks(y_padded_smoothed, height=0)
|
|
|
|
peaks, _ = find_peaks(y_padded_smoothed, height=0)
|
|
|
|
peaks_neg, _ = find_peaks(y_padded_up_to_down_padded, height=0)
|
|
|
|
peaks_neg, _ = find_peaks(y_padded_up_to_down_padded, height=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
neg_peaks_max = np.max(y_padded_smoothed[peaks])
|
|
|
|
neg_peaks_max = np.max(y_padded_smoothed[peaks])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
arg_neg_must_be_deleted = np.array(range(len(peaks_neg)))[y_padded_up_to_down_padded[peaks_neg] / float(neg_peaks_max) < 0.42]
|
|
|
|
arg_neg_must_be_deleted = np.array(range(len(peaks_neg)))[y_padded_up_to_down_padded[peaks_neg] / float(neg_peaks_max) < 0.42]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
diff_arg_neg_must_be_deleted = np.diff(arg_neg_must_be_deleted)
|
|
|
|
diff_arg_neg_must_be_deleted = np.diff(arg_neg_must_be_deleted)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
arg_diff = np.array(range(len(diff_arg_neg_must_be_deleted)))
|
|
|
|
arg_diff = np.array(range(len(diff_arg_neg_must_be_deleted)))
|
|
|
|
arg_diff_cluster = arg_diff[diff_arg_neg_must_be_deleted > 1]
|
|
|
|
arg_diff_cluster = arg_diff[diff_arg_neg_must_be_deleted > 1]
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
arg_neg_must_be_deleted = []
|
|
|
|
arg_neg_must_be_deleted = []
|
|
|
|
arg_diff_cluster = []
|
|
|
|
arg_diff_cluster = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
peaks_new = peaks[:]
|
|
|
|
peaks_new = peaks[:]
|
|
|
|
peaks_neg_new = peaks_neg[:]
|
|
|
|
peaks_neg_new = peaks_neg[:]
|
|
|
|
clusters_to_be_deleted = []
|
|
|
|
clusters_to_be_deleted = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(arg_diff_cluster) >= 2 and len(arg_diff_cluster) > 0:
|
|
|
|
if len(arg_diff_cluster) >= 2 and len(arg_diff_cluster) > 0:
|
|
|
|
|
|
|
|
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted[0:arg_diff_cluster[0] + 1])
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted[0:arg_diff_cluster[0] + 1])
|
|
|
|
for i in range(len(arg_diff_cluster) - 1):
|
|
|
|
for i in range(len(arg_diff_cluster) - 1):
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted[arg_diff_cluster[i]+1:arg_diff_cluster[i+1]+1])
|
|
|
|
clusters_to_be_deleted.append(
|
|
|
|
|
|
|
|
arg_neg_must_be_deleted[arg_diff_cluster[i] + 1:arg_diff_cluster[i + 1] + 1])
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted[arg_diff_cluster[len(arg_diff_cluster) - 1] + 1:])
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted[arg_diff_cluster[len(arg_diff_cluster) - 1] + 1:])
|
|
|
|
elif len(arg_neg_must_be_deleted) >= 2 and len(arg_diff_cluster) == 0:
|
|
|
|
elif len(arg_neg_must_be_deleted) >= 2 and len(arg_diff_cluster) == 0:
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted[:])
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted[:])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(arg_neg_must_be_deleted) == 1:
|
|
|
|
if len(arg_neg_must_be_deleted) == 1:
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted)
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(clusters_to_be_deleted) > 0:
|
|
|
|
if len(clusters_to_be_deleted) > 0:
|
|
|
|
peaks_new_extra = []
|
|
|
|
peaks_new_extra = []
|
|
|
|
for m in range(len(clusters_to_be_deleted)):
|
|
|
|
for m in range(len(clusters_to_be_deleted)):
|
|
|
@ -303,26 +285,25 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
peaks_new_tot.append(i1)
|
|
|
|
peaks_new_tot.append(i1)
|
|
|
|
peaks_new_tot = np.sort(peaks_new_tot)
|
|
|
|
peaks_new_tot = np.sort(peaks_new_tot)
|
|
|
|
|
|
|
|
|
|
|
|
##plt.plot(y_padded_up_to_down_padded)
|
|
|
|
# plt.plot(y_padded_up_to_down_padded)
|
|
|
|
##plt.plot(peaks_neg,y_padded_up_to_down_padded[peaks_neg],'*')
|
|
|
|
# plt.plot(peaks_neg,y_padded_up_to_down_padded[peaks_neg],'*')
|
|
|
|
##plt.show()
|
|
|
|
# plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
##plt.plot(y_padded_up_to_down_padded)
|
|
|
|
# plt.plot(y_padded_up_to_down_padded)
|
|
|
|
##plt.plot(peaks_neg_new,y_padded_up_to_down_padded[peaks_neg_new],'*')
|
|
|
|
# plt.plot(peaks_neg_new,y_padded_up_to_down_padded[peaks_neg_new],'*')
|
|
|
|
##plt.show()
|
|
|
|
# plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
##plt.plot(y_padded_smoothed)
|
|
|
|
# plt.plot(y_padded_smoothed)
|
|
|
|
##plt.plot(peaks,y_padded_smoothed[peaks],'*')
|
|
|
|
# plt.plot(peaks,y_padded_smoothed[peaks],'*')
|
|
|
|
##plt.show()
|
|
|
|
# plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
##plt.plot(y_padded_smoothed)
|
|
|
|
# plt.plot(y_padded_smoothed)
|
|
|
|
##plt.plot(peaks_new_tot,y_padded_smoothed[peaks_new_tot],'*')
|
|
|
|
# plt.plot(peaks_new_tot,y_padded_smoothed[peaks_new_tot],'*')
|
|
|
|
##plt.show()
|
|
|
|
# plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
peaks = peaks_new_tot[:]
|
|
|
|
peaks = peaks_new_tot[:]
|
|
|
|
peaks_neg = peaks_neg_new[:]
|
|
|
|
peaks_neg = peaks_neg_new[:]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
peaks_new_tot = peaks[:]
|
|
|
|
peaks_new_tot = peaks[:]
|
|
|
|
peaks = peaks_new_tot[:]
|
|
|
|
peaks = peaks_new_tot[:]
|
|
|
@ -330,12 +311,10 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mean_value_of_peaks = np.mean(y_padded_smoothed[peaks])
|
|
|
|
mean_value_of_peaks = np.mean(y_padded_smoothed[peaks])
|
|
|
|
std_value_of_peaks = np.std(y_padded_smoothed[peaks])
|
|
|
|
std_value_of_peaks = np.std(y_padded_smoothed[peaks])
|
|
|
|
peaks_values = y_padded_smoothed[peaks]
|
|
|
|
peaks_values = y_padded_smoothed[peaks]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
peaks_neg = peaks_neg - 20 - 20
|
|
|
|
peaks_neg = peaks_neg - 20 - 20
|
|
|
|
peaks = peaks - 20
|
|
|
|
peaks = peaks - 20
|
|
|
|
|
|
|
|
|
|
|
@ -347,8 +326,6 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
if peaks[jj] > len(x) - 1:
|
|
|
|
if peaks[jj] > len(x) - 1:
|
|
|
|
peaks[jj] = len(x) - 1
|
|
|
|
peaks[jj] = len(x) - 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
textline_boxes = []
|
|
|
|
textline_boxes = []
|
|
|
|
textline_boxes_rot = []
|
|
|
|
textline_boxes_rot = []
|
|
|
|
|
|
|
|
|
|
|
@ -360,34 +337,33 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
dis_to_next_down = abs(peaks[jj] - peaks_neg[jj + 1])
|
|
|
|
dis_to_next_down = abs(peaks[jj] - peaks_neg[jj + 1])
|
|
|
|
|
|
|
|
|
|
|
|
if peaks_values[jj] > mean_value_of_peaks - std_value_of_peaks / 2.:
|
|
|
|
if peaks_values[jj] > mean_value_of_peaks - std_value_of_peaks / 2.:
|
|
|
|
point_up = peaks[jj] + first_nonzero - int(1.3 * dis_to_next_up) ##+int(dis_to_next_up*1./4.0)
|
|
|
|
point_up = peaks[jj] + first_nonzero - int(1.3 * dis_to_next_up) # +int(dis_to_next_up*1./4.0)
|
|
|
|
point_down =y_max_cont-1##peaks[jj] + first_nonzero + int(1.3 * dis_to_next_down) #point_up# np.max(y_cont)#peaks[jj] + first_nonzero + int(1.4 * dis_to_next_down) ###-int(dis_to_next_down*1./4.0)
|
|
|
|
point_down = y_max_cont - 1 # peaks[jj] + first_nonzero + int(1.3 * dis_to_next_down) #point_up# np.max(y_cont)#peaks[jj] + first_nonzero + int(1.4 * dis_to_next_down) ###-int(dis_to_next_down*1./4.0)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
point_up = peaks[jj] + first_nonzero - int(1.4 * dis_to_next_up) ##+int(dis_to_next_up*1./4.0)
|
|
|
|
point_up = peaks[jj] + first_nonzero - int(1.4 * dis_to_next_up) # +int(dis_to_next_up*1./4.0)
|
|
|
|
point_down =y_max_cont-1##peaks[jj] + first_nonzero + int(1.6 * dis_to_next_down) #point_up# np.max(y_cont)#peaks[jj] + first_nonzero + int(1.4 * dis_to_next_down) ###-int(dis_to_next_down*1./4.0)
|
|
|
|
point_down = y_max_cont - 1 # peaks[jj] + first_nonzero + int(1.6 * dis_to_next_down) #point_up# np.max(y_cont)#peaks[jj] + first_nonzero + int(1.4 * dis_to_next_down) ###-int(dis_to_next_down*1./4.0)
|
|
|
|
|
|
|
|
|
|
|
|
point_down_narrow = peaks[jj] + first_nonzero + int(
|
|
|
|
point_down_narrow = peaks[jj] + first_nonzero + int(
|
|
|
|
1.4 * dis_to_next_down) ###-int(dis_to_next_down*1./2)
|
|
|
|
1.4 * dis_to_next_down) # -int(dis_to_next_down*1./2)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
dis_to_next_up = abs(peaks[jj] - peaks_neg[jj])
|
|
|
|
dis_to_next_up = abs(peaks[jj] - peaks_neg[jj])
|
|
|
|
dis_to_next_down = abs(peaks[jj] - peaks_neg[jj + 1])
|
|
|
|
dis_to_next_down = abs(peaks[jj] - peaks_neg[jj + 1])
|
|
|
|
|
|
|
|
|
|
|
|
if peaks_values[jj] > mean_value_of_peaks - std_value_of_peaks / 2.:
|
|
|
|
if peaks_values[jj] > mean_value_of_peaks - std_value_of_peaks / 2.:
|
|
|
|
point_up = peaks[jj] + first_nonzero - int(1.1 * dis_to_next_up) ##+int(dis_to_next_up*1./4.0)
|
|
|
|
point_up = peaks[jj] + first_nonzero - int(1.1 * dis_to_next_up) # +int(dis_to_next_up*1./4.0)
|
|
|
|
point_down = peaks[jj] + first_nonzero + int(1.1 * dis_to_next_down) ###-int(dis_to_next_down*1./4.0)
|
|
|
|
point_down = peaks[jj] + first_nonzero + int(
|
|
|
|
|
|
|
|
1.1 * dis_to_next_down) # -int(dis_to_next_down*1./4.0)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
point_up = peaks[jj] + first_nonzero - int(1.23 * dis_to_next_up) ##+int(dis_to_next_up*1./4.0)
|
|
|
|
point_up = peaks[jj] + first_nonzero - int(1.23 * dis_to_next_up) # +int(dis_to_next_up*1./4.0)
|
|
|
|
point_down = peaks[jj] + first_nonzero + int(1.33 * dis_to_next_down) ###-int(dis_to_next_down*1./4.0)
|
|
|
|
point_down = peaks[jj] + first_nonzero + int(
|
|
|
|
|
|
|
|
1.33 * dis_to_next_down) # -int(dis_to_next_down*1./4.0)
|
|
|
|
|
|
|
|
|
|
|
|
point_down_narrow = peaks[jj] + first_nonzero + int(
|
|
|
|
point_down_narrow = peaks[jj] + first_nonzero + int(
|
|
|
|
1.1 * dis_to_next_down) ###-int(dis_to_next_down*1./2)
|
|
|
|
1.1 * dis_to_next_down) # -int(dis_to_next_down*1./2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if point_down_narrow >= img_patch.shape[0]:
|
|
|
|
if point_down_narrow >= img_patch.shape[0]:
|
|
|
|
point_down_narrow = img_patch.shape[0] - 2
|
|
|
|
point_down_narrow = img_patch.shape[0] - 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
distances = [cv2.pointPolygonTest(contour_text_interest_copy, tuple(int(x) for x in np.array([xv[mj], peaks[jj] + first_nonzero])), True)
|
|
|
|
distances = [cv2.pointPolygonTest(contour_text_interest_copy, tuple(int(x) for x in np.array([xv[mj], peaks[jj] + first_nonzero])), True)
|
|
|
|
for mj in range(len(xv))]
|
|
|
|
for mj in range(len(xv))]
|
|
|
|
distances = np.array(distances)
|
|
|
|
distances = np.array(distances)
|
|
|
@ -420,8 +396,6 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
if point_up_rot2 < 0:
|
|
|
|
if point_up_rot2 < 0:
|
|
|
|
point_up_rot2 = 0
|
|
|
|
point_up_rot2 = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
x_min_rot1 = x_min_rot1 - x_help
|
|
|
|
x_min_rot1 = x_min_rot1 - x_help
|
|
|
|
x_max_rot2 = x_max_rot2 - x_help
|
|
|
|
x_max_rot2 = x_max_rot2 - x_help
|
|
|
|
x_max_rot3 = x_max_rot3 - x_help
|
|
|
|
x_max_rot3 = x_max_rot3 - x_help
|
|
|
@ -432,9 +406,6 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
point_down_rot3 = point_down_rot3 - y_help
|
|
|
|
point_down_rot3 = point_down_rot3 - y_help
|
|
|
|
point_down_rot4 = point_down_rot4 - y_help
|
|
|
|
point_down_rot4 = point_down_rot4 - y_help
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
textline_boxes_rot.append(np.array([[int(x_min_rot1), int(point_up_rot1)],
|
|
|
|
textline_boxes_rot.append(np.array([[int(x_min_rot1), int(point_up_rot1)],
|
|
|
|
[int(x_max_rot2), int(point_up_rot2)],
|
|
|
|
[int(x_max_rot2), int(point_up_rot2)],
|
|
|
|
[int(x_max_rot3), int(point_down_rot3)],
|
|
|
|
[int(x_max_rot3), int(point_down_rot3)],
|
|
|
@ -477,7 +448,6 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
x_max_rot3, point_down_rot3 = p3[0] + x_d, p3[1] + y_d
|
|
|
|
x_max_rot3, point_down_rot3 = p3[0] + x_d, p3[1] + y_d
|
|
|
|
x_min_rot4, point_down_rot4 = p4[0] + x_d, p4[1] + y_d
|
|
|
|
x_min_rot4, point_down_rot4 = p4[0] + x_d, p4[1] + y_d
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if x_min_rot1 < 0:
|
|
|
|
if x_min_rot1 < 0:
|
|
|
|
x_min_rot1 = 0
|
|
|
|
x_min_rot1 = 0
|
|
|
|
if x_min_rot4 < 0:
|
|
|
|
if x_min_rot4 < 0:
|
|
|
@ -487,7 +457,6 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
if point_up_rot2 < 0:
|
|
|
|
if point_up_rot2 < 0:
|
|
|
|
point_up_rot2 = 0
|
|
|
|
point_up_rot2 = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
x_min_rot1 = x_min_rot1 - x_help
|
|
|
|
x_min_rot1 = x_min_rot1 - x_help
|
|
|
|
x_max_rot2 = x_max_rot2 - x_help
|
|
|
|
x_max_rot2 = x_max_rot2 - x_help
|
|
|
|
x_max_rot3 = x_max_rot3 - x_help
|
|
|
|
x_max_rot3 = x_max_rot3 - x_help
|
|
|
@ -498,9 +467,6 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
point_down_rot3 = point_down_rot3 - y_help
|
|
|
|
point_down_rot3 = point_down_rot3 - y_help
|
|
|
|
point_down_rot4 = point_down_rot4 - y_help
|
|
|
|
point_down_rot4 = point_down_rot4 - y_help
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
textline_boxes_rot.append(np.array([[int(x_min_rot1), int(point_up_rot1)],
|
|
|
|
textline_boxes_rot.append(np.array([[int(x_min_rot1), int(point_up_rot1)],
|
|
|
|
[int(x_max_rot2), int(point_up_rot2)],
|
|
|
|
[int(x_max_rot2), int(point_up_rot2)],
|
|
|
|
[int(x_max_rot3), int(point_down_rot3)],
|
|
|
|
[int(x_max_rot3), int(point_down_rot3)],
|
|
|
@ -512,7 +478,6 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
[int(x_min), int(y_max)]]))
|
|
|
|
[int(x_min), int(y_max)]]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif len(peaks) == 2:
|
|
|
|
elif len(peaks) == 2:
|
|
|
|
dis_to_next = np.abs(peaks[1] - peaks[0])
|
|
|
|
dis_to_next = np.abs(peaks[1] - peaks[0])
|
|
|
|
for jj in range(len(peaks)):
|
|
|
|
for jj in range(len(peaks)):
|
|
|
@ -553,8 +518,6 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
x_max_rot3, point_down_rot3 = p3[0] + x_d, p3[1] + y_d
|
|
|
|
x_max_rot3, point_down_rot3 = p3[0] + x_d, p3[1] + y_d
|
|
|
|
x_min_rot4, point_down_rot4 = p4[0] + x_d, p4[1] + y_d
|
|
|
|
x_min_rot4, point_down_rot4 = p4[0] + x_d, p4[1] + y_d
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if x_min_rot1 < 0:
|
|
|
|
if x_min_rot1 < 0:
|
|
|
|
x_min_rot1 = 0
|
|
|
|
x_min_rot1 = 0
|
|
|
|
if x_min_rot4 < 0:
|
|
|
|
if x_min_rot4 < 0:
|
|
|
@ -574,9 +537,6 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
point_down_rot3 = point_down_rot3 - y_help
|
|
|
|
point_down_rot3 = point_down_rot3 - y_help
|
|
|
|
point_down_rot4 = point_down_rot4 - y_help
|
|
|
|
point_down_rot4 = point_down_rot4 - y_help
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
textline_boxes_rot.append(np.array([[int(x_min_rot1), int(point_up_rot1)],
|
|
|
|
textline_boxes_rot.append(np.array([[int(x_min_rot1), int(point_up_rot1)],
|
|
|
|
[int(x_max_rot2), int(point_up_rot2)],
|
|
|
|
[int(x_max_rot2), int(point_up_rot2)],
|
|
|
|
[int(x_max_rot3), int(point_down_rot3)],
|
|
|
|
[int(x_max_rot3), int(point_down_rot3)],
|
|
|
@ -644,7 +604,6 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
if point_up_rot2 < 0:
|
|
|
|
if point_up_rot2 < 0:
|
|
|
|
point_up_rot2 = 0
|
|
|
|
point_up_rot2 = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
x_min_rot1 = x_min_rot1 - x_help
|
|
|
|
x_min_rot1 = x_min_rot1 - x_help
|
|
|
|
x_max_rot2 = x_max_rot2 - x_help
|
|
|
|
x_max_rot2 = x_max_rot2 - x_help
|
|
|
|
x_max_rot3 = x_max_rot3 - x_help
|
|
|
|
x_max_rot3 = x_max_rot3 - x_help
|
|
|
@ -655,9 +614,6 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
point_down_rot3 = point_down_rot3 - y_help
|
|
|
|
point_down_rot3 = point_down_rot3 - y_help
|
|
|
|
point_down_rot4 = point_down_rot4 - y_help
|
|
|
|
point_down_rot4 = point_down_rot4 - y_help
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
textline_boxes_rot.append(np.array([[int(x_min_rot1), int(point_up_rot1)],
|
|
|
|
textline_boxes_rot.append(np.array([[int(x_min_rot1), int(point_up_rot1)],
|
|
|
|
[int(x_max_rot2), int(point_up_rot2)],
|
|
|
|
[int(x_max_rot2), int(point_up_rot2)],
|
|
|
|
[int(x_max_rot3), int(point_down_rot3)],
|
|
|
|
[int(x_max_rot3), int(point_down_rot3)],
|
|
|
@ -668,15 +624,14 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
|
|
|
|
[int(x_max), int(point_down)],
|
|
|
|
[int(x_max), int(point_down)],
|
|
|
|
[int(x_min), int(point_down)]]))
|
|
|
|
[int(x_min), int(point_down)]]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return peaks, textline_boxes_rot
|
|
|
|
return peaks, textline_boxes_rot
|
|
|
|
|
|
|
|
|
|
|
|
def separate_lines_vertical(img_patch, contour_text_interest, thetha):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def separate_lines_vertical(img_patch, contour_text_interest, thetha):
|
|
|
|
thetha = thetha + 90
|
|
|
|
thetha = thetha + 90
|
|
|
|
contour_text_interest_copy = contour_text_interest.copy()
|
|
|
|
contour_text_interest_copy = contour_text_interest.copy()
|
|
|
|
x, y, x_d, y_d, xv, x_min_cont, y_min_cont, x_max_cont, y_max_cont, first_nonzero, y_padded_up_to_down_padded, y_padded_smoothed, peaks, peaks_neg, rotation_matrix = dedup_separate_lines(img_patch, contour_text_interest, thetha, 0)
|
|
|
|
x, y, x_d, y_d, xv, x_min_cont, y_min_cont, x_max_cont, y_max_cont, first_nonzero, y_padded_up_to_down_padded, y_padded_smoothed, peaks, peaks_neg, rotation_matrix = dedup_separate_lines(
|
|
|
|
|
|
|
|
img_patch, contour_text_interest, thetha, 0)
|
|
|
|
|
|
|
|
|
|
|
|
# plt.plot(y_padded_up_to_down_padded)
|
|
|
|
# plt.plot(y_padded_up_to_down_padded)
|
|
|
|
# plt.plot(peaks_neg,y_padded_up_to_down_padded[peaks_neg],'*')
|
|
|
|
# plt.plot(peaks_neg,y_padded_up_to_down_padded[peaks_neg],'*')
|
|
|
@ -766,25 +721,25 @@ def separate_lines_vertical(img_patch, contour_text_interest, thetha):
|
|
|
|
dis_to_next_down = abs(peaks[jj] - peaks_neg[jj + 1])
|
|
|
|
dis_to_next_down = abs(peaks[jj] - peaks_neg[jj + 1])
|
|
|
|
|
|
|
|
|
|
|
|
if peaks_values[jj] > mean_value_of_peaks - std_value_of_peaks / 2.0:
|
|
|
|
if peaks_values[jj] > mean_value_of_peaks - std_value_of_peaks / 2.0:
|
|
|
|
point_up = peaks[jj] + first_nonzero - int(1.3 * dis_to_next_up) ##+int(dis_to_next_up*1./4.0)
|
|
|
|
point_up = peaks[jj] + first_nonzero - int(1.3 * dis_to_next_up) # +int(dis_to_next_up*1./4.0)
|
|
|
|
point_down = x_max_cont - 1 ##peaks[jj] + first_nonzero + int(1.3 * dis_to_next_down) #point_up# np.max(y_cont)#peaks[jj] + first_nonzero + int(1.4 * dis_to_next_down) ###-int(dis_to_next_down*1./4.0)
|
|
|
|
point_down = x_max_cont - 1 # peaks[jj] + first_nonzero + int(1.3 * dis_to_next_down) #point_up# np.max(y_cont)#peaks[jj] + first_nonzero + int(1.4 * dis_to_next_down) ###-int(dis_to_next_down*1./4.0)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
point_up = peaks[jj] + first_nonzero - int(1.4 * dis_to_next_up) ##+int(dis_to_next_up*1./4.0)
|
|
|
|
point_up = peaks[jj] + first_nonzero - int(1.4 * dis_to_next_up) # +int(dis_to_next_up*1./4.0)
|
|
|
|
point_down = x_max_cont - 1 ##peaks[jj] + first_nonzero + int(1.6 * dis_to_next_down) #point_up# np.max(y_cont)#peaks[jj] + first_nonzero + int(1.4 * dis_to_next_down) ###-int(dis_to_next_down*1./4.0)
|
|
|
|
point_down = x_max_cont - 1 # peaks[jj] + first_nonzero + int(1.6 * dis_to_next_down) #point_up# np.max(y_cont)#peaks[jj] + first_nonzero + int(1.4 * dis_to_next_down) ###-int(dis_to_next_down*1./4.0)
|
|
|
|
|
|
|
|
|
|
|
|
point_down_narrow = peaks[jj] + first_nonzero + int(1.4 * dis_to_next_down) ###-int(dis_to_next_down*1./2)
|
|
|
|
point_down_narrow = peaks[jj] + first_nonzero + int(1.4 * dis_to_next_down) # -int(dis_to_next_down*1./2)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
dis_to_next_up = abs(peaks[jj] - peaks_neg[jj])
|
|
|
|
dis_to_next_up = abs(peaks[jj] - peaks_neg[jj])
|
|
|
|
dis_to_next_down = abs(peaks[jj] - peaks_neg[jj + 1])
|
|
|
|
dis_to_next_down = abs(peaks[jj] - peaks_neg[jj + 1])
|
|
|
|
|
|
|
|
|
|
|
|
if peaks_values[jj] > mean_value_of_peaks - std_value_of_peaks / 2.0:
|
|
|
|
if peaks_values[jj] > mean_value_of_peaks - std_value_of_peaks / 2.0:
|
|
|
|
point_up = peaks[jj] + first_nonzero - int(1.1 * dis_to_next_up) ##+int(dis_to_next_up*1./4.0)
|
|
|
|
point_up = peaks[jj] + first_nonzero - int(1.1 * dis_to_next_up) # +int(dis_to_next_up*1./4.0)
|
|
|
|
point_down = peaks[jj] + first_nonzero + int(1.1 * dis_to_next_down) ###-int(dis_to_next_down*1./4.0)
|
|
|
|
point_down = peaks[jj] + first_nonzero + int(1.1 * dis_to_next_down) # -int(dis_to_next_down*1./4.0)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
point_up = peaks[jj] + first_nonzero - int(1.23 * dis_to_next_up) ##+int(dis_to_next_up*1./4.0)
|
|
|
|
point_up = peaks[jj] + first_nonzero - int(1.23 * dis_to_next_up) # +int(dis_to_next_up*1./4.0)
|
|
|
|
point_down = peaks[jj] + first_nonzero + int(1.33 * dis_to_next_down) ###-int(dis_to_next_down*1./4.0)
|
|
|
|
point_down = peaks[jj] + first_nonzero + int(1.33 * dis_to_next_down) # -int(dis_to_next_down*1./4.0)
|
|
|
|
|
|
|
|
|
|
|
|
point_down_narrow = peaks[jj] + first_nonzero + int(1.1 * dis_to_next_down) ###-int(dis_to_next_down*1./2)
|
|
|
|
point_down_narrow = peaks[jj] + first_nonzero + int(1.1 * dis_to_next_down) # -int(dis_to_next_down*1./2)
|
|
|
|
|
|
|
|
|
|
|
|
if point_down_narrow >= img_patch.shape[0]:
|
|
|
|
if point_down_narrow >= img_patch.shape[0]:
|
|
|
|
point_down_narrow = img_patch.shape[0] - 2
|
|
|
|
point_down_narrow = img_patch.shape[0] - 2
|
|
|
@ -820,9 +775,13 @@ def separate_lines_vertical(img_patch, contour_text_interest, thetha):
|
|
|
|
if point_up_rot2 < 0:
|
|
|
|
if point_up_rot2 < 0:
|
|
|
|
point_up_rot2 = 0
|
|
|
|
point_up_rot2 = 0
|
|
|
|
|
|
|
|
|
|
|
|
textline_boxes_rot.append(np.array([[int(x_min_rot1), int(point_up_rot1)], [int(x_max_rot2), int(point_up_rot2)], [int(x_max_rot3), int(point_down_rot3)], [int(x_min_rot4), int(point_down_rot4)]]))
|
|
|
|
textline_boxes_rot.append(np.array(
|
|
|
|
|
|
|
|
[[int(x_min_rot1), int(point_up_rot1)], [int(x_max_rot2), int(point_up_rot2)],
|
|
|
|
|
|
|
|
[int(x_max_rot3), int(point_down_rot3)], [int(x_min_rot4), int(point_down_rot4)]]))
|
|
|
|
|
|
|
|
|
|
|
|
textline_boxes.append(np.array([[int(x_min), int(point_up)], [int(x_max), int(point_up)], [int(x_max), int(point_down)], [int(x_min), int(point_down)]]))
|
|
|
|
textline_boxes.append(np.array(
|
|
|
|
|
|
|
|
[[int(x_min), int(point_up)], [int(x_max), int(point_up)], [int(x_max), int(point_down)],
|
|
|
|
|
|
|
|
[int(x_min), int(point_down)]]))
|
|
|
|
|
|
|
|
|
|
|
|
elif len(peaks) < 1:
|
|
|
|
elif len(peaks) < 1:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
@ -853,9 +812,12 @@ def separate_lines_vertical(img_patch, contour_text_interest, thetha):
|
|
|
|
if point_up_rot2 < 0:
|
|
|
|
if point_up_rot2 < 0:
|
|
|
|
point_up_rot2 = 0
|
|
|
|
point_up_rot2 = 0
|
|
|
|
|
|
|
|
|
|
|
|
textline_boxes_rot.append(np.array([[int(x_min_rot1), int(point_up_rot1)], [int(x_max_rot2), int(point_up_rot2)], [int(x_max_rot3), int(point_down_rot3)], [int(x_min_rot4), int(point_down_rot4)]]))
|
|
|
|
textline_boxes_rot.append(np.array(
|
|
|
|
|
|
|
|
[[int(x_min_rot1), int(point_up_rot1)], [int(x_max_rot2), int(point_up_rot2)],
|
|
|
|
|
|
|
|
[int(x_max_rot3), int(point_down_rot3)], [int(x_min_rot4), int(point_down_rot4)]]))
|
|
|
|
|
|
|
|
|
|
|
|
textline_boxes.append(np.array([[int(x_min), int(y_min)], [int(x_max), int(y_min)], [int(x_max), int(y_max)], [int(x_min), int(y_max)]]))
|
|
|
|
textline_boxes.append(np.array(
|
|
|
|
|
|
|
|
[[int(x_min), int(y_min)], [int(x_max), int(y_min)], [int(x_max), int(y_max)], [int(x_min), int(y_max)]]))
|
|
|
|
|
|
|
|
|
|
|
|
elif len(peaks) == 2:
|
|
|
|
elif len(peaks) == 2:
|
|
|
|
dis_to_next = np.abs(peaks[1] - peaks[0])
|
|
|
|
dis_to_next = np.abs(peaks[1] - peaks[0])
|
|
|
@ -902,9 +864,13 @@ def separate_lines_vertical(img_patch, contour_text_interest, thetha):
|
|
|
|
if point_up_rot2 < 0:
|
|
|
|
if point_up_rot2 < 0:
|
|
|
|
point_up_rot2 = 0
|
|
|
|
point_up_rot2 = 0
|
|
|
|
|
|
|
|
|
|
|
|
textline_boxes_rot.append(np.array([[int(x_min_rot1), int(point_up_rot1)], [int(x_max_rot2), int(point_up_rot2)], [int(x_max_rot3), int(point_down_rot3)], [int(x_min_rot4), int(point_down_rot4)]]))
|
|
|
|
textline_boxes_rot.append(np.array(
|
|
|
|
|
|
|
|
[[int(x_min_rot1), int(point_up_rot1)], [int(x_max_rot2), int(point_up_rot2)],
|
|
|
|
|
|
|
|
[int(x_max_rot3), int(point_down_rot3)], [int(x_min_rot4), int(point_down_rot4)]]))
|
|
|
|
|
|
|
|
|
|
|
|
textline_boxes.append(np.array([[int(x_min), int(point_up)], [int(x_max), int(point_up)], [int(x_max), int(point_down)], [int(x_min), int(point_down)]]))
|
|
|
|
textline_boxes.append(np.array(
|
|
|
|
|
|
|
|
[[int(x_min), int(point_up)], [int(x_max), int(point_up)], [int(x_max), int(point_down)],
|
|
|
|
|
|
|
|
[int(x_min), int(point_down)]]))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
for jj in range(len(peaks)):
|
|
|
|
for jj in range(len(peaks)):
|
|
|
|
|
|
|
|
|
|
|
@ -962,14 +928,18 @@ def separate_lines_vertical(img_patch, contour_text_interest, thetha):
|
|
|
|
if point_up_rot2 < 0:
|
|
|
|
if point_up_rot2 < 0:
|
|
|
|
point_up_rot2 = 0
|
|
|
|
point_up_rot2 = 0
|
|
|
|
|
|
|
|
|
|
|
|
textline_boxes_rot.append(np.array([[int(x_min_rot1), int(point_up_rot1)], [int(x_max_rot2), int(point_up_rot2)], [int(x_max_rot3), int(point_down_rot3)], [int(x_min_rot4), int(point_down_rot4)]]))
|
|
|
|
textline_boxes_rot.append(np.array(
|
|
|
|
|
|
|
|
[[int(x_min_rot1), int(point_up_rot1)], [int(x_max_rot2), int(point_up_rot2)],
|
|
|
|
|
|
|
|
[int(x_max_rot3), int(point_down_rot3)], [int(x_min_rot4), int(point_down_rot4)]]))
|
|
|
|
|
|
|
|
|
|
|
|
textline_boxes.append(np.array([[int(x_min), int(point_up)], [int(x_max), int(point_up)], [int(x_max), int(point_down)], [int(x_min), int(point_down)]]))
|
|
|
|
textline_boxes.append(np.array(
|
|
|
|
|
|
|
|
[[int(x_min), int(point_up)], [int(x_max), int(point_up)], [int(x_max), int(point_down)],
|
|
|
|
|
|
|
|
[int(x_min), int(point_down)]]))
|
|
|
|
|
|
|
|
|
|
|
|
return peaks, textline_boxes_rot
|
|
|
|
return peaks, textline_boxes_rot
|
|
|
|
|
|
|
|
|
|
|
|
def separate_lines_new_inside_tiles2(img_patch, thetha):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def separate_lines_new_inside_tiles2(img_patch, thetha):
|
|
|
|
(h, w) = img_patch.shape[:2]
|
|
|
|
(h, w) = img_patch.shape[:2]
|
|
|
|
center = (w // 2, h // 2)
|
|
|
|
center = (w // 2, h // 2)
|
|
|
|
M = cv2.getRotationMatrix2D(center, -thetha, 1.0)
|
|
|
|
M = cv2.getRotationMatrix2D(center, -thetha, 1.0)
|
|
|
@ -1094,7 +1064,8 @@ def separate_lines_new_inside_tiles2(img_patch, thetha):
|
|
|
|
|
|
|
|
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted[0: arg_diff_cluster[0] + 1])
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted[0: arg_diff_cluster[0] + 1])
|
|
|
|
for i in range(len(arg_diff_cluster) - 1):
|
|
|
|
for i in range(len(arg_diff_cluster) - 1):
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted[arg_diff_cluster[i] + 1 : arg_diff_cluster[i + 1] + 1])
|
|
|
|
clusters_to_be_deleted.append(
|
|
|
|
|
|
|
|
arg_neg_must_be_deleted[arg_diff_cluster[i] + 1: arg_diff_cluster[i + 1] + 1])
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted[arg_diff_cluster[len(arg_diff_cluster) - 1] + 1:])
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted[arg_diff_cluster[len(arg_diff_cluster) - 1] + 1:])
|
|
|
|
elif len(arg_neg_must_be_deleted) >= 2 and len(arg_diff_cluster) == 0:
|
|
|
|
elif len(arg_neg_must_be_deleted) >= 2 and len(arg_diff_cluster) == 0:
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted[:])
|
|
|
|
clusters_to_be_deleted.append(arg_neg_must_be_deleted[:])
|
|
|
@ -1150,8 +1121,8 @@ def separate_lines_new_inside_tiles2(img_patch, thetha):
|
|
|
|
std_value_of_peaks = np.std(y_padded_smoothed[peaks])
|
|
|
|
std_value_of_peaks = np.std(y_padded_smoothed[peaks])
|
|
|
|
peaks_values = y_padded_smoothed[peaks]
|
|
|
|
peaks_values = y_padded_smoothed[peaks]
|
|
|
|
|
|
|
|
|
|
|
|
###peaks_neg = peaks_neg - 20 - 20
|
|
|
|
# peaks_neg = peaks_neg - 20 - 20
|
|
|
|
###peaks = peaks - 20
|
|
|
|
# peaks = peaks - 20
|
|
|
|
peaks_neg_true = peaks_neg[:]
|
|
|
|
peaks_neg_true = peaks_neg[:]
|
|
|
|
peaks_pos_true = peaks[:]
|
|
|
|
peaks_pos_true = peaks[:]
|
|
|
|
|
|
|
|
|
|
|
@ -1172,17 +1143,18 @@ def separate_lines_new_inside_tiles2(img_patch, thetha):
|
|
|
|
peaks_pos_true = peaks_pos_true - 20
|
|
|
|
peaks_pos_true = peaks_pos_true - 20
|
|
|
|
|
|
|
|
|
|
|
|
for i in range(len(peaks_pos_true)):
|
|
|
|
for i in range(len(peaks_pos_true)):
|
|
|
|
##img_patch[peaks_pos_true[i]-8:peaks_pos_true[i]+8,:]=1
|
|
|
|
# img_patch[peaks_pos_true[i]-8:peaks_pos_true[i]+8,:]=1
|
|
|
|
img_patch[peaks_pos_true[i] - 6: peaks_pos_true[i] + 6, :] = 1
|
|
|
|
img_patch[peaks_pos_true[i] - 6: peaks_pos_true[i] + 6, :] = 1
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
kernel = np.ones((5, 5), np.uint8)
|
|
|
|
kernel = np.ones((5, 5), np.uint8)
|
|
|
|
|
|
|
|
|
|
|
|
# img_patch = cv2.erode(img_patch,kernel,iterations = 3)
|
|
|
|
# img_patch = cv2.erode(img_patch,kernel,iterations = 3)
|
|
|
|
#######################img_patch = cv2.erode(img_patch,kernel,iterations = 2)
|
|
|
|
# img_patch = cv2.erode(img_patch,kernel,iterations = 2)
|
|
|
|
img_patch = cv2.erode(img_patch, kernel, iterations=1)
|
|
|
|
img_patch = cv2.erode(img_patch, kernel, iterations=1)
|
|
|
|
return img_patch
|
|
|
|
return img_patch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def separate_lines_new_inside_tiles(img_path, thetha):
|
|
|
|
def separate_lines_new_inside_tiles(img_path, thetha):
|
|
|
|
(h, w) = img_path.shape[:2]
|
|
|
|
(h, w) = img_path.shape[:2]
|
|
|
|
center = (w // 2, h // 2)
|
|
|
|
center = (w // 2, h // 2)
|
|
|
@ -1202,8 +1174,8 @@ def separate_lines_new_inside_tiles(img_path, thetha):
|
|
|
|
|
|
|
|
|
|
|
|
mada_n = img_path.sum(axis=1)
|
|
|
|
mada_n = img_path.sum(axis=1)
|
|
|
|
|
|
|
|
|
|
|
|
##plt.plot(mada_n)
|
|
|
|
# plt.plot(mada_n)
|
|
|
|
##plt.show()
|
|
|
|
# plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
first_nonzero = 0 # (next((i for i, x in enumerate(mada_n) if x), None))
|
|
|
|
first_nonzero = 0 # (next((i for i, x in enumerate(mada_n) if x), None))
|
|
|
|
|
|
|
|
|
|
|
@ -1326,6 +1298,7 @@ def separate_lines_new_inside_tiles(img_path, thetha):
|
|
|
|
img_path = cv2.erode(img_path, kernel, iterations=2)
|
|
|
|
img_path = cv2.erode(img_path, kernel, iterations=2)
|
|
|
|
return img_path
|
|
|
|
return img_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def separate_lines_vertical_cont(img_patch, contour_text_interest, thetha, box_ind, add_boxes_coor_into_textlines):
|
|
|
|
def separate_lines_vertical_cont(img_patch, contour_text_interest, thetha, box_ind, add_boxes_coor_into_textlines):
|
|
|
|
kernel = np.ones((5, 5), np.uint8)
|
|
|
|
kernel = np.ones((5, 5), np.uint8)
|
|
|
|
pixel = 255
|
|
|
|
pixel = 255
|
|
|
@ -1346,7 +1319,7 @@ def separate_lines_vertical_cont(img_patch, contour_text_interest, thetha, box_i
|
|
|
|
contours_imgs = filter_contours_area_of_image_tables(thresh, contours_imgs, hierarchy, max_area=max_area, min_area=min_area)
|
|
|
|
contours_imgs = filter_contours_area_of_image_tables(thresh, contours_imgs, hierarchy, max_area=max_area, min_area=min_area)
|
|
|
|
|
|
|
|
|
|
|
|
cont_final = []
|
|
|
|
cont_final = []
|
|
|
|
###print(add_boxes_coor_into_textlines,'ikki')
|
|
|
|
# print(add_boxes_coor_into_textlines,'ikki')
|
|
|
|
for i in range(len(contours_imgs)):
|
|
|
|
for i in range(len(contours_imgs)):
|
|
|
|
img_contour = np.zeros((cnts_images.shape[0], cnts_images.shape[1], 3))
|
|
|
|
img_contour = np.zeros((cnts_images.shape[0], cnts_images.shape[1], 3))
|
|
|
|
img_contour = cv2.fillPoly(img_contour, pts=[contours_imgs[i]], color=(255, 255, 255))
|
|
|
|
img_contour = cv2.fillPoly(img_contour, pts=[contours_imgs[i]], color=(255, 255, 255))
|
|
|
@ -1358,21 +1331,20 @@ def separate_lines_vertical_cont(img_patch, contour_text_interest, thetha, box_i
|
|
|
|
_, threshrot = cv2.threshold(imgrayrot, 0, 255, 0)
|
|
|
|
_, threshrot = cv2.threshold(imgrayrot, 0, 255, 0)
|
|
|
|
contours_text_rot, _ = cv2.findContours(threshrot.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
|
|
|
|
contours_text_rot, _ = cv2.findContours(threshrot.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
|
|
|
|
|
|
|
|
|
|
|
|
##contour_text_copy[:, 0, 0] = contour_text_copy[:, 0, 0] - box_ind[
|
|
|
|
# contour_text_copy[:, 0, 0] = contour_text_copy[:, 0, 0] - box_ind[
|
|
|
|
##0]
|
|
|
|
# 0]
|
|
|
|
##contour_text_copy[:, 0, 1] = contour_text_copy[:, 0, 1] - box_ind[1]
|
|
|
|
# contour_text_copy[:, 0, 1] = contour_text_copy[:, 0, 1] - box_ind[1]
|
|
|
|
##if add_boxes_coor_into_textlines:
|
|
|
|
# if add_boxes_coor_into_textlines:
|
|
|
|
##print(np.shape(contours_text_rot[0]),'sjppo')
|
|
|
|
# print(np.shape(contours_text_rot[0]),'sjppo')
|
|
|
|
##contours_text_rot[0][:, 0, 0]=contours_text_rot[0][:, 0, 0] + box_ind[0]
|
|
|
|
# contours_text_rot[0][:, 0, 0]=contours_text_rot[0][:, 0, 0] + box_ind[0]
|
|
|
|
##contours_text_rot[0][:, 0, 1]=contours_text_rot[0][:, 0, 1] + box_ind[1]
|
|
|
|
# contours_text_rot[0][:, 0, 1]=contours_text_rot[0][:, 0, 1] + box_ind[1]
|
|
|
|
cont_final.append(contours_text_rot[0])
|
|
|
|
cont_final.append(contours_text_rot[0])
|
|
|
|
|
|
|
|
|
|
|
|
##print(cont_final,'nadizzzz')
|
|
|
|
# print(cont_final,'nadizzzz')
|
|
|
|
return None, cont_final
|
|
|
|
return None, cont_final
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def textline_contours_postprocessing(textline_mask, slope, contour_text_interest, box_ind, add_boxes_coor_into_textlines=False):
|
|
|
|
def textline_contours_postprocessing(textline_mask, slope, contour_text_interest, box_ind, add_boxes_coor_into_textlines=False):
|
|
|
|
|
|
|
|
|
|
|
|
textline_mask = np.repeat(textline_mask[:, :, np.newaxis], 3, axis=2) * 255
|
|
|
|
textline_mask = np.repeat(textline_mask[:, :, np.newaxis], 3, axis=2) * 255
|
|
|
|
textline_mask = textline_mask.astype(np.uint8)
|
|
|
|
textline_mask = textline_mask.astype(np.uint8)
|
|
|
|
kernel = np.ones((5, 5), np.uint8)
|
|
|
|
kernel = np.ones((5, 5), np.uint8)
|
|
|
@ -1461,8 +1433,8 @@ def textline_contours_postprocessing(textline_mask, slope, contour_text_interest
|
|
|
|
|
|
|
|
|
|
|
|
return contours_rotated_clean
|
|
|
|
return contours_rotated_clean
|
|
|
|
|
|
|
|
|
|
|
|
def separate_lines_new2(img_path, thetha, num_col, slope_region, plotter=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def separate_lines_new2(img_path, thetha, num_col, slope_region, plotter=None):
|
|
|
|
if num_col == 1:
|
|
|
|
if num_col == 1:
|
|
|
|
num_patches = int(img_path.shape[1] / 200.0)
|
|
|
|
num_patches = int(img_path.shape[1] / 200.0)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -1547,9 +1519,10 @@ def separate_lines_new2(img_path, thetha, num_col, slope_region, plotter=None):
|
|
|
|
img_int = np.zeros((img_xline.shape[0], img_xline.shape[1]))
|
|
|
|
img_int = np.zeros((img_xline.shape[0], img_xline.shape[1]))
|
|
|
|
img_int[:, :] = img_xline[:, :] # img_patch_org[:,:,0]
|
|
|
|
img_int[:, :] = img_xline[:, :] # img_patch_org[:,:,0]
|
|
|
|
|
|
|
|
|
|
|
|
img_resized = np.zeros((int(img_int.shape[0] * (1.2)), int(img_int.shape[1] * (3))))
|
|
|
|
img_resized = np.zeros((int(img_int.shape[0] * 1.2), int(img_int.shape[1] * 3)))
|
|
|
|
|
|
|
|
|
|
|
|
img_resized[int(img_int.shape[0] * (0.1)) : int(img_int.shape[0] * (0.1)) + img_int.shape[0], int(img_int.shape[1] * (1)) : int(img_int.shape[1] * (1)) + img_int.shape[1]] = img_int[:, :]
|
|
|
|
img_resized[int(img_int.shape[0] * 0.1): int(img_int.shape[0] * 0.1) + img_int.shape[0],
|
|
|
|
|
|
|
|
int(img_int.shape[1] * 1): int(img_int.shape[1] * 1) + img_int.shape[1]] = img_int[:, :]
|
|
|
|
# plt.imshow(img_xline)
|
|
|
|
# plt.imshow(img_xline)
|
|
|
|
# plt.show()
|
|
|
|
# plt.show()
|
|
|
|
img_line_rotated = rotate_image(img_resized, slopes_tile_wise[i])
|
|
|
|
img_line_rotated = rotate_image(img_resized, slopes_tile_wise[i])
|
|
|
@ -1560,7 +1533,9 @@ def separate_lines_new2(img_path, thetha, num_col, slope_region, plotter=None):
|
|
|
|
img_patch_separated_returned = rotate_image(img_patch_separated, -slopes_tile_wise[i])
|
|
|
|
img_patch_separated_returned = rotate_image(img_patch_separated, -slopes_tile_wise[i])
|
|
|
|
img_patch_separated_returned[:, :][img_patch_separated_returned[:, :] != 0] = 1
|
|
|
|
img_patch_separated_returned[:, :][img_patch_separated_returned[:, :] != 0] = 1
|
|
|
|
|
|
|
|
|
|
|
|
img_patch_separated_returned_true_size = img_patch_separated_returned[int(img_int.shape[0] * (0.1)) : int(img_int.shape[0] * (0.1)) + img_int.shape[0], int(img_int.shape[1] * (1)) : int(img_int.shape[1] * (1)) + img_int.shape[1]]
|
|
|
|
img_patch_separated_returned_true_size = img_patch_separated_returned[
|
|
|
|
|
|
|
|
int(img_int.shape[0] * 0.1): int(img_int.shape[0] * 0.1) + img_int.shape[0],
|
|
|
|
|
|
|
|
int(img_int.shape[1] * 1): int(img_int.shape[1] * 1) + img_int.shape[1]]
|
|
|
|
|
|
|
|
|
|
|
|
img_patch_separated_returned_true_size = img_patch_separated_returned_true_size[:, margin: length_x - margin]
|
|
|
|
img_patch_separated_returned_true_size = img_patch_separated_returned_true_size[:, margin: length_x - margin]
|
|
|
|
img_patch_ineterst_revised[:, index_x_d + margin: index_x_u - margin] = img_patch_separated_returned_true_size
|
|
|
|
img_patch_ineterst_revised[:, index_x_d + margin: index_x_u - margin] = img_patch_separated_returned_true_size
|
|
|
@ -1569,28 +1544,22 @@ def separate_lines_new2(img_path, thetha, num_col, slope_region, plotter=None):
|
|
|
|
# plt.show()
|
|
|
|
# plt.show()
|
|
|
|
return img_patch_ineterst_revised
|
|
|
|
return img_patch_ineterst_revised
|
|
|
|
|
|
|
|
|
|
|
|
def return_deskew_slop(img_patch_org, sigma_des, main_page=False, plotter=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def return_deskew_slop(img_patch_org, sigma_des, main_page=False, plotter=None):
|
|
|
|
if main_page and plotter:
|
|
|
|
if main_page and plotter:
|
|
|
|
plotter.save_plot_of_textline_density(img_patch_org)
|
|
|
|
plotter.save_plot_of_textline_density(img_patch_org)
|
|
|
|
|
|
|
|
|
|
|
|
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]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
max_shape = np.max(img_int.shape)
|
|
|
|
max_shape = np.max(img_int.shape)
|
|
|
|
img_resized=np.zeros((int( max_shape*(1.1) ) , int( max_shape*(1.1) ) ))
|
|
|
|
img_resized = np.zeros((int(max_shape * 1.1), int(max_shape * 1.1)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onset_x = int((img_resized.shape[1] - img_int.shape[1]) / 2.)
|
|
|
|
onset_x = int((img_resized.shape[1] - img_int.shape[1]) / 2.)
|
|
|
|
onset_y = int((img_resized.shape[0] - img_int.shape[0]) / 2.)
|
|
|
|
onset_y = int((img_resized.shape[0] - img_int.shape[0]) / 2.)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# img_resized = np.zeros((int( img_int.shape[0]*(1.8) ) , int( img_int.shape[1]*(2.6) ) ))
|
|
|
|
# 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]*(.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[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[:, :]
|
|
|
|
img_resized[onset_y:onset_y + img_int.shape[0], onset_x:onset_x + img_int.shape[1]] = img_int[:, :]
|
|
|
|
|
|
|
|
|
|
|
@ -1615,24 +1584,24 @@ def return_deskew_slop(img_patch_org, sigma_des, main_page=False, plotter=None):
|
|
|
|
# print(var_spectrum,'var_spectrum')
|
|
|
|
# print(var_spectrum,'var_spectrum')
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3)
|
|
|
|
var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3)
|
|
|
|
##print(rot,var_spectrum,'var_spectrum')
|
|
|
|
# print(rot,var_spectrum,'var_spectrum')
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
var_spectrum = 0
|
|
|
|
var_spectrum = 0
|
|
|
|
var_res.append(var_spectrum)
|
|
|
|
var_res.append(var_spectrum)
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
var_res = []
|
|
|
|
var_res = []
|
|
|
|
for rot in angels:
|
|
|
|
for rot in angels:
|
|
|
|
img_rot = rotate_image(img_resized, rot)
|
|
|
|
img_rot = 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
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3)
|
|
|
|
var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3)
|
|
|
@ -1651,7 +1620,6 @@ def return_deskew_slop(img_patch_org, sigma_des, main_page=False, plotter=None):
|
|
|
|
# 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])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var_res = []
|
|
|
|
var_res = []
|
|
|
|
|
|
|
|
|
|
|
|
for rot in angels:
|
|
|
|
for rot in angels:
|
|
|
@ -1669,7 +1637,6 @@ def return_deskew_slop(img_patch_org, sigma_des, main_page=False, plotter=None):
|
|
|
|
|
|
|
|
|
|
|
|
var_res.append(var_spectrum)
|
|
|
|
var_res.append(var_spectrum)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if plotter:
|
|
|
|
if plotter:
|
|
|
|
plotter.save_plot_of_rotation_angle(angels, var_res)
|
|
|
|
plotter.save_plot_of_rotation_angle(angels, var_res)
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -1684,8 +1651,8 @@ def return_deskew_slop(img_patch_org, sigma_des, main_page=False, plotter=None):
|
|
|
|
var_res = []
|
|
|
|
var_res = []
|
|
|
|
for rot in angels:
|
|
|
|
for rot in angels:
|
|
|
|
img_rot = rotate_image(img_resized, rot)
|
|
|
|
img_rot = 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
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3)
|
|
|
|
var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3)
|
|
|
@ -1704,8 +1671,8 @@ def return_deskew_slop(img_patch_org, sigma_des, main_page=False, plotter=None):
|
|
|
|
var_res = []
|
|
|
|
var_res = []
|
|
|
|
for rot in angels:
|
|
|
|
for rot in angels:
|
|
|
|
img_rot = rotate_image(img_resized, rot)
|
|
|
|
img_rot = 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
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3)
|
|
|
|
var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3)
|
|
|
@ -1742,8 +1709,8 @@ def return_deskew_slop(img_patch_org, sigma_des, main_page=False, plotter=None):
|
|
|
|
|
|
|
|
|
|
|
|
# plt.plot(var_res)
|
|
|
|
# plt.plot(var_res)
|
|
|
|
# plt.show()
|
|
|
|
# plt.show()
|
|
|
|
##plt.plot(mom3_res)
|
|
|
|
# plt.plot(mom3_res)
|
|
|
|
##plt.show()
|
|
|
|
# plt.show()
|
|
|
|
# print(ang_int,'ang_int111')
|
|
|
|
# print(ang_int,'ang_int111')
|
|
|
|
|
|
|
|
|
|
|
|
early_slope_edge = 22
|
|
|
|
early_slope_edge = 22
|
|
|
@ -1755,8 +1722,8 @@ def return_deskew_slop(img_patch_org, sigma_des, main_page=False, plotter=None):
|
|
|
|
|
|
|
|
|
|
|
|
for rot in angels:
|
|
|
|
for rot in angels:
|
|
|
|
img_rot = rotate_image(img_resized, rot)
|
|
|
|
img_rot = 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
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3)
|
|
|
|
var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3)
|
|
|
@ -1779,8 +1746,8 @@ def return_deskew_slop(img_patch_org, sigma_des, main_page=False, plotter=None):
|
|
|
|
indexer = 0
|
|
|
|
indexer = 0
|
|
|
|
for rot in angels:
|
|
|
|
for rot in angels:
|
|
|
|
img_rot = rotate_image(img_resized, rot)
|
|
|
|
img_rot = 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
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3)
|
|
|
|
var_spectrum = find_num_col_deskew(img_rot, sigma_des, 20.3)
|
|
|
@ -1796,4 +1763,3 @@ def return_deskew_slop(img_patch_org, sigma_des, main_page=False, plotter=None):
|
|
|
|
ang_int = 0
|
|
|
|
ang_int = 0
|
|
|
|
|
|
|
|
|
|
|
|
return ang_int
|
|
|
|
return ang_int
|
|
|
|
|
|
|
|
|
|
|
|