|
@@ -773,7 +773,7 @@ class LineTable:
|
|
|
|
|
|
return list_l_rect
|
|
|
|
|
|
- def crosspoint2rect(self, list_crosspoint, margin=4):
|
|
|
+ def crosspoint2rect(self, list_crosspoint, margin=5):
|
|
|
|
|
|
dict_line_points = {}
|
|
|
for _point in list_crosspoint:
|
|
@@ -830,11 +830,35 @@ class LineTable:
|
|
|
set_bbox = set()
|
|
|
for _r in list_rect:
|
|
|
_bbox = "%.2f-%.2f-%.2f-%.2f"%_r.bbox
|
|
|
+ width = _r.bbox[2]-_r.bbox[0]
|
|
|
+ height = _r.bbox[3]-_r.bbox[1]
|
|
|
+ if width<=margin or height<=margin:
|
|
|
+ continue
|
|
|
if _bbox not in set_bbox:
|
|
|
tmp_rect.append(_r)
|
|
|
set_bbox.add(_bbox)
|
|
|
list_rect = tmp_rect
|
|
|
|
|
|
+
|
|
|
+ # import cv2
|
|
|
+ # import numpy as np
|
|
|
+ # import random
|
|
|
+ # img = np.zeros(shape=(1000,1000),dtype=np.uint8)
|
|
|
+ # img += 255
|
|
|
+ #
|
|
|
+ # color = []
|
|
|
+ # for rect in list_rect:
|
|
|
+ # color += 10
|
|
|
+ # x0,y0,x1,y1 = rect.bbox
|
|
|
+ # x0 *= 10/18
|
|
|
+ # y0 *= 10/18
|
|
|
+ # x1 *= 10/18
|
|
|
+ # y1 *= 10/18
|
|
|
+ # print(rect.bbox)
|
|
|
+ # cv2.rectangle(img, (int(x0),int(y0)),(int(x1),int(y1)), (color%255, (color+10)%255, (color+20)%255), 3)
|
|
|
+ # cv2.imshow("bbox", img)
|
|
|
+ # cv2.waitKey(0)
|
|
|
+
|
|
|
return list_rect
|
|
|
|
|
|
def cross_point(self, line1, line2, segment=True, margin=2):
|
|
@@ -1010,7 +1034,7 @@ class LineTable:
|
|
|
_y0 = _rect.bbox[3]
|
|
|
_find = False
|
|
|
for l_cr in clusters_rects:
|
|
|
- if abs(l_cr[0].bbox[3]-_y0)<2:
|
|
|
+ if abs(l_cr[0].bbox[3]-_y0)<margin:
|
|
|
_find = True
|
|
|
l_cr.append(_rect)
|
|
|
break
|
|
@@ -1029,6 +1053,8 @@ class LineTable:
|
|
|
set_y.add(y1)
|
|
|
if len(set_x)==0 or len(set_y)==0:
|
|
|
return
|
|
|
+ if len(list_rect)<=1:
|
|
|
+ return
|
|
|
list_x = list(set_x)
|
|
|
list_y = list(set_y)
|
|
|
|
|
@@ -1264,5 +1290,25 @@ def sort_object(obj_list, is_reverse=False):
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
- strs = r"D:\Project\temp\04384fcc9e8911ecbd2844f971944973\043876ca9e8911eca5e144f971944973_rar\1624114035529.jpeg"
|
|
|
- print(slash_replace(strs))
|
|
|
+ # strs = r"D:\Project\temp\04384fcc9e8911ecbd2844f971944973\043876ca9e8911eca5e144f971944973_rar\1624114035529.jpeg"
|
|
|
+ # print(slash_replace(strs))
|
|
|
+ # from matplotlib import pyplot as plt
|
|
|
+ # import random
|
|
|
+ # fig = plt.figure()
|
|
|
+ # plt.xlim(100)
|
|
|
+ # plt.ylim(100)
|
|
|
+ # fig.add_subplot(111)
|
|
|
+ # x0,y0,x1,y1 = (1,2,3,4)
|
|
|
+ # plt.gca().add_patch(plt.Rectangle(xy=(x0, y0),
|
|
|
+ # width=x1-x0,
|
|
|
+ # height=y1-y0,
|
|
|
+ # edgecolor=(random.randint(0,255)/255,random.randint(0,255)/255,random.randint(0,255)/255),
|
|
|
+ # fill=False, linewidth=2))
|
|
|
+ #
|
|
|
+ # plt.show()
|
|
|
+ import cv2
|
|
|
+ import numpy as np
|
|
|
+ img = np.zeros(shape=(1800,1800),dtype=np.uint8)
|
|
|
+ img += 255
|
|
|
+ cv2.imshow("bbox", img)
|
|
|
+ cv2.waitKey(0)
|