hand-tracking-teleop 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of hand-tracking-teleop might be problematic. Click here for more details.

Files changed (27) hide show
  1. hand_tracking_teleop-0.1.0/MANIFEST.in +18 -0
  2. hand_tracking_teleop-0.1.0/PKG-INFO +436 -0
  3. hand_tracking_teleop-0.1.0/README.md +393 -0
  4. hand_tracking_teleop-0.1.0/build_and_publish.sh +250 -0
  5. hand_tracking_teleop-0.1.0/config/calibrated_config.yaml +27 -0
  6. hand_tracking_teleop-0.1.0/config/hand_tracking_config.yaml +40 -0
  7. hand_tracking_teleop-0.1.0/config/robot_mapping_config.yaml +107 -0
  8. hand_tracking_teleop-0.1.0/example_usage.py +69 -0
  9. hand_tracking_teleop-0.1.0/pyproject.toml +77 -0
  10. hand_tracking_teleop-0.1.0/requirements.txt +37 -0
  11. hand_tracking_teleop-0.1.0/setup.cfg +4 -0
  12. hand_tracking_teleop-0.1.0/setup.py +68 -0
  13. hand_tracking_teleop-0.1.0/src/hand_tracking/__init__.py +17 -0
  14. hand_tracking_teleop-0.1.0/src/hand_tracking/cli.py +279 -0
  15. hand_tracking_teleop-0.1.0/src/hand_tracking/hand_detector.py +475 -0
  16. hand_tracking_teleop-0.1.0/src/hand_tracking/visualizer_3d.py +214 -0
  17. hand_tracking_teleop-0.1.0/src/hand_tracking/visualizer_combined.py +221 -0
  18. hand_tracking_teleop-0.1.0/src/hand_tracking/visualizer_rerun.py +255 -0
  19. hand_tracking_teleop-0.1.0/src/hand_tracking_teleop.egg-info/PKG-INFO +436 -0
  20. hand_tracking_teleop-0.1.0/src/hand_tracking_teleop.egg-info/SOURCES.txt +25 -0
  21. hand_tracking_teleop-0.1.0/src/hand_tracking_teleop.egg-info/dependency_links.txt +1 -0
  22. hand_tracking_teleop-0.1.0/src/hand_tracking_teleop.egg-info/entry_points.txt +6 -0
  23. hand_tracking_teleop-0.1.0/src/hand_tracking_teleop.egg-info/requires.txt +18 -0
  24. hand_tracking_teleop-0.1.0/src/hand_tracking_teleop.egg-info/top_level.txt +4 -0
  25. hand_tracking_teleop-0.1.0/src/mapping/__init__.py +12 -0
  26. hand_tracking_teleop-0.1.0/src/mapping/kinematic_mapper.py +405 -0
  27. hand_tracking_teleop-0.1.0/src/robot_interface/dual_interface.py +780 -0
@@ -0,0 +1,18 @@
1
+ # Include documentation files
2
+ include README.md
3
+ include LICENSE
4
+ include requirements.txt
5
+
6
+ # Include configuration files
7
+ recursive-include config *.yaml
8
+
9
+ # Exclude development and build files
10
+ global-exclude *.pyc
11
+ global-exclude *.pyo
12
+ global-exclude __pycache__
13
+ global-exclude .git*
14
+ global-exclude .DS_Store
15
+ prune scripts
16
+ prune tests
17
+ prune .vscode
18
+ prune .idea
@@ -0,0 +1,436 @@
1
+ Metadata-Version: 2.4
2
+ Name: hand_tracking_teleop
3
+ Version: 0.1.0
4
+ Summary: Hand tracking system for robot teleoperation using MediaPipe
5
+ Home-page: https://github.com/yourusername/hand_tracking_teleop
6
+ Author: Bruk Gebregziabher
7
+ Author-email: Bruk Gebregziabher <bruk@signalbotics.com>
8
+ License: MIT
9
+ Project-URL: Homepage, https://github.com/yourusername/hand_tracking_teleop
10
+ Project-URL: Documentation, https://github.com/yourusername/hand_tracking_teleop#readme
11
+ Project-URL: Repository, https://github.com/yourusername/hand_tracking_teleop
12
+ Project-URL: Bug Tracker, https://github.com/yourusername/hand_tracking_teleop/issues
13
+ Keywords: hand-tracking,teleoperation,robotics,mediapipe,computer-vision
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Requires-Python: >=3.8
24
+ Description-Content-Type: text/markdown
25
+ Requires-Dist: opencv-python>=4.5.0
26
+ Requires-Dist: mediapipe>=0.10.0
27
+ Requires-Dist: numpy>=1.20.0
28
+ Requires-Dist: pyyaml>=6.0
29
+ Provides-Extra: vis
30
+ Requires-Dist: matplotlib>=3.5.0; extra == "vis"
31
+ Provides-Extra: rerun
32
+ Requires-Dist: rerun-sdk>=0.18.0; extra == "rerun"
33
+ Provides-Extra: dev
34
+ Requires-Dist: pytest>=7.0; extra == "dev"
35
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
36
+ Requires-Dist: black>=23.0; extra == "dev"
37
+ Requires-Dist: flake8>=6.0; extra == "dev"
38
+ Requires-Dist: mypy>=1.0; extra == "dev"
39
+ Requires-Dist: isort>=5.0; extra == "dev"
40
+ Dynamic: author
41
+ Dynamic: home-page
42
+ Dynamic: requires-python
43
+
44
+ # Hand Tracking Data Collector
45
+
46
+ A real-time hand tracking system for collecting training data for the dual-arm robot using MediaPipe and Gazebo simulation.
47
+
48
+ ## Overview
49
+
50
+ This system enables intuitive data collection by tracking human hand movements and mapping them to robot joint configurations. The operator demonstrates tasks by moving their hands while the system records synchronized data from:
51
+
52
+ - Hand landmark detection (21 points per hand)
53
+ - Robot joint states from Gazebo simulation
54
+ - Robot camera feeds (4 cameras)
55
+ - Timestamps for synchronization
56
+
57
+ ## Quick Start
58
+
59
+ ### 1. Installation
60
+
61
+ ```bash
62
+ # Navigate to the hand tracking collector directory
63
+ cd examples/dual_arm/hand_tracking_collector/
64
+
65
+ # Install dependencies
66
+ pip install -r requirements.txt
67
+ ```
68
+
69
+ ### 2. Test Hand Tracking (Phase 1)
70
+
71
+ ```bash
72
+ # Run the interactive test script (choose visualization mode)
73
+ python scripts/test_hand_tracking.py
74
+ ```
75
+
76
+ **Options:**
77
+ 1. 2D hand tracking (OpenCV window) - Classic view
78
+ 2. **3D hand tracking (matplotlib) - Shows coordinate axes at key landmarks**
79
+ 3. **Combined 2D + 3D view - Best for full overview**
80
+ 4. Quick detection test (no display)
81
+
82
+ **Or use directly in Python:**
83
+ ```python
84
+ from hand_tracking.hand_detector import HandDetector
85
+
86
+ detector = HandDetector()
87
+
88
+ # Choose mode: '2d', '3d', or 'combined'
89
+ detector.run_interactive(mode='3d') # 3D visualization with axes
90
+ ```
91
+
92
+ ### 3. 3D Visualization
93
+
94
+ Visualize hand landmarks in interactive 3D space using matplotlib:
95
+
96
+ ```bash
97
+ # Combined 2D + 3D view (Recommended)
98
+ python scripts/visualize_hand_combined.py
99
+
100
+ # 3D only - dual hand plots
101
+ python scripts/visualize_hand_3d.py
102
+
103
+ # Snapshot mode - capture single frame
104
+ python scripts/visualize_hand_3d_simple.py
105
+
106
+ # Test system
107
+ python scripts/test_visualization.py
108
+ ```
109
+
110
+ **Features:**
111
+ - **Coordinate axes at key landmarks** (wrist + fingertips): X=red, Y=green, Z=blue
112
+ - Color-coded finger bones: 🔴 Thumb | 🔵 Index | 💙 Middle | 💚 Ring | 💛 Pinky
113
+ - Interactive controls: Click+drag to rotate, scroll to zoom, right-click to pan
114
+ - Real-time tracking at ~30 FPS
115
+ - Hand confidence scores and statistics
116
+
117
+ **Tips for best tracking:**
118
+ - Good, even lighting (avoid backlighting)
119
+ - Plain background
120
+ - Keep hands 1-2 feet from camera
121
+ - All fingers visible
122
+
123
+ ### 4. Controls
124
+
125
+ - **'q'**: Quit hand tracking (2D view)
126
+ - **Close window**: Exit visualization
127
+ - **Mouse drag**: Rotate 3D view
128
+ - **Scroll wheel**: Zoom in/out
129
+ - **Right-click drag**: Pan view
130
+ - **Gestures**: (Future phases will support gesture controls)
131
+
132
+ ## Current Status: Phase 1 Complete ✅
133
+
134
+ **Phase 1: Basic Hand Tracking**
135
+ - [x] MediaPipe hand detection setup
136
+ - [x] Real-time landmark extraction (21 points per hand)
137
+ - [x] Hand confidence and bounding box calculation
138
+ - [x] Temporal smoothing for stable tracking
139
+ - [x] Interactive 2D visualization
140
+ - [x] Interactive 3D visualization with matplotlib
141
+ - [x] Configuration system
142
+
143
+ ## System Architecture
144
+
145
+ ```
146
+ Human Hands → Camera → MediaPipe → Hand Landmarks
147
+
148
+ Future: Robot Control ← Joint Mapping ← Hand Poses
149
+
150
+ Future: Data Collection ← Gazebo Robot ← Joint Commands
151
+ ```
152
+
153
+ ## Mathematical Framework
154
+
155
+ ### Camera-to-Robot Coordinate Mapping
156
+
157
+ The system assumes a **top-view camera** looking down at the hands. The coordinate transformation from camera space to robot workspace is:
158
+
159
+ **Camera Coordinate System:**
160
+ - X_cam: Left-to-right in camera image (0 to 640 pixels)
161
+ - Y_cam: Top-to-bottom in camera image (0 to 480 pixels)
162
+ - Z_cam: Depth from camera (MediaPipe estimated depth)
163
+
164
+ **Robot Coordinate System (TorsoLink frame):**
165
+ - X_robot: Forward/backward relative to robot torso (+X = forward)
166
+ - Y_robot: Left/right relative to robot torso (+Y = left)
167
+ - Z_robot: Up/down relative to robot torso (+Z = up)
168
+
169
+ **Coordinate Transformation:**
170
+ ```
171
+ Δy_robot = -(X_cam/640 - 0.5) × 0.3 [±15cm left/right, inverted]
172
+ Δx_robot = -(Y_cam/480 - 0.5) × 0.2 [±10cm forward/back, inverted]
173
+ Δz_robot = -Z_cam × 0.2 [0-20cm up/down, inverted]
174
+
175
+ P_target = P_current + [Δx_robot, Δy_robot, Δz_robot]
176
+ ```
177
+
178
+ **Coordinate System Mapping (with ROS conventions):**
179
+ - Camera X (left-right in image) → Robot -Y (right in image = robot moves right = -Y)
180
+ - Camera Y (top-bottom in image) → Robot -X (down in image = robot moves back = -X)
181
+ - Camera Z (depth from camera) → Robot -Z (closer to camera = robot moves down = -Z)
182
+
183
+ Where:
184
+ - P_current = Current robot hand position from forward kinematics
185
+ - P_target = Target robot hand position for inverse kinematics
186
+
187
+ ### Hand Landmark Processing
188
+
189
+ MediaPipe provides 21 landmarks per hand in normalized coordinates [0,1]. The wrist landmark (index 0) is used for position tracking:
190
+
191
+ ```
192
+ P_hand = MediaPipe_landmarks[0] × [640, 480, depth_scale]
193
+ ```
194
+
195
+ ### Finger Joint Mapping
196
+
197
+ The system uses kinematic mapping to convert hand landmarks into robot joint commands. Here are the detailed equations for each controller:
198
+
199
+ ### Finger Mapping (Per Hand Controller)
200
+
201
+ Each hand has 6 DOF mapped from MediaPipe hand landmarks:
202
+
203
+ #### Left Hand Controller: `left_hand_controller`
204
+ - `left_thumb_finger_proximal_pitch` (Joint 15)
205
+ - `left_thumb_finger_proximal_yaw` (Joint 16)
206
+ - `left_index_finger_proximal` (Joint 17)
207
+ - `left_middle_finger_proximal` (Joint 18)
208
+ - `left_ring_finger_proximal` (Joint 19)
209
+ - `left_pinky_finger_proximal` (Joint 20)
210
+
211
+ #### Right Hand Controller: `right_hand_controller`
212
+ - `right_thumb_finger_proximal_pitch` (Joint 21)
213
+ - `right_thumb_finger_proximal_yaw` (Joint 22)
214
+ - `right_index_finger_proximal` (Joint 23)
215
+ - `right_middle_finger_proximal` (Joint 24)
216
+ - `right_ring_finger_proximal` (Joint 25)
217
+ - `right_pinky_finger_proximal` (Joint 26)
218
+
219
+ ### Finger Curl Calculation
220
+
221
+ The core finger mapping uses a "curl ratio" calculation based on triangle inequality:
222
+
223
+ **Distance Calculations:**
224
+ - d₁ = ||P_mcp - P_wrist||₂ (wrist to MCP joint)
225
+ - d₂ = ||P_tip - P_mcp||₂ (MCP joint to fingertip)
226
+ - d₃ = ||P_tip - P_wrist||₂ (wrist to fingertip direct)
227
+
228
+ **Expected vs Actual Distance:**
229
+ - d_expected = d₁ + d₂ (if finger was straight)
230
+ - curl_ratio = 1 - (d₃ / d_expected)
231
+
232
+ **Sensitivity Enhancement:**
233
+ - curl_final = (curl_ratio)^0.7
234
+ - Result clamped to [0, 1] where 0 = straight, 1 = fully curled
235
+
236
+ ### Joint Angle Mapping
237
+
238
+ Each finger type uses different scaling factors:
239
+
240
+ #### Thumb (2 DOF):
241
+ - θ_pitch = clamp(curl_final × 3.0, 0.0, 1.5) radians
242
+ - θ_yaw = clamp(curl_final × 2.0, 0.0, 1.5) radians
243
+
244
+ #### Other Fingers (1 DOF each):
245
+ - θ_joint = clamp(curl_final × 2.5, 0.0, 1.5) radians
246
+
247
+ ### MediaPipe Landmark Indices
248
+
249
+ The system uses these specific MediaPipe hand landmarks:
250
+
251
+ - **Wrist**: Landmark 0
252
+ - **Thumb**: MCP=2, Tip=4
253
+ - **Index**: MCP=5, Tip=8
254
+ - **Middle**: MCP=9, Tip=12
255
+ - **Ring**: MCP=13, Tip=16
256
+ - **Pinky**: MCP=17, Tip=20
257
+
258
+ ### Arm/Torso Controller: `torso_controller`
259
+
260
+ The torso controller handles 15 DOF (currently disabled for safety):
261
+
262
+ #### Hand Position Calculation
263
+
264
+ The 3D hand position P_hand is derived from the wrist landmark (MediaPipe landmark 0):
265
+
266
+ **Image to World Coordinate Transform:**
267
+ - x_norm = (landmark₀.x / 640) - 0.5 (normalize to [-0.5, 0.5])
268
+ - y_norm = (landmark₀.y / 480) - 0.5 (normalize to [-0.5, 0.5])
269
+ - z_norm = landmark₀.z (MediaPipe depth estimate)
270
+
271
+ **Workspace Scaling:**
272
+ - P_hand.x = 2.0 × x_norm × (x_max - x_min) / 2
273
+ - P_hand.y = 2.0 × y_norm × (y_max - y_min) / 2
274
+ - P_hand.z = z_norm × (z_max - z_min) / 2 + z_min
275
+
276
+ Where workspace limits: x ∈ [-0.8, 0.8], y ∈ [-0.6, 0.6], z ∈ [0.5, 1.5] meters
277
+
278
+ #### Hand Orientation Calculation
279
+
280
+ Hand orientation Ω = [roll, pitch, yaw] is calculated from palm geometry:
281
+
282
+ **Key Points:**
283
+ - P_wrist = landmark₀ (wrist)
284
+ - P_middle = landmark₉ (middle finger MCP)
285
+ - P_index = landmark₅ (index finger MCP)
286
+
287
+ **Orientation Vectors:**
288
+ - V_palm = P_middle - P_wrist
289
+ - V_finger = P_index - P_wrist
290
+
291
+ **Euler Angles:**
292
+ - roll = atan2(V_palm.y, V_palm.x)
293
+ - pitch = atan2(V_palm.z, ||V_palm.xy||₂)
294
+ - yaw = atan2(V_finger.y, V_finger.x)
295
+
296
+ #### Left Arm (7 DOF):
297
+ Based on calculated hand position P_hand = [x, y, z] and orientation Ω = [roll, pitch, yaw]:
298
+
299
+ - **Shoulder X**: θ₁ = clamp(2.0 × x, -1.5, 1.5)
300
+ - **Shoulder Z**: θ₂ = clamp(-1.5 × y, -1.0, 1.0)
301
+ - **Shoulder Y**: θ₃ = 0.5 × yaw
302
+ - **Elbow Y**: θ₄ = clamp(2.0 × (1 - ||P_hand||), -2.0, 0.0)
303
+ - **Wrist Z**: θ₅ = 0.8 × roll
304
+ - **Wrist X**: θ₆ = 0.6 × pitch
305
+ - **Wrist Y**: θ₇ = 0.4 × yaw
306
+
307
+ #### Right Arm (7 DOF):
308
+ Same equations as left arm, applied to right hand landmarks.
309
+
310
+ #### Torso (1 DOF):
311
+ - **Torso Z**: θ_torso = 0.0 (currently neutral)
312
+
313
+ ### Smoothing and Limits
314
+
315
+ The system applies temporal smoothing and joint limits:
316
+
317
+ **Exponential Moving Average (α = 0.9):**
318
+ - θ_smoothed(t) = α × θ_smoothed(t-1) + (1-α) × θ_raw(t)
319
+
320
+ **Joint Limits:**
321
+ - Finger joints: θ ∈ [0.0, 1.57] radians (0° to 90°)
322
+ - Shoulder joints: θ ∈ [-3.14, 3.14] radians (±180°)
323
+ - All joints: θ = clamp(θ, θ_min, θ_max)
324
+
325
+ ## Configuration
326
+
327
+ The system uses YAML configuration files in the `config/` directory:
328
+
329
+ - `hand_tracking_config.yaml`: Camera and MediaPipe settings
330
+ - `robot_mapping_config.yaml`: Joint mappings and kinematic parameters
331
+ - `data_collection_config.yaml`: Recording and dataset settings
332
+
333
+ ## File Structure
334
+
335
+ ```
336
+ hand_tracking_collector/
337
+ ├── README.md # This file
338
+ ├── requirements.txt # Python dependencies
339
+ ├── config/ # Configuration files
340
+ │ ├── hand_tracking_config.yaml
341
+ │ ├── robot_mapping_config.yaml
342
+ │ └── data_collection_config.yaml (future)
343
+ ├── src/ # Source code
344
+ │ ├── hand_tracking/ # Phase 1: Hand detection
345
+ │ │ ├── hand_detector.py ✅ Complete
346
+ │ │ ├── pose_estimator.py 🔄 Future
347
+ │ │ └── gesture_recognizer.py 🔄 Future
348
+ │ ├── robot_interface/ # Phase 2: Robot control
349
+ │ ├── mapping/ # Phase 3: Kinematic mapping
350
+ │ └── data_collection/ # Phase 4: Data recording
351
+ ├── scripts/ # Utility scripts
352
+ │ ├── test_hand_tracking.py ✅ Basic 2D tracking test
353
+ │ ├── test_visualization.py ✅ System check for visualization
354
+ │ ├── visualize_hand_3d.py ✅ Real-time 3D visualization
355
+ │ ├── visualize_hand_3d_simple.py ✅ Snapshot 3D visualization
356
+ │ ├── visualize_hand_combined.py ✅ Combined 2D+3D visualization
357
+ │ ├── calibrate_system.py 🔄 Future
358
+ │ ├── collect_data.py 🔄 Future
359
+ │ └── validate_dataset.py 🔄 Future
360
+ └── tests/ # Unit tests
361
+ ```
362
+
363
+ ## Hardware Requirements
364
+
365
+ - **Camera**: USB webcam (1080p recommended)
366
+ - **Computer**: CPU with decent performance (GPU recommended for real-time processing)
367
+ - **Memory**: 4GB+ RAM
368
+ - **Network**: For future Gazebo/ROS2 communication
369
+
370
+ ## Troubleshooting
371
+
372
+ ### Camera Issues
373
+ ```bash
374
+ # Check available cameras
375
+ python -c "import cv2; print([i for i in range(10) if cv2.VideoCapture(i).isOpened()])"
376
+
377
+ # Test specific camera
378
+ python -c "import cv2; cap = cv2.VideoCapture(0); print('Camera OK' if cap.isOpened() else 'Camera failed')"
379
+ ```
380
+
381
+ ### MediaPipe Issues
382
+ ```bash
383
+ # Verify MediaPipe installation
384
+ python -c "import mediapipe as mp; print('MediaPipe version:', mp.__version__)"
385
+ ```
386
+
387
+ ### Performance Issues
388
+ - Lower camera resolution in `hand_tracking_config.yaml`
389
+ - Reduce MediaPipe model complexity to 0 (lite mode)
390
+ - Close other applications using the camera
391
+
392
+ ## Next Phases
393
+
394
+ ### Phase 2: Robot Interface (Coming Next)
395
+ - ROS2 connection to Gazebo robot
396
+ - Joint command publishing
397
+ - Robot state feedback
398
+ - Camera image capture
399
+
400
+ ### Phase 3: Kinematic Mapping
401
+ - Hand-to-arm inverse kinematics
402
+ - Finger-to-gripper mapping
403
+ - User calibration system
404
+ - Safety limits and smoothing
405
+
406
+ ### Phase 4: Data Collection
407
+ - Synchronized recording
408
+ - Episode management
409
+ - LeRobot dataset format
410
+ - Data validation
411
+
412
+ ### Phase 5: Integration & Testing
413
+ - End-to-end system testing
414
+ - Performance optimization
415
+ - User interface improvements
416
+
417
+ ## Contributing
418
+
419
+ When adding new features:
420
+
421
+ 1. Follow the existing code structure
422
+ 2. Add configuration options to YAML files
423
+ 3. Include unit tests in the `tests/` directory
424
+ 4. Update this README with new functionality
425
+
426
+ ## Dependencies
427
+
428
+ - **opencv-python**: Camera capture and image processing
429
+ - **mediapipe**: Hand landmark detection
430
+ - **numpy**: Numerical operations
431
+ - **pyyaml**: Configuration file parsing
432
+ - **matplotlib**: Visualization (future phases)
433
+
434
+ ## License
435
+
436
+ This project is part of the LeRobot ecosystem and follows the same license terms.