| 82 | diffs = np.diff(pts, axis=1).reshape(-1) |
| 83 | top_left = pts[np.argmin(sums)] |
| 84 | bottom_right = pts[np.argmax(sums)] |
| 85 | top_right = pts[np.argmin(diffs)] |
| 86 | bottom_left = pts[np.argmax(diffs)] |
| 87 | return np.array([top_left, top_right, bottom_right, bottom_left], dtype=np.float32) |
| 88 | |
| 89 | |
| 90 | def poly_to_bbox(poly): |
| 91 | xs = poly[:, 0] |
| 92 | ys = poly[:, 1] |
| 93 | x1 = float(xs.min()) |
| 94 | y1 = float(ys.min()) |
| 95 | x2 = float(xs.max()) |
| 96 | y2 = float(ys.max()) |
| 97 | return int(round(x1)), int(round(y1)), int(round(x2 - x1)), int(round(y2 - y1)) |