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)
| 52 | |
| 53 | |
| 54 | def 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 | |
| 78 | class OpenOCRE2E(object): |
no outgoing calls
no test coverage detected