Convert xywh coordinates to center and scale. Args: bbox_xywh (numpy.ndarray): the height of the bbox_xywh aspect_ratio (int, optional): Defaults to 1.0 bbox_scale_factor (float, optional): Defaults to 1.25 Returns: numpy.ndarray: center of the bbox numpy.ndarray
(bbox_xywh, aspect_ratio=1.0, bbox_scale_factor=1.25)
| 61 | |
| 62 | |
| 63 | def box2cs(bbox_xywh, aspect_ratio=1.0, bbox_scale_factor=1.25): |
| 64 | """Convert xywh coordinates to center and scale. |
| 65 | |
| 66 | Args: |
| 67 | bbox_xywh (numpy.ndarray): the height of the bbox_xywh |
| 68 | aspect_ratio (int, optional): Defaults to 1.0 |
| 69 | bbox_scale_factor (float, optional): Defaults to 1.25 |
| 70 | Returns: |
| 71 | numpy.ndarray: center of the bbox |
| 72 | numpy.ndarray: the scale of the bbox w & h |
| 73 | """ |
| 74 | if not isinstance(bbox_xywh, np.ndarray): |
| 75 | raise TypeError( |
| 76 | f'Input type is {type(bbox_xywh)}, which should be numpy.ndarray.') |
| 77 | |
| 78 | bbox_xywh = bbox_xywh.copy() |
| 79 | pixel_std = 1 |
| 80 | center = np.stack([ |
| 81 | bbox_xywh[..., 0] + bbox_xywh[..., 2] * 0.5, |
| 82 | bbox_xywh[..., 1] + bbox_xywh[..., 3] * 0.5 |
| 83 | ], -1) |
| 84 | |
| 85 | mask_h = bbox_xywh[..., 2] > aspect_ratio * bbox_xywh[..., 3] |
| 86 | mask_w = ~mask_h |
| 87 | |
| 88 | bbox_xywh[mask_h, 3] = bbox_xywh[mask_h, 2] / aspect_ratio |
| 89 | bbox_xywh[mask_w, 2] = bbox_xywh[mask_w, 3] * aspect_ratio |
| 90 | scale = np.stack([ |
| 91 | bbox_xywh[..., 2] * 1.0 / pixel_std, |
| 92 | bbox_xywh[..., 3] * 1.0 / pixel_std |
| 93 | ], -1) |
| 94 | scale = scale * bbox_scale_factor |
| 95 | |
| 96 | return center, scale |
| 97 | |
| 98 | |
| 99 | def convert_crop_cam_to_orig_img(cam: np.ndarray, |
no test coverage detected