|
|
@@ -485,29 +485,6 @@ def table_line(img, model, size=(512, 1024), prob=0.2, is_test=0):
|
|
|
elif line[1] == line[3]:
|
|
|
list_rows.append(line)
|
|
|
|
|
|
- # 删掉贴着边框的line
|
|
|
- # temp_list = []
|
|
|
- # threshold = 5
|
|
|
- # for line in list_rows:
|
|
|
- # if line[1]-0 <= threshold or size[1]-line[1] <= threshold:
|
|
|
- # continue
|
|
|
- # # 内部排序
|
|
|
- # if line[0] > line[2]:
|
|
|
- # line = [line[2], line[3], line[0], line[1]]
|
|
|
- # temp_list.append(line)
|
|
|
- # list_rows = temp_list
|
|
|
- # temp_list = []
|
|
|
- # for line in list_cols:
|
|
|
- # if line[0]-0 <= threshold or size[0]-line[0] <= threshold:
|
|
|
- # continue
|
|
|
- # # 内部排序
|
|
|
- # if line[1] > line[3]:
|
|
|
- # line = [line[2], line[3], line[0], line[1]]
|
|
|
- # temp_list.append(line)
|
|
|
- # list_cols = temp_list
|
|
|
- # if not list_rows or not list_cols:
|
|
|
- # return []
|
|
|
-
|
|
|
# 合并错开线
|
|
|
list_rows = merge_line(list_rows, axis=0)
|
|
|
list_cols = merge_line(list_cols, axis=1)
|
|
|
@@ -519,10 +496,11 @@ def table_line(img, model, size=(512, 1024), prob=0.2, is_test=0):
|
|
|
return []
|
|
|
|
|
|
# 清掉外围的没用的线
|
|
|
- list_rows, list_cols = delete_outline(list_rows, list_cols, cross_points)
|
|
|
- mat_plot(list_rows+list_cols, "delete_outline", is_test)
|
|
|
+ # list_rows, list_cols = delete_outline(list_rows, list_cols, cross_points)
|
|
|
+ # mat_plot(list_rows+list_cols, "delete_outline", is_test)
|
|
|
|
|
|
# 多个表格分割线
|
|
|
+ list_rows, list_cols = fix_in_split_lines(list_rows, list_cols, img_new)
|
|
|
split_lines, split_y = get_split_line(cross_points, list_cols, img_new)
|
|
|
|
|
|
# 修复边框
|
|
|
@@ -541,9 +519,15 @@ def table_line(img, model, size=(512, 1024), prob=0.2, is_test=0):
|
|
|
if new_cols:
|
|
|
list_cols += new_cols
|
|
|
|
|
|
+ list_rows, list_cols = fix_in_split_lines(list_rows, list_cols, img_new)
|
|
|
+
|
|
|
# 修复边框后重新计算交点、分割线
|
|
|
cross_points = get_points(list_rows, list_cols, (img_new.shape[0], img_new.shape[1]))
|
|
|
+ cv_plot(cross_points, img_new.shape, 0, is_test)
|
|
|
+
|
|
|
split_lines, split_y = get_split_line(cross_points, list_cols, img_new)
|
|
|
+ print("fix new split_y", split_y)
|
|
|
+ print("fix new split_lines", split_lines)
|
|
|
|
|
|
# 修复内部缺线
|
|
|
# cross_points = fix_inner(list_rows, list_cols, cross_points, split_y)
|
|
|
@@ -551,16 +535,25 @@ def table_line(img, model, size=(512, 1024), prob=0.2, is_test=0):
|
|
|
# return []
|
|
|
mat_plot(list_rows+list_cols, "fix_outline", is_test)
|
|
|
|
|
|
+ split_lines_show = []
|
|
|
+ for _l in split_lines:
|
|
|
+ split_lines_show.append([_l[0][0], _l[0][1], _l[1][0], _l[1][1]])
|
|
|
+ mat_plot(split_lines_show+list_cols,
|
|
|
+ "split_lines", is_test)
|
|
|
+
|
|
|
+ # 修复表格4个角
|
|
|
+ list_rows, list_cols = fix_corner(list_rows, list_cols, split_y, threshold=0)
|
|
|
+ mat_plot(list_rows+list_cols, "fix_corner", is_test)
|
|
|
+
|
|
|
# 修复内部缺线
|
|
|
- cross_points = fix_inner(list_rows, list_cols, cross_points, split_y)
|
|
|
- if not cross_points:
|
|
|
- return []
|
|
|
- row_point_list = get_points_row(cross_points, split_y, 5)
|
|
|
- col_point_list = get_points_col(cross_points, split_y, 5)
|
|
|
- list_rows = points_to_line(row_point_list, axis=0)
|
|
|
- list_cols = points_to_line(col_point_list, axis=1)
|
|
|
+ list_rows, list_cols = fix_inner(list_rows, list_cols, cross_points, split_y)
|
|
|
mat_plot(list_rows+list_cols, "fix_inner", is_test)
|
|
|
|
|
|
+ # 合并错开线
|
|
|
+ list_rows = merge_line(list_rows, axis=0)
|
|
|
+ list_cols = merge_line(list_cols, axis=1)
|
|
|
+ mat_plot(list_rows+list_cols, "merge_line", is_test)
|
|
|
+
|
|
|
list_line = list_rows + list_cols
|
|
|
|
|
|
# 打印处理后线
|
|
|
@@ -642,6 +635,27 @@ def table_line2(img, model, size=(512, 1024), hprob=0.5, vprob=0.5, row=50, col=
|
|
|
return rowboxes, colboxes, img_new
|
|
|
|
|
|
|
|
|
+def fix_in_split_lines(_rows, _cols, _img):
|
|
|
+ # 补线贴着边缘无法得到split_y,导致无法分区
|
|
|
+ for _row in _rows:
|
|
|
+ if _row[1] >= _img.shape[0] - 5:
|
|
|
+ _row[1] = _img.shape[0] - 6
|
|
|
+ _row[3] = _img.shape[0] - 6
|
|
|
+ print("_row", _row)
|
|
|
+ if _row[1] <= 0 + 5:
|
|
|
+ _row[1] = 6
|
|
|
+ _row[3] = 6
|
|
|
+
|
|
|
+ for _col in _cols:
|
|
|
+ if _col[3] >= _img.shape[0] - 5:
|
|
|
+ _col[3] = _img.shape[0] - 6
|
|
|
+
|
|
|
+ if _col[1] <= 0 + 5:
|
|
|
+ _col[1] = 6
|
|
|
+
|
|
|
+ return _rows, _cols
|
|
|
+
|
|
|
+
|
|
|
def mat_plot(list_line, name="", is_test=1):
|
|
|
if not is_test:
|
|
|
return
|
|
|
@@ -654,14 +668,22 @@ def mat_plot(list_line, name="", is_test=1):
|
|
|
plt.show()
|
|
|
|
|
|
|
|
|
-def cv_plot(list_line, img_shape):
|
|
|
+def cv_plot(_list, img_shape, line_or_point=1, is_test=1):
|
|
|
+ if is_test == 0:
|
|
|
+ return
|
|
|
img_print = np.zeros(img_shape, np.uint8)
|
|
|
img_print.fill(255)
|
|
|
- for line in list_line:
|
|
|
- cv2.line(img_print, (int(line[0]), int(line[1])), (int(line[2]), int(line[3])),
|
|
|
- (255, 0, 0))
|
|
|
- cv2.imshow("cv_plot", img_print)
|
|
|
- cv2.waitKey(0)
|
|
|
+ if line_or_point:
|
|
|
+ for line in _list:
|
|
|
+ cv2.line(img_print, (int(line[0]), int(line[1])), (int(line[2]), int(line[3])),
|
|
|
+ (255, 0, 0))
|
|
|
+ cv2.imshow("cv_plot", img_print)
|
|
|
+ cv2.waitKey(0)
|
|
|
+ else:
|
|
|
+ for point in _list:
|
|
|
+ cv2.circle(img_print, (int(point[0]), int(point[1])), 1, (255, 0, 0), 2)
|
|
|
+ cv2.imshow("cv_plot", img_print)
|
|
|
+ cv2.waitKey(0)
|
|
|
|
|
|
|
|
|
def delete_no_cross_lines(list_lines):
|
|
|
@@ -725,7 +747,7 @@ def get_outline(points, image_np):
|
|
|
return outline_img
|
|
|
|
|
|
|
|
|
-def get_split_line(points, col_lines, image_np):
|
|
|
+def get_split_line(points, col_lines, image_np, threshold=5):
|
|
|
# print("get_split_line", image_np.shape)
|
|
|
points.sort(key=lambda x: (x[1], x[0]))
|
|
|
# 遍历y坐标,并判断y坐标与上一个y坐标是否存在连接线
|
|
|
@@ -734,10 +756,10 @@ def get_split_line(points, col_lines, image_np):
|
|
|
for point in points:
|
|
|
# 从已分开的线下面开始判断
|
|
|
if split_line_y:
|
|
|
- if point[1] <= split_line_y[-1] + 5:
|
|
|
+ if point[1] <= split_line_y[-1] + threshold:
|
|
|
last_y = point[1]
|
|
|
continue
|
|
|
- if last_y <= split_line_y[-1] + 5:
|
|
|
+ if last_y <= split_line_y[-1] + threshold:
|
|
|
last_y = point[1]
|
|
|
continue
|
|
|
|
|
|
@@ -768,14 +790,14 @@ def get_split_line(points, col_lines, image_np):
|
|
|
y_min = points[0][1]
|
|
|
y_max = points[-1][1]
|
|
|
# print("加上收尾分割线", y_min, y_max)
|
|
|
- if y_min-5 < 0:
|
|
|
+ if y_min-threshold < 0:
|
|
|
split_line_y.append(0)
|
|
|
else:
|
|
|
- split_line_y.append(y_min-5)
|
|
|
- if y_max+5 > image_np.shape[0]:
|
|
|
+ split_line_y.append(y_min-threshold)
|
|
|
+ if y_max+threshold > image_np.shape[0]:
|
|
|
split_line_y.append(image_np.shape[0])
|
|
|
else:
|
|
|
- split_line_y.append(y_max+5)
|
|
|
+ split_line_y.append(y_max+threshold)
|
|
|
split_line_y = list(set(split_line_y))
|
|
|
|
|
|
# 剔除两条相隔太近分割线
|
|
|
@@ -829,7 +851,8 @@ def get_points(row_lines, col_lines, image_size):
|
|
|
|
|
|
# 求出交点
|
|
|
point_img = np.bitwise_and(row_img, col_img)
|
|
|
- # cv2.imshow("point_img", np.bitwise_not(point_img))
|
|
|
+ # cv2.imwrite("get_points.jpg", row_img+col_img)
|
|
|
+ # cv2.imshow("get_points", row_img+col_img)
|
|
|
# cv2.waitKey(0)
|
|
|
|
|
|
# 识别黑白图中的白色交叉点,将横纵坐标取出
|
|
|
@@ -998,7 +1021,7 @@ def fix_inner2(row_points, col_points, row_lines, col_lines, threshold=3):
|
|
|
return row_lines, col_lines
|
|
|
|
|
|
|
|
|
-def fix_inner(row_lines, col_lines, points, split_y):
|
|
|
+def fix_inner1(row_lines, col_lines, points, split_y):
|
|
|
def fix(fix_lines, assist_lines, split_points, axis):
|
|
|
new_points = []
|
|
|
for line1 in fix_lines:
|
|
|
@@ -1047,11 +1070,11 @@ def fix_inner(row_lines, col_lines, points, split_y):
|
|
|
line_distance = abs(min_col_point[i][axis] - line1_point[i][axis])
|
|
|
if bbox_len/3 <= line_distance <= bbox_len:
|
|
|
add_point = (line1_point[i][1-axis], min_assist_line[i][axis])
|
|
|
- # print("============================table line==")
|
|
|
- # print("fix_inner add point", add_point)
|
|
|
- # print(min_col_point[i][axis], line1_point[i][axis], min_col_point[i][axis], min_assist_line[i][axis])
|
|
|
- # print(abs(min_col_point[i][axis] - line1_point[i][axis]), abs(min_col_point[i][axis] - min_assist_line[i][axis])/3)
|
|
|
- # print("line1, line2", line1, min_assist_line[i])
|
|
|
+ print("============================table line==")
|
|
|
+ print("fix_inner add point", add_point)
|
|
|
+ print(min_col_point[i][axis], line1_point[i][axis], min_col_point[i][axis], min_assist_line[i][axis])
|
|
|
+ print(abs(min_col_point[i][axis] - line1_point[i][axis]), abs(min_col_point[i][axis] - min_assist_line[i][axis])/3)
|
|
|
+ print("line1, line2", line1, min_assist_line[i])
|
|
|
new_points.append(add_point)
|
|
|
|
|
|
return new_points
|
|
|
@@ -1144,7 +1167,138 @@ def fix_inner(row_lines, col_lines, points, split_y):
|
|
|
return points+new_points
|
|
|
|
|
|
|
|
|
-def fix_corner(row_lines, col_lines, split_y):
|
|
|
+def fix_inner(row_lines, col_lines, points, split_y):
|
|
|
+ def fix(fix_lines, assist_lines, split_points, axis):
|
|
|
+ new_points = []
|
|
|
+ for line1 in fix_lines:
|
|
|
+ min_assist_line = [[], []]
|
|
|
+ min_distance = [1000, 1000]
|
|
|
+ if_find = [0, 0]
|
|
|
+
|
|
|
+ # 获取fix_line中的所有col point,里面可能不包括两个顶点,col point是交点,顶点可能不是交点
|
|
|
+ fix_line_points = []
|
|
|
+ for point in split_points:
|
|
|
+ if abs(point[1-axis] - line1[1-axis]) <= 2:
|
|
|
+ if line1[axis] <= point[axis] <= line1[axis+2]:
|
|
|
+ fix_line_points.append(point)
|
|
|
+
|
|
|
+ # 找出离两个顶点最近的assist_line, 并且assist_line与fix_line不相交
|
|
|
+ line1_point = [line1[:2], line1[2:]]
|
|
|
+ for i in range(2):
|
|
|
+ point = line1_point[i]
|
|
|
+ for line2 in assist_lines:
|
|
|
+ if not if_find[i] and abs(point[axis] - line2[axis]) <= 2:
|
|
|
+ if line1[1-axis] <= point[1-axis] <= line2[1-axis+2]:
|
|
|
+ # print("line1, match line2", line1, line2)
|
|
|
+ if_find[i] = 1
|
|
|
+ break
|
|
|
+ else:
|
|
|
+ if abs(point[axis] - line2[axis]) < min_distance[i] and line2[1-axis] <= point[1-axis] <= line2[1-axis+2]:
|
|
|
+ if line1[axis] <= line2[axis] <= line1[axis+2]:
|
|
|
+ continue
|
|
|
+ min_distance[i] = abs(line1[axis] - line2[axis])
|
|
|
+ min_assist_line[i] = line2
|
|
|
+
|
|
|
+ # 找出离assist_line最近的交点
|
|
|
+ # 顶点到交点的距离(多出来的线)需大于assist_line到交点的距离(bbox的边)的1/3
|
|
|
+ min_distance = [1000, 1000]
|
|
|
+ min_col_point = [[], []]
|
|
|
+ for i in range(2):
|
|
|
+ # print("顶点", i, line1_point[i])
|
|
|
+ if min_assist_line[i]:
|
|
|
+ for point in fix_line_points:
|
|
|
+ if abs(point[axis] - min_assist_line[i][axis]) < min_distance[i]:
|
|
|
+ min_distance[i] = abs(point[axis] - min_assist_line[i][axis])
|
|
|
+ min_col_point[i] = point
|
|
|
+
|
|
|
+ # print("min_col_point", min_col_point)
|
|
|
+ # print("min_assist_line", min_assist_line)
|
|
|
+ # print("line1_point", line1_point)
|
|
|
+ if min_assist_line[0] and min_assist_line[0] == min_assist_line[1]:
|
|
|
+ if min_assist_line[0][axis] < line1_point[0][axis]:
|
|
|
+ bbox_len = abs(min_col_point[0][axis] - min_assist_line[0][axis])
|
|
|
+ line_distance = abs(min_col_point[0][axis] - line1_point[0][axis])
|
|
|
+ if bbox_len/3 <= line_distance <= bbox_len:
|
|
|
+ if axis == 1:
|
|
|
+ add_point = (line1_point[0][1-axis], min_assist_line[0][axis])
|
|
|
+ else:
|
|
|
+ add_point = (min_assist_line[0][axis], line1_point[0][1-axis])
|
|
|
+ new_points.append([line1, add_point])
|
|
|
+ elif min_assist_line[1][axis] > line1_point[1][axis]:
|
|
|
+ bbox_len = abs(min_col_point[1][axis] - min_assist_line[1][axis])
|
|
|
+ line_distance = abs(min_col_point[1][axis] - line1_point[1][axis])
|
|
|
+ if bbox_len/3 <= line_distance <= bbox_len:
|
|
|
+ if axis == 1:
|
|
|
+ add_point = (line1_point[1][1-axis], min_assist_line[1][axis])
|
|
|
+ else:
|
|
|
+ add_point = (min_assist_line[1][axis], line1_point[1][1-axis])
|
|
|
+ new_points.append([line1, add_point])
|
|
|
+ else:
|
|
|
+ for i in range(2):
|
|
|
+ if min_col_point[i]:
|
|
|
+ bbox_len = abs(min_col_point[i][axis] - min_assist_line[i][axis])
|
|
|
+ line_distance = abs(min_col_point[i][axis] - line1_point[i][axis])
|
|
|
+ # print("bbox_len, line_distance", bbox_len, line_distance)
|
|
|
+ if bbox_len/3 <= line_distance <= bbox_len:
|
|
|
+ if axis == 1:
|
|
|
+ add_point = (line1_point[i][1-axis], min_assist_line[i][axis])
|
|
|
+ else:
|
|
|
+ add_point = (min_assist_line[i][axis], line1_point[i][1-axis])
|
|
|
+ # print("============================table line==")
|
|
|
+ # print("fix_inner add point", add_point)
|
|
|
+ # print(min_col_point[i][axis], line1_point[i][axis], min_col_point[i][axis], min_assist_line[i][axis])
|
|
|
+ # print(abs(min_col_point[i][axis] - line1_point[i][axis]), abs(min_col_point[i][axis] - min_assist_line[i][axis])/3)
|
|
|
+ # print("line1, line2", line1, min_assist_line[i])
|
|
|
+ # print("line1, add_point", [line1, add_point])
|
|
|
+ new_points.append([line1, add_point])
|
|
|
+
|
|
|
+ return new_points
|
|
|
+
|
|
|
+ new_points = []
|
|
|
+ for i in range(1, len(split_y)):
|
|
|
+ last_y = split_y[i-1]
|
|
|
+ y = split_y[i]
|
|
|
+
|
|
|
+ # 先对点线进行分区
|
|
|
+ split_row_lines = []
|
|
|
+ split_col_lines = []
|
|
|
+ split_points = []
|
|
|
+ for row in row_lines:
|
|
|
+ if last_y <= row[1] <= y:
|
|
|
+ split_row_lines.append(row)
|
|
|
+ for col in col_lines:
|
|
|
+ if last_y <= col[1] <= y:
|
|
|
+ split_col_lines.append(col)
|
|
|
+ for point in points:
|
|
|
+ if last_y <= point[1] <= y:
|
|
|
+ split_points.append(point)
|
|
|
+
|
|
|
+ new_point_list = fix(split_col_lines, split_row_lines, split_points, axis=1)
|
|
|
+ for line, new_point in new_point_list:
|
|
|
+ if line in col_lines:
|
|
|
+ index = col_lines.index(line)
|
|
|
+ point1 = line[:2]
|
|
|
+ point2 = line[2:]
|
|
|
+ if new_point[1] >= point2[1]:
|
|
|
+ col_lines[index] = [point1[0], point1[1], new_point[0], new_point[1]]
|
|
|
+ elif new_point[1] <= point1[1]:
|
|
|
+ col_lines[index] = [new_point[0], new_point[1], point2[0], point2[1]]
|
|
|
+
|
|
|
+ new_point_list = fix(split_row_lines, split_col_lines, split_points, axis=0)
|
|
|
+ for line, new_point in new_point_list:
|
|
|
+ if line in row_lines:
|
|
|
+ index = row_lines.index(line)
|
|
|
+ point1 = line[:2]
|
|
|
+ point2 = line[2:]
|
|
|
+ if new_point[0] >= point2[0]:
|
|
|
+ row_lines[index] = [point1[0], point1[1], new_point[0], new_point[1]]
|
|
|
+ elif new_point[0] <= point1[0]:
|
|
|
+ row_lines[index] = [new_point[0], new_point[1], point2[0], point2[1]]
|
|
|
+
|
|
|
+ return row_lines, col_lines
|
|
|
+
|
|
|
+
|
|
|
+def fix_corner(row_lines, col_lines, split_y, threshold=0):
|
|
|
new_row_lines = []
|
|
|
new_col_lines = []
|
|
|
last_y = split_y[0]
|
|
|
@@ -1155,10 +1309,11 @@ def fix_corner(row_lines, col_lines, split_y):
|
|
|
split_row_lines = []
|
|
|
split_col_lines = []
|
|
|
for row in row_lines:
|
|
|
- if last_y <= row[1] <= y or last_y <= row[3] <= y:
|
|
|
+ if last_y-threshold <= row[1] <= y+threshold or last_y-threshold <= row[3] <= y+threshold:
|
|
|
split_row_lines.append(row)
|
|
|
for col in col_lines:
|
|
|
- if last_y <= col[1] <= y or last_y <= col[3] <= y:
|
|
|
+ # fix corner 容易因split line 漏掉线
|
|
|
+ if last_y-threshold <= col[1] <= y+threshold or last_y-threshold <= col[3] <= y+threshold:
|
|
|
split_col_lines.append(col)
|
|
|
|
|
|
if not split_row_lines or not split_col_lines:
|
|
|
@@ -1629,11 +1784,13 @@ def fix_outline2(image, row_lines, col_lines, points, split_y):
|
|
|
return new_row_lines, new_col_lines, all_longer_row_lines, all_longer_col_lines
|
|
|
|
|
|
|
|
|
-def fix_outline(image, row_lines, col_lines, points, split_y, scale=20):
|
|
|
+def fix_outline(image, row_lines, col_lines, points, split_y, scale=25):
|
|
|
+ logging.info("into fix_outline")
|
|
|
x_min_len = max(10, int(image.shape[0] / scale))
|
|
|
y_min_len = max(10, int(image.shape[1] / scale))
|
|
|
+ # print("x_min_len", x_min_len, "y_min_len", y_min_len)
|
|
|
|
|
|
- print("split_y", split_y)
|
|
|
+ # print("split_y", split_y)
|
|
|
# 分割线纵坐标
|
|
|
if len(split_y) < 2:
|
|
|
return [], [], [], []
|
|
|
@@ -1735,13 +1892,16 @@ def fix_outline(image, row_lines, col_lines, points, split_y, scale=20):
|
|
|
for j in range(len(split_row_list[i])):
|
|
|
if j + 1 > len(split_row_list[i]) - 1:
|
|
|
break
|
|
|
+ # print("height_dict", split_row_list[i][j], split_row_list[i][j+1])
|
|
|
height = abs(int(split_row_list[i][j][3] - split_row_list[i][j+1][3]))
|
|
|
- if height in height_dict.keys():
|
|
|
- height_dict[height] = height_dict[height] + 1
|
|
|
- else:
|
|
|
- height_dict[height] = 1
|
|
|
+ if height >= 10:
|
|
|
+ if height in height_dict.keys():
|
|
|
+ height_dict[height] = height_dict[height] + 1
|
|
|
+ else:
|
|
|
+ height_dict[height] = 1
|
|
|
height_list = [[x, height_dict[x]] for x in height_dict.keys()]
|
|
|
height_list.sort(key=lambda x: (x[1], -x[0]), reverse=True)
|
|
|
+ # print("box_height", height_list)
|
|
|
box_height = height_list[0][0]
|
|
|
else:
|
|
|
box_height = y_min_len
|
|
|
@@ -1750,11 +1910,20 @@ def fix_outline(image, row_lines, col_lines, points, split_y, scale=20):
|
|
|
box_width = abs(split_col_list[i][1][2] - split_col_list[i][0][2])
|
|
|
else:
|
|
|
box_width = x_min_len
|
|
|
- print("box_height", box_height, "box_width", box_width)
|
|
|
+ # print("box_height", box_height, "box_width", box_width)
|
|
|
+
|
|
|
+ # 设置轮廓线需超出阈值
|
|
|
+ if box_height >= 2*y_min_len:
|
|
|
+ fix_h_len = y_min_len
|
|
|
+ else:
|
|
|
+ fix_h_len = box_height * 2/3
|
|
|
+ if box_width >= 2*x_min_len:
|
|
|
+ fix_w_len = x_min_len
|
|
|
+ else:
|
|
|
+ fix_w_len = box_width * 2/3
|
|
|
|
|
|
# 补左右两条竖线超出来的线的row
|
|
|
- if (up_line[1] - left_line[1] >= y_min_len and up_line[1] - right_line[1] >= y_min_len) or \
|
|
|
- (up_line[1] - left_line[1] >= y_min_len and up_line[1] - right_line[1] >= y_min_len):
|
|
|
+ if up_line[1] - left_line[1] >= fix_h_len and up_line[1] - right_line[1] >= fix_h_len:
|
|
|
|
|
|
if up_line[1] - left_line[1] >= up_line[1] - right_line[1]:
|
|
|
new_row_lines.append([left_line[0], left_line[1], right_line[0], left_line[1]])
|
|
|
@@ -1781,8 +1950,7 @@ def fix_outline(image, row_lines, col_lines, points, split_y, scale=20):
|
|
|
if abs(new_col_y - col[1]) <= box_height:
|
|
|
split_col_list[i][j][1] = min([new_col_y, col[1]])
|
|
|
|
|
|
- if (left_line[3] - bottom_line[3] >= y_min_len and right_line[3] - bottom_line[3] >= y_min_len) or \
|
|
|
- (left_line[3] - bottom_line[3] >= y_min_len and right_line[3] - bottom_line[3] >= y_min_len):
|
|
|
+ if left_line[3] - bottom_line[3] >= fix_h_len and right_line[3] - bottom_line[3] >= fix_h_len:
|
|
|
|
|
|
if left_line[3] - bottom_line[3] >= right_line[3] - bottom_line[3]:
|
|
|
new_row_lines.append([left_line[2], left_line[3], right_line[2], left_line[3]])
|
|
|
@@ -1805,8 +1973,7 @@ def fix_outline(image, row_lines, col_lines, points, split_y, scale=20):
|
|
|
split_col_list[i][j][3] = max([new_col_y, col[3]])
|
|
|
|
|
|
# 补上下两条横线超出来的线的col
|
|
|
- if (left_line[0] - up_line[0] >= x_min_len and left_line[0] - bottom_line[0] >= x_min_len) or \
|
|
|
- (left_line[0] - up_line[0] >= x_min_len and left_line[0] - bottom_line[0] >= x_min_len):
|
|
|
+ if left_line[0] - up_line[0] >= fix_w_len and left_line[0] - bottom_line[0] >= fix_w_len:
|
|
|
if left_line[0] - up_line[0] >= left_line[0] - bottom_line[0]:
|
|
|
new_col_lines.append([up_line[0], up_line[1], up_line[0], bottom_line[1]])
|
|
|
new_row_x = up_line[0]
|
|
|
@@ -1826,8 +1993,7 @@ def fix_outline(image, row_lines, col_lines, points, split_y, scale=20):
|
|
|
if abs(new_row_x - row[0]) <= box_width:
|
|
|
split_row_list[i][j][0] = min([new_row_x, row[0]])
|
|
|
|
|
|
- if (up_line[2] - right_line[2] >= x_min_len and bottom_line[2] - right_line[2] >= x_min_len) or \
|
|
|
- (up_line[2] - right_line[2] >= x_min_len and bottom_line[2] - right_line[2] >= x_min_len):
|
|
|
+ if up_line[2] - right_line[2] >= fix_w_len and bottom_line[2] - right_line[2] >= fix_w_len:
|
|
|
if up_line[2] - right_line[2] >= bottom_line[2] - right_line[2]:
|
|
|
new_col_lines.append([up_line[2], up_line[3], up_line[2], bottom_line[3]])
|
|
|
new_row_x = up_line[2]
|