A ROS 2 workspace for hand gesture recognition and camera streaming, enabling gesture-based robot control using MediaPipe and computer vision.
Robotics/
├── README.md
├── .gitignore
├── scripts/
│ └── test_cam.py # Simple webcam test script
└── ros2_ws/
└── src/
├── hand_gesture_recognition/ # Gesture recognition & robot control
│ ├── package.xml
│ ├── setup.py
│ ├── config/
│ │ └── params.yaml # ROS 2 parameters
│ ├── launch/
│ │ └── hand_gesture.launch.py
│ └── hand_gesture_recognition/
│ ├── __init__.py
│ ├── gesture_detector.py # MediaPipe hand tracking
│ └── gesture_controller.py # Velocity command mapping
│
└── my_camera_pkg/ # Camera publisher & subscriber
├── package.xml
├── setup.py
├── launch/
│ └── camera_launch.py
└── my_camera_pkg/
├── __init__.py
├── camera_pub.py # Webcam → /camera/image_raw
└── camera_sub.py # Subscriber with live display
- ROS 2 (Humble / Iron / Jazzy)
- Python 3.8+
- Webcam
sudo apt install python3-opencv python3-numpy
pip install mediapipeROS 2 packages (install via rosdep):
sudo apt install ros-<distro>-cv-bridge ros-<distro>-vision-opencvcd ros2_ws
colcon build
source install/setup.bashQuick test to verify your webcam works:
python3 scripts/test_cam.pyLaunch the ROS 2 camera pipeline:
ros2 launch my_camera_pkg camera_launch.pyOr run individually:
# Terminal 1 — publish webcam frames
ros2 run my_camera_pkg camera_pub
# Terminal 2 — view incoming frames
ros2 run my_camera_pkg camera_subRun the full gesture recognition system:
ros2 launch hand_gesture_recognition hand_gesture.launch.py| Argument | Default | Description |
|---|---|---|
use_webcam |
true |
Use webcam or ROS camera topic |
camera_id |
0 |
Webcam device ID |
linear_speed |
0.5 |
Max linear speed (m/s) |
angular_speed |
1.0 |
Max angular speed (rad/s) |
enable_controller |
true |
Enable the robot controller node |
cmd_vel_topic |
/cmd_vel |
Velocity command topic |
enable_timeout |
true |
Auto-stop robot on gesture timeout |
timeout_seconds |
1.0 |
Timeout before auto-stop |
| Gesture | Robot Command | Description |
|---|---|---|
| OPEN_PALM | Stop | Stop all motion |
| FIST | Stop | Stop all motion |
| POINT | Forward | Move forward |
| PEACE | Backward | Move backward |
| THUMBS_UP | Rotate Left | Turn counter-clockwise |
| THREE | Rotate Right | Turn clockwise |
| FOUR | Increase Speed | Speed ×1.1 (up to 2.0×) |
| ONE | Decrease Speed | Speed ×0.9 (down to 0.2×) |
Note: Speed changes persist until reset. The robot auto-stops if no gesture is received within the configured timeout.
| Topic | Type | Description |
|---|---|---|
/hand_gesture |
String |
Recognized gesture ("Left: POINT") |
/hand_count |
Int32 |
Number of extended fingers |
/hand_position |
Point |
Wrist center coordinates (pixels) |
/annotated_image |
Image |
Frame with landmarks drawn |
| Topic | Type | Description |
|---|---|---|
/cmd_vel |
Twist |
Velocity commands to robot |
| Topic | Type | Description |
|---|---|---|
/camera/image_raw |
Image |
Raw webcam frames (60fps) |
Edit ros2_ws/src/hand_gesture_recognition/config/params.yaml to adjust:
- Camera: device ID, resolution, confidence thresholds
- MediaPipe: detection/tracking confidence, max hands
- Controller: speed limits, timeout behavior
| Node | File | Role |
|---|---|---|
gesture_detector |
gesture_detector.py |
Captures frames, detects hands via MediaPipe, publishes gesture data |
gesture_controller |
gesture_controller.py |
Subscribes to gesture topics, publishes /cmd_vel Twist commands |
| Node | File | Role |
|---|---|---|
camera_pub |
camera_pub.py |
Opens webcam, publishes Image messages |
camera_sub |
camera_sub.py |
Subscribes and displays camera feed |