| 45 | |
| 46 | |
| 47 | def sanitize_bbox(bbox, img_width, img_height): |
| 48 | x, y, w, h = bbox |
| 49 | x1 = np.max((0, x)) |
| 50 | y1 = np.max((0, y)) |
| 51 | x2 = np.min((img_width - 1, x1 + np.max((0, w - 1)))) |
| 52 | y2 = np.min((img_height - 1, y1 + np.max((0, h - 1)))) |
| 53 | if w > 0 and h > 0 and x2 >= x1 and y2 >= y1: |
| 54 | bbox = np.array([x1, y1, x2 - x1 + 1, y2 - y1 + 1]) |
| 55 | else: |
| 56 | bbox = None |
| 57 | |
| 58 | return bbox |
| 59 | def resize(ori_shape, size, max_size=None): |
| 60 | # size can be min_size (scalar) or (w, h) tuple |
| 61 | # import ipdb; ipdb.set_trace(context=15) |