Skip to content
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
fix: rename mediapipe_pose module to pose
Browse files Browse the repository at this point in the history
  • Loading branch information
Mouwrice committed May 28, 2024
1 parent adbbdc7 commit 689d20c
Show file tree
Hide file tree
Showing 14 changed files with 558 additions and 10 deletions.
2 changes: 1 addition & 1 deletion drumpy/app/camera_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pygame import Surface

from drumpy.app.video_source import VideoSource, Source
from drumpy.mediapipe_pose.mediapipe_pose import MediaPipePose
from drumpy.pose.mediapipe_pose import MediaPipePose


class VideoDisplay:
Expand Down
2 changes: 1 addition & 1 deletion drumpy/app/fps_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pygame_gui import UIManager # type: ignore
from pygame_gui.elements import UILabel # type: ignore

from drumpy.mediapipe_pose.mediapipe_pose import MediaPipePose
from drumpy.pose.mediapipe_pose import MediaPipePose

MEMORY = 30

Expand Down
6 changes: 3 additions & 3 deletions drumpy/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from drumpy.app.camera_display import VideoDisplay
from drumpy.app.fps_display import FPSDisplay
from drumpy.app.video_source import CameraSource, VideoFileSource, Source
from drumpy.mediapipe_pose.landmark_type import LandmarkType
from drumpy.mediapipe_pose.landmarker_model import LandmarkerModel
from drumpy.mediapipe_pose.mediapipe_pose import MediaPipePose
from drumpy.pose.landmark_type import LandmarkType
from drumpy.pose.landmarker_model import LandmarkerModel
from drumpy.pose.mediapipe_pose import MediaPipePose
from drumpy.tracking.drum_trackers import DrumTrackers


Expand Down
2 changes: 1 addition & 1 deletion drumpy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from drumpy.app.main import App
from drumpy.app.video_source import Source
from drumpy.mediapipe_pose.landmarker_model import LandmarkerModel
from drumpy.pose.landmarker_model import LandmarkerModel


def parse_running_mode(mode: str) -> RunningMode:
Expand Down
2 changes: 1 addition & 1 deletion drumpy/drum/drum.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from drumpy.drum.sound import Sound, SoundState
from drumpy.util import position_str, Position
from drumpy.mediapipe_pose.mediapipe_markers import MarkerEnum
from drumpy.pose.mediapipe_markers import MarkerEnum


class DrumPresets:
Expand Down
Empty file added drumpy/pose/__init__.py
Empty file.
23 changes: 23 additions & 0 deletions drumpy/pose/landmark_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from enum import Enum


class LandmarkType(Enum):
"""
From the MediaPipe documentation:
The output contains both normalized coordinates (Landmarks) and world coordinates (WorldLandmarks)
for each landmark.
The output contains the following normalized coordinates (Landmarks):
- x and y: Landmark coordinates normalized between 0.0 and 1.0 by the image width (x) and height (y).
- z: The landmark depth, with the depth at the midpoint of the hips as the origin. The smaller the value,
the closer the landmark is to the camera. The magnitude of z uses roughly the same scale as x.
- visibility: The likelihood of the landmark being visible within the image.
The output contains the following world coordinates (WorldLandmarks):
- x, y, and z: Real-world 3-dimensional coordinates in meters, with the midpoint of the hips as the origin.
- visibility: The likelihood of the landmark being visible within the image.
"""

LANDMARKS = 0
WORLD_LANDMARKS = 1
7 changes: 7 additions & 0 deletions drumpy/pose/landmarker_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from enum import Enum


class LandmarkerModel(Enum):
LITE = "./resources/pose_landmarker_models/pose_landmarker_lite.task"
FULL = "./resources/pose_landmarker_models/pose_landmarker_full.task"
HEAVY = "./resources/pose_landmarker_models/pose_landmarker_heavy.task"
156 changes: 156 additions & 0 deletions drumpy/pose/mediapipe_markers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
from enum import IntEnum
from typing import Self


class MarkerEnum(IntEnum):
"""
From the documentation:
0 - nose
1 - left eye (inner)
2 - left eye
3 - left eye (outer)
4 - right eye (inner)
5 - right eye
6 - right eye (outer)
7 - left ear
8 - right ear
9 - mouth (left)
10 - mouth (right)
11 - left shoulder
12 - right shoulder
13 - left elbow
14 - right elbow
15 - left wrist
16 - right wrist
17 - left pinky
18 - right pinky
19 - left index
20 - right index
21 - left thumb
22 - right thumb
23 - left hip
24 - right hip
25 - left knee
26 - right knee
27 - left ankle
28 - right ankle
29 - left heel
30 - right heel
31 - left foot index
32 - right foot index
"""

