Args: boxes: (...)x4, float shape: h, w
(boxes, shape)
| 110 | |
| 111 | |
| 112 | def clip_boxes(boxes, shape): |
| 113 | """ |
| 114 | Args: |
| 115 | boxes: (...)x4, float |
| 116 | shape: h, w |
| 117 | """ |
| 118 | orig_shape = boxes.shape |
| 119 | boxes = boxes.reshape([-1, 4]) |
| 120 | h, w = shape |
| 121 | boxes[:, [0, 1]] = np.maximum(boxes[:, [0, 1]], 0) |
| 122 | boxes[:, 2] = np.minimum(boxes[:, 2], w) |
| 123 | boxes[:, 3] = np.minimum(boxes[:, 3], h) |
| 124 | return boxes.reshape(orig_shape) |
| 125 | |
| 126 | |
| 127 | def filter_boxes_inside_shape(boxes, shape): |