(dst_img, bg_color=(128, 128, 128))
| 1401 | return i, i + mh, j, j + mw |
| 1402 | |
| 1403 | def find_largest_rect(dst_img, bg_color=(128, 128, 128)): |
| 1404 | valid = np.any(dst_img[..., :3] != bg_color, axis=-1) |
| 1405 | dst_h, dst_w = dst_img.shape[:2] |
| 1406 | ret, labels = cv2.connectedComponents(np.uint8(valid == False)) |
| 1407 | red_mat = np.zeros_like(labels) |
| 1408 | # denoise |
| 1409 | for i in range(1, np.max(labels)+1, 1): |
| 1410 | x, y, w, h = cv2.boundingRect(np.uint8(labels==i)) |
| 1411 | if x == 0 or (x+w) == dst_h or y == 0 or (y+h) == dst_w: |
| 1412 | red_mat[labels==i] = 1 |
| 1413 | # crop |
| 1414 | t, b, l, r = find_anchors(red_mat) |
| 1415 | |
| 1416 | return t, b, l, r |
nothing calls this directly
no test coverage detected