Convert kp2d to bbox. Args: kp2d (np.ndarray): shape should be (num_frame, num_points, 2/3) or (num_frame, num_person, num_points, 2/3). bbox_format (Literal['xyxy', 'xywh'], optional): Defaults to 'xyxy'. Returns: np.ndarray: shape will be (num_frame,
(
kp2d: np.ndarray,
bbox_format: Literal['xyxy', 'xywh'] = 'xyxy')
| 233 | |
| 234 | |
| 235 | def convert_kp2d_to_bbox( |
| 236 | kp2d: np.ndarray, |
| 237 | bbox_format: Literal['xyxy', 'xywh'] = 'xyxy') -> np.ndarray: |
| 238 | """Convert kp2d to bbox. |
| 239 | |
| 240 | Args: |
| 241 | kp2d (np.ndarray): shape should be (num_frame, num_points, 2/3) |
| 242 | or (num_frame, num_person, num_points, 2/3). |
| 243 | bbox_format (Literal['xyxy', 'xywh'], optional): Defaults to 'xyxy'. |
| 244 | |
| 245 | Returns: |
| 246 | np.ndarray: shape will be (num_frame, num_person, 4) |
| 247 | """ |
| 248 | assert bbox_format in ['xyxy', 'xywh'] |
| 249 | if kp2d.ndim == 2: |
| 250 | kp2d = kp2d[None, None] |
| 251 | elif kp2d.ndim == 3: |
| 252 | kp2d = kp2d[:, None] |
| 253 | num_frame, num_person, _, _ = kp2d.shape |
| 254 | x1 = np.max(kp2d[..., 0], axis=-2) |
| 255 | y1 = np.max(kp2d[..., 1], axis=-2) |
| 256 | x2 = np.max(kp2d[..., 2], axis=-2) |
| 257 | y2 = np.max(kp2d[..., 3], axis=-2) |
| 258 | bbox = np.concatenate([x1, y1, x2, y2], axis=-1) |
| 259 | assert bbox.shape == (num_frame, num_person, 4) |
| 260 | if bbox_format == 'xywh': |
| 261 | bbox = xyxy2xywh(bbox) |
| 262 | return bbox |
| 263 | |
| 264 | |
| 265 | def convert_verts_to_cam_coord(verts, |
no test coverage detected