|
1 | | -from typing import Tuple |
| 1 | +from typing import Tuple, Literal |
2 | 2 |
|
3 | 3 | import numpy as np |
4 | 4 | from numpy import ma |
|
7 | 7 | from pose_format.pose_header import PoseHeader, PoseHeaderDimensions |
8 | 8 | from pose_format.utils.normalization_3d import PoseNormalizer |
9 | 9 | from pose_format.utils.openpose import OpenPose_Components |
| 10 | +from pose_format.utils.openpose_135 import OpenPose_Components as OpenPose135_Components |
| 11 | +# from pose_format.utils.holistic import holistic_components # creates an error: ImportError: Please install mediapipe with: pip install mediapipe |
10 | 12 |
|
| 13 | +SupportedPoseFormat = Literal["holistic", "openpose", "openpose_135"] |
| 14 | + |
| 15 | +def detect_pose_format(pose: Pose) -> SupportedPoseFormat: |
| 16 | + component_names = [c.name for c in pose.header.components] |
| 17 | + |
| 18 | + # would be better to import from pose_format.utils.holistic but that creates a dep on mediapipe |
| 19 | + mediapipe_components = [ |
| 20 | + "POSE_LANDMARKS", |
| 21 | + "FACE_LANDMARKS", |
| 22 | + "LEFT_HAND_LANDMARKS", |
| 23 | + "RIGHT_HAND_LANDMARKS", |
| 24 | + "POSE_WORLD_LANDMARKS", |
| 25 | + ] |
| 26 | + |
| 27 | + openpose_components = [c.name for c in OpenPose_Components] |
| 28 | + openpose_135_components = [c.name for c in OpenPose135_Components] |
| 29 | + for component_name in component_names: |
| 30 | + if component_name in mediapipe_components: |
| 31 | + return "holistic" |
| 32 | + if component_name in openpose_components: |
| 33 | + return "openpose" |
| 34 | + if component_name in openpose_135_components: |
| 35 | + return "openpose_135" |
| 36 | + |
| 37 | + raise ValueError( |
| 38 | + f"Unknown pose header schema with component names: {component_names}" |
| 39 | + ) |
11 | 40 |
|
12 | 41 | def normalize_pose_size(pose: Pose, target_width: int = 512): |
13 | 42 | shift = 1.25 |
|
0 commit comments