def filter_overlap self line_boxes line_boxes sorted line_boxes key la

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def filter_overlap(self, line_boxes):
line_boxes = sorted(line_boxes,key=lambda box: (box[1], box[0]))
corr_boxes = [line_boxes[0]]
for i in range(1, len(line_boxes)):
prev = corr_boxes[-1]
curr = line_boxes[i]
center_y = (curr[3] - curr[1]) // 2 + curr[1]
if center_y > prev[1] and center_y < prev[3] and self.overlap_x(prev, curr):
corr_boxes.pop()
corr_boxes += [[min(prev[0], curr[0]), min(prev[1], curr[1]), max(prev[2], curr[2]), max(prev[3], curr[3])]]
else:
corr_boxes += [curr]
return corr_boxes