NOSE = 0
LEFT_EYE_INNER = 1
LEFT_EYE = 2
LEFT_EYE_OUTER = 3
RIGHT_EYE_INNER = 4
RIGHT_EYE = 5
RIGHT_EYE_OUTER = 6
LEFT_EAR = 7
RIGHT_EAR = 8
MOUTH_LEFT = 9
MOUTH_RIGHT = 10
LEFT_SHOULDER = 11
RIGHT_SHOULDER = 12
LEFT_ELBOW = 13
RIGHT_ELBOW = 14
LEFT_WRIST = 15
RIGHT_WRIST = 16
LEFT_PINKY = 17
RIGHT_PINKY = 18
LEFT_INDEX = 19
RIGHT_INDEX = 20
LEFT_THUMB = 21
RIGHT_THUMB = 22
LEFT_HIP = 23
RIGHT_HIP = 24
LEFT_KNEE = 25
RIGHT_KNEE = 26
LEFT_ANKLE = 27
RIGHT_ANKLE = 28
LEFT_HEEL = 29
RIGHT_HEEL = 30
LEFT_FOOT_INDEX = 31
RIGHT_FOOT_INDEX = 32

# Some own additions
LEFT_DRUM_STICK = 33
RIGHT_DRUM_STICK = 34
LEFT_FOOT = 35
RIGHT_FOOT = 36

@staticmethod
def from_qtm_label(label: str) -> "MarkerEnum": # noqa: PLR0911
match label:
case "Nose":
return MarkerEnum.NOSE
case "Eye_Inner_L":
return MarkerEnum.LEFT_EYE_INNER
case "Eye_L":
return MarkerEnum.LEFT_EYE
case "Eye_Outer_L":
return MarkerEnum.LEFT_EYE_OUTER
case "Eye_Inner_R":
return MarkerEnum.RIGHT_EYE_INNER
case "Eye_R":
return MarkerEnum.RIGHT_EYE
case "Eye_Outer_R":
return MarkerEnum.RIGHT_EYE_OUTER
case "Ear_L":
return MarkerEnum.LEFT_EAR
case "Ear_R":
return MarkerEnum.RIGHT_EAR
case "Mouth_L":
return MarkerEnum.MOUTH_LEFT
case "Mouth_R":
return MarkerEnum.MOUTH_RIGHT
case "Shoulder_L":
return MarkerEnum.LEFT_SHOULDER
case "Shoulder_R":
return MarkerEnum.RIGHT_SHOULDER
case "Elbow_L":
return MarkerEnum.LEFT_ELBOW
case "Elbow_R":
return MarkerEnum.RIGHT_ELBOW
case "Wrist_L":
return MarkerEnum.LEFT_WRIST
case "Wrist_R":
return MarkerEnum.RIGHT_WRIST
case "Pinky_L":
return MarkerEnum.LEFT_PINKY
case "Pinky_R":
return MarkerEnum.RIGHT_PINKY
case "Index_L":
return MarkerEnum.LEFT_INDEX
case "Index_R":
return MarkerEnum.RIGHT_INDEX
case "Thumb_L":
return MarkerEnum.LEFT_THUMB
case "Thumb_R":
return MarkerEnum.RIGHT_THUMB
case "Hip_L":
return MarkerEnum.LEFT_HIP
case "Hip_R":
return MarkerEnum.RIGHT_HIP
case "Knee_L":
return MarkerEnum.LEFT_KNEE
case "Knee_R":
return MarkerEnum.RIGHT_KNEE
case "Ankle_L":
return MarkerEnum.LEFT_ANKLE
case "Ankle_R":
return MarkerEnum.RIGHT_ANKLE
case "Heel_L":
return MarkerEnum.LEFT_HEEL
case "Heel_R":
return MarkerEnum.RIGHT_HEEL
case "Foot_Index_L":
return MarkerEnum.LEFT_FOOT_INDEX
case "Foot_Index_R":
return MarkerEnum.RIGHT_FOOT_INDEX
case _:
raise ValueError(f"Unknown label: {label}")

def __str__(self: Self) -> str:
return self.name.replace("_", " ").title()
Loading

0 comments on commit 689d20c

Please sign in to comment.