Flip human joints horizontally. Note: num_keypoints: K num_dimension: D Args: keypoints (np.ndarray([K, D])): Coordinates of keypoints. flip_pairs (list[tuple()]): Pairs of keypoints which are mirrored (for example, left ear -- right ear).
(keypoints, flip_pairs, img_width=None)
| 259 | |
| 260 | |
| 261 | def _flip_keypoints(keypoints, flip_pairs, img_width=None): |
| 262 | """Flip human joints horizontally. |
| 263 | |
| 264 | Note: |
| 265 | num_keypoints: K |
| 266 | num_dimension: D |
| 267 | Args: |
| 268 | keypoints (np.ndarray([K, D])): Coordinates of keypoints. |
| 269 | flip_pairs (list[tuple()]): Pairs of keypoints which are mirrored |
| 270 | (for example, left ear -- right ear). |
| 271 | img_width (int | None, optional): The width of the original image. |
| 272 | To flip 2D keypoints, image width is needed. To flip 3D keypoints, |
| 273 | we simply negate the value of x-axis. Default: None. |
| 274 | Returns: |
| 275 | keypoints_flipped |
| 276 | """ |
| 277 | |
| 278 | keypoints_flipped = keypoints.copy() |
| 279 | |
| 280 | # Swap left-right parts |
| 281 | for left, right in flip_pairs: |
| 282 | keypoints_flipped[..., left, :] = keypoints[..., right, :] |
| 283 | keypoints_flipped[..., right, :] = keypoints[..., left, :] |
| 284 | |
| 285 | # Flip horizontally |
| 286 | if img_width is None: |
| 287 | keypoints_flipped[..., 0] = -keypoints_flipped[..., 0] |
| 288 | else: |
| 289 | keypoints_flipped[..., 0] = img_width - 1 - keypoints_flipped[..., 0] |
| 290 | |
| 291 | return keypoints_flipped |
| 292 | |
| 293 | |
| 294 | def _rotate_joints_3d(joints_3d, rot): |