themalinery commited on
Commit
db9e7b7
·
1 Parent(s): 893cd4d
requirements.txt CHANGED
Binary files a/requirements.txt and b/requirements.txt differ
 
src/mediapipe_pose/get_landmarks_and_connections.py CHANGED
@@ -1,9 +1,44 @@
1
  from typing import Mapping, Tuple
2
- from mediapipe.python.solutions.hands import HandLandmark
3
- from mediapipe.python.solutions.drawing_utils import DrawingSpec
4
  import yaml
5
  import os
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  # Load hand drawing config from config.yaml
9
  def load_hand_drawing_config():
 
1
  from typing import Mapping, Tuple
2
+ from dataclasses import dataclass
3
+ from enum import IntEnum
4
  import yaml
5
  import os
6
 
7
+ # Try to import from mediapipe, fall back to local definitions
8
+ try:
9
+ from mediapipe.python.solutions.hands import HandLandmark
10
+ from mediapipe.python.solutions.drawing_utils import DrawingSpec
11
+ except ImportError:
12
+ # Fallback HandLandmark enum for environments without mediapipe.python.solutions
13
+ class HandLandmark(IntEnum):
14
+ WRIST = 0
15
+ THUMB_CMC = 1
16
+ THUMB_MCP = 2
17
+ THUMB_IP = 3
18
+ THUMB_TIP = 4
19
+ INDEX_FINGER_MCP = 5
20
+ INDEX_FINGER_PIP = 6
21
+ INDEX_FINGER_DIP = 7
22
+ INDEX_FINGER_TIP = 8
23
+ MIDDLE_FINGER_MCP = 9
24
+ MIDDLE_FINGER_PIP = 10
25
+ MIDDLE_FINGER_DIP = 11
26
+ MIDDLE_FINGER_TIP = 12
27
+ RING_FINGER_MCP = 13
28
+ RING_FINGER_PIP = 14
29
+ RING_FINGER_DIP = 15
30
+ RING_FINGER_TIP = 16
31
+ PINKY_MCP = 17
32
+ PINKY_PIP = 18
33
+ PINKY_DIP = 19
34
+ PINKY_TIP = 20
35
+
36
+ @dataclass
37
+ class DrawingSpec:
38
+ color: tuple = (0, 0, 255)
39
+ thickness: int = 2
40
+ circle_radius: int = 2
41
+
42
 
43
  # Load hand drawing config from config.yaml
44
  def load_hand_drawing_config():
src/mediapipe_pose/utils.py CHANGED
@@ -3,15 +3,26 @@ try:
3
  from mediapipe.framework.formats import landmark_pb2
4
  except ImportError:
5
  # Fallback for environments where mediapipe.framework is not available
6
- import mediapipe as mp
7
- landmark_pb2 = mp.solutions.hands.HandLandmark.__class__.__module__
8
- # Use mp.solutions protobuf types instead
9
- from google.protobuf import descriptor_pb2
10
- class _LandmarkListProxy:
 
 
 
 
 
 
 
 
11
  """Proxy class that wraps mediapipe landmark data."""
12
  def __init__(self, landmarks=None):
13
  self.landmark = landmarks if landmarks else []
14
- landmark_pb2 = type('landmark_pb2', (), {'NormalizedLandmarkList': _LandmarkListProxy})()
 
 
 
15
 
16
  try:
