(bbox, H, W, scale=1.)
| 18 | |
| 19 | |
| 20 | def process_bbox(bbox, H, W, scale=1.): |
| 21 | # transform a bbox(xmin, ymin, xmax, ymax) to (H, W) square |
| 22 | x_min, y_min, x_max, y_max = bbox |
| 23 | width = x_max - x_min |
| 24 | height = y_max - y_min |
| 25 | |
| 26 | side_length = max(width, height) |
| 27 | |
| 28 | center_x = (x_min + x_max) / 2 |
| 29 | center_y = (y_min + y_max) / 2 |
| 30 | |
| 31 | scaled_side_length = side_length * scale |
| 32 | scaled_xmin = center_x - scaled_side_length / 2 |
| 33 | scaled_xmax = center_x + scaled_side_length / 2 |
| 34 | scaled_ymin = center_y - scaled_side_length / 2 |
| 35 | scaled_ymax = center_y + scaled_side_length / 2 |
| 36 | |
| 37 | scaled_xmin = int(max(0, scaled_xmin)) |
| 38 | scaled_xmax = int(min(W, scaled_xmax)) |
| 39 | scaled_ymin = int(max(0, scaled_ymin)) |
| 40 | scaled_ymax = int(min(H, scaled_ymax)) |
| 41 | |
| 42 | return scaled_xmin, scaled_ymin, scaled_xmax, scaled_ymax |
| 43 | |
| 44 | def crop_bbox(img, bbox, do_resize=False, size=512): |
| 45 |
no outgoing calls
no test coverage detected