apirrone commited on
Commit
6bc3013
·
1 Parent(s): 60505d3
hand_tracker_app/hand_tracker.py DELETED
@@ -1,42 +0,0 @@
1
- """Hand Tracker using MediaPipe to detect hand positions in images."""
2
-
3
- import cv2
4
- import mediapipe as mp
5
- import numpy as np
6
-
7
- mp_drawing = mp.solutions.drawing_utils
8
- mp_drawing_styles = mp.solutions.drawing_styles
9
- mp_hands = mp.solutions.hands
10
-
11
-
12
- class HandTracker:
13
- """Hand Tracker using MediaPipe Hands to detect hand positions."""
14
-
15
- def __init__(self, nb_hands=1):
16
- """Initialize the Hand Tracker."""
17
- self.hands = mp_hands.Hands(
18
- static_image_mode=True, max_num_hands=nb_hands, min_detection_confidence=0.5
19
- )
20
-
21
- def get_hands_positions(self, img):
22
- """Get the positions of the hands in the image."""
23
- img = cv2.flip(img, 1)
24
-
25
- results = self.hands.process(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
26
- if results.multi_hand_landmarks is not None:
27
- palm_centers = []
28
- for landmarks in results.multi_hand_landmarks:
29
- middle_finger_pip_landmark = landmarks.landmark[
30
- mp_hands.HandLandmark.MIDDLE_FINGER_PIP
31
- ]
32
- palm_center = np.array(
33
- [middle_finger_pip_landmark.x, middle_finger_pip_landmark.y]
34
- )
35
-
36
- # Normalize the palm center to the range [-1, 1]
37
- # Flip the x-axis
38
- palm_center = [-(palm_center[0] - 0.5) * 2, (palm_center[1] - 0.5) * 2]
39
- palm_centers.append(palm_center)
40
-
41
- return palm_centers
42
- return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
hand_tracker_app/main.py CHANGED
@@ -13,7 +13,7 @@ import numpy as np
13
  from reachy_mini import ReachyMini, ReachyMiniApp
14
  from scipy.spatial.transform import Rotation as R
15
 
16
- from hand_tracker_app.hand_tracker import HandTracker
17
 
18
  gui = False # Set to True if you want to use the GUI for debugging
19
 
 
13
  from reachy_mini import ReachyMini, ReachyMiniApp
14
  from scipy.spatial.transform import Rotation as R
15
 
16
+ from reachy_mini_toolbox.vision.hand_tracker import HandTracker
17
 
18
  gui = False # Set to True if you want to use the GUI for debugging
19
 
pyproject.toml CHANGED
@@ -12,7 +12,7 @@ requires-python = ">=3.8"
12
  # dependencies = ["reachy-mini"]
13
  dependencies = [
14
  "reachy-mini",
15
- "reachy-mini-toolbox[vision]>=1.0.1"
16
  ]
17
 
18
  [project.entry-points."reachy_mini_apps"]
 
12
  # dependencies = ["reachy-mini"]
13
  dependencies = [
14
  "reachy-mini",
15
+ "reachy-mini-toolbox[vision]>=1.1.1"
16
  ]
17
 
18
  [project.entry-points."reachy_mini_apps"]