#43 empty textlines caused by newer python-opencv, is resolved

pull/44/head
vahid 4 years ago
parent d1330ffb80
commit 059905c9e4

@ -387,7 +387,8 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
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, (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)
@ -448,8 +449,7 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
pass pass
elif len(peaks) == 1: elif len(peaks) == 1:
distances = [cv2.pointPolygonTest(contour_text_interest_copy, tuple(int(x) for x in np.array([xv[mj], peaks[0] + first_nonzero])), True)
distances = [cv2.pointPolygonTest(contour_text_interest_copy, (xv[mj], peaks[0] + first_nonzero), True)
for mj in range(len(xv))] for mj in range(len(xv))]
distances = np.array(distances) distances = np.array(distances)
@ -530,7 +530,7 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
except: except:
point_up =peaks[jj] + first_nonzero - int(1. / 1.8 * dis_to_next) point_up =peaks[jj] + first_nonzero - int(1. / 1.8 * dis_to_next)
distances = [cv2.pointPolygonTest(contour_text_interest_copy, (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)
@ -612,7 +612,7 @@ def separate_lines(img_patch, contour_text_interest, thetha, x_help, y_help):
point_up = peaks[jj] + first_nonzero - int(1. / 1.9 * dis_to_next_up) point_up = peaks[jj] + first_nonzero - int(1. / 1.9 * dis_to_next_up)
point_down = peaks[jj] + first_nonzero + int(1. / 1.9 * dis_to_next_down) point_down = peaks[jj] + first_nonzero + int(1. / 1.9 * dis_to_next_down)
distances = [cv2.pointPolygonTest(contour_text_interest_copy, (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)
@ -789,7 +789,7 @@ def separate_lines_vertical(img_patch, contour_text_interest, thetha):
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, (xv[mj], peaks[jj] + first_nonzero), True) for mj in range(len(xv))] 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))]
distances = np.array(distances) distances = np.array(distances)
xvinside = xv[distances >= 0] xvinside = xv[distances >= 0]
@ -871,7 +871,7 @@ def separate_lines_vertical(img_patch, contour_text_interest, thetha):
point_down = img_patch.shape[0] - 2 point_down = img_patch.shape[0] - 2
point_up = peaks[jj] + first_nonzero - int(1.0 / 1.8 * dis_to_next) point_up = peaks[jj] + first_nonzero - int(1.0 / 1.8 * dis_to_next)
distances = [cv2.pointPolygonTest(contour_text_interest_copy, (xv[mj], peaks[jj] + first_nonzero), True) for mj in range(len(xv))] 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))]
distances = np.array(distances) distances = np.array(distances)
xvinside = xv[distances >= 0] xvinside = xv[distances >= 0]
@ -931,7 +931,7 @@ def separate_lines_vertical(img_patch, contour_text_interest, thetha):
point_up = peaks[jj] + first_nonzero - int(1.0 / 1.9 * dis_to_next_up) point_up = peaks[jj] + first_nonzero - int(1.0 / 1.9 * dis_to_next_up)
point_down = peaks[jj] + first_nonzero + int(1.0 / 1.9 * dis_to_next_down) point_down = peaks[jj] + first_nonzero + int(1.0 / 1.9 * dis_to_next_down)
distances = [cv2.pointPolygonTest(contour_text_interest_copy, (xv[mj], peaks[jj] + first_nonzero), True) for mj in range(len(xv))] 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))]
distances = np.array(distances) distances = np.array(distances)
xvinside = xv[distances >= 0] xvinside = xv[distances >= 0]
@ -1382,7 +1382,7 @@ def textline_contours_postprocessing(textline_mask, slope, contour_text_interest
# textline_mask = cv2.erode(textline_mask, kernel, iterations=1) # textline_mask = cv2.erode(textline_mask, kernel, iterations=1)
# print(textline_mask.shape[0]/float(textline_mask.shape[1]),'miz') # print(textline_mask.shape[0]/float(textline_mask.shape[1]),'miz')
try: #try:
# if np.abs(slope)>.5 and textline_mask.shape[0]/float(textline_mask.shape[1])>3: # if np.abs(slope)>.5 and textline_mask.shape[0]/float(textline_mask.shape[1])>3:
# plt.imshow(textline_mask) # plt.imshow(textline_mask)
# plt.show() # plt.show()
@ -1455,9 +1455,9 @@ def textline_contours_postprocessing(textline_mask, slope, contour_text_interest
else: else:
_, contours_rotated_clean = separate_lines(dst, contours_text_rot[ind_big_con], slope, x_help, y_help) _, contours_rotated_clean = separate_lines(dst, contours_text_rot[ind_big_con], slope, x_help, y_help)
except: #except:
contours_rotated_clean = [] #contours_rotated_clean = []
return contours_rotated_clean return contours_rotated_clean

Loading…
Cancel
Save