17
  from mediapipe.python.solutions.drawing_utils import (
 
3
  from mediapipe.framework.formats import landmark_pb2
4
  except ImportError:
5
  # Fallback for environments where mediapipe.framework is not available
6
+ class _Landmark:
7
+ """Proxy class that wraps a single landmark."""
8
+ def __init__(self, x=0, y=0, z=0, visibility=1.0, presence=1.0):
9
+ self.x = x
10
+ self.y = y
11
+ self.z = z
12
+ self.visibility = visibility
13
+ self.presence = presence
14
+
15
+ def HasField(self, field_name):
16
+ return hasattr(self, field_name)
17
+
18
+ class _NormalizedLandmarkList:
19
  """Proxy class that wraps mediapipe landmark data."""
20
  def __init__(self, landmarks=None):
21
  self.landmark = landmarks if landmarks else []
22
+
23
+ class landmark_pb2:
24
+ NormalizedLandmarkList = _NormalizedLandmarkList
25
+ NormalizedLandmark = _Landmark
26
 
27
  try:
28
  from mediapipe.python.solutions.drawing_utils import (
src/utils.py CHANGED
@@ -1,4 +1,3 @@
1
- import mediapipe as mp
2
  import os
3
  from moviepy import ImageSequenceClip
4
  from natsort import natsorted
@@ -20,6 +19,24 @@ from transformers import (
20
  )
21
  from src.body_pose.vertex_annotator_heart import VertexAnnotatorHeart
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  def create_video_from_images(folder_path, output_video_file, fps):
25
  """
@@ -67,7 +84,8 @@ def create_video_from_images(folder_path, output_video_file, fps):
67
 
68
 
69
  def process_hand_pose_estimation(path_video, output_folder, drawing_settings):
70
- mp_hands = mp.solutions.hands
 
71
 
72
  landmark_annotations = get_default_hand_landmark_style(drawing_settings.get("color_landmarks"), drawing_settings.get("radius"))
73
  connections_annotations = get_default_hand_connection_style(drawing_settings.get("color_connections"), drawing_settings.get("thickness"))
@@ -98,7 +116,7 @@ def process_hand_pose_estimation(path_video, output_folder, drawing_settings):
98
  draw_landmarks(
99
  frame,
100
  lm,
101
- mp_hands.HAND_CONNECTIONS,
102
  landmark_drawing_spec=landmark_annotations,
103
  connection_drawing_spec=connections_annotations,
104
  )
 
 
1
  import os
2
  from moviepy import ImageSequenceClip
3
  from natsort import natsorted
 
19
  )
20
  from src.body_pose.vertex_annotator_heart import VertexAnnotatorHeart
21
 
22
+ # Import mediapipe with fallback
23
+ try:
24
+ import mediapipe as mp
25
+ mp_hands = mp.solutions.hands
26
+ HAND_CONNECTIONS = mp_hands.HAND_CONNECTIONS
27
+ except (ImportError, AttributeError):
28
+ # Fallback for newer mediapipe versions without solutions module
29
+ mp_hands = None
30
+ # Define hand connections manually
31
+ HAND_CONNECTIONS = frozenset([
32
+ (0, 1), (1, 2), (2, 3), (3, 4), # Thumb
33
+ (0, 5), (5, 6), (6, 7), (7, 8), # Index
34
+ (0, 9), (9, 10), (10, 11), (11, 12), # Middle
35
+ (0, 13), (13, 14), (14, 15), (15, 16), # Ring
36
+ (0, 17), (17, 18), (18, 19), (19, 20), # Pinky
37
+ (5, 9), (9, 13), (13, 17), # Palm
38
+ ])
39
+
40
 
41
  def create_video_from_images(folder_path, output_video_file, fps):
42
  """
 
84
 
85
 
86
  def process_hand_pose_estimation(path_video, output_folder, drawing_settings):
87
+ if mp_hands is None:
88
+ raise RuntimeError("Hand pose estimation requires mediapipe with solutions module. Please install mediapipe<0.10.8")
89
 
90
  landmark_annotations = get_default_hand_landmark_style(drawing_settings.get("color_landmarks"), drawing_settings.get("radius"))
91
  connections_annotations = get_default_hand_connection_style(drawing_settings.get("color_connections"), drawing_settings.get("thickness"))
 
116
  draw_landmarks(
117
  frame,
118
  lm,
119
+ HAND_CONNECTIONS,
120
  landmark_drawing_spec=landmark_annotations,
121
  connection_drawing_spec=connections_annotations,
122
  )