MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / _flip_keypoints

Function _flip_keypoints

detrsmpl/data/datasets/pipelines/transforms.py:261–291  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

259
260
261def _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
294def _rotate_joints_3d(joints_3d, rot):

Callers 1

__call__Method · 0.85

Calls 1

copyMethod · 0.80

Tested by

no test coverage detected