MCPcopy Create free account
hub / github.com/Topdu/OpenOCR / sorted_boxes

Function sorted_boxes

tools/infer_e2e.py:54–75  ·  view source on GitHub ↗

Sort text boxes in order from top to bottom, left to right args: dt_boxes(array):detected text boxes with shape [4, 2] return: sorted boxes(array) with shape [4, 2]

(dt_boxes)

Source from the content-addressed store, hash-verified

52
53
54def sorted_boxes(dt_boxes):
55 """
56 Sort text boxes in order from top to bottom, left to right
57 args:
58 dt_boxes(array):detected text boxes with shape [4, 2]
59 return:
60 sorted boxes(array) with shape [4, 2]
61 """
62 num_boxes = dt_boxes.shape[0]
63 sorted_boxes = sorted(dt_boxes, key=lambda x: (x[0][1], x[0][0]))
64 _boxes = list(sorted_boxes)
65
66 for i in range(num_boxes - 1):
67 for j in range(i, -1, -1):
68 if abs(_boxes[j + 1][0][1] - _boxes[j][0][1]) < 10 and (
69 _boxes[j + 1][0][0] < _boxes[j][0][0]):
70 tmp = _boxes[j]
71 _boxes[j] = _boxes[j + 1]
72 _boxes[j + 1] = tmp
73 else:
74 break
75 return _boxes
76
77
78class OpenOCRE2E(object):

Callers 2

detect_textMethod · 0.90
infer_single_imageMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected