Welcome to MicroROS V2 Robot Car repository
9. Gesture Recognition
Gesture Recognition
1. Experiment Objective
Use MediaPipe Hands combined with custom gesture classification logic to recognize 13 predefined gestures in real time (number gestures, special gestures, etc.).
2. Experiment Principle
1. Key Terms
| Keyword | Description |
|---|---|
| 13 gesture types | Zero, One, Two, Three, Four, Five, Six, Seven, Eight, Ok, Rock, Thumb_up, Thumb_down |
| Finger-up counting | Compares the y-coordinates of the fingertip (tip) and proximal interphalangeal joint (pip) to determine whether a finger is extended, returning a 5-bit binary array |
| Thumb-index distance | The key metric distinguishing the OK gesture from number gestures; a distance under 22% of the hand scale is judged as a pinch |
| Display scaling and black-bar padding | resize_with_padding scales the frame proportionally and pads it with black bars so the content stays complete and undistorted |
| Semi-transparent status overlay | A semi-transparent black bar at the top of the frame overlays the gesture name, FPS and operation hints |
2. Technical Architecture
Terminal 1: start agent + camera + joint modelsTerminal 2: start gesture recognition
3. Experiment Steps
1. Hardware Preparation
| Hardware | Requirement |
|---|---|
| PTZ version | ✅ Supported |
| No-PTZ version | ✅ Supported |
| Required peripherals | ESP32 camera |
2. Start the agent + camera + joint models (Terminal 1)
xxxxxxxxxxros2 launch microros_v2_bringup car_base.launch.py
3. Start gesture recognition (Terminal 2)
xxxxxxxxxxros2 launch microros_v2_mediapipe_pkg mediapipe_gesture.launch.py4. Operating Instructions
- Make one of the 13 gestures at the camera; the recognized result and FPS are shown at the top of the frame
- Press
qto exit.
4. Observed Results
- Making number gestures (0-8) shows the corresponding gesture name at the top of the frame (e.g. "Five", "Ok")
- Finger extended/bent state is determined in real time through the
fingersUparray - A semi-transparent black overlay shows the gesture name, FPS and operation hints

5. Code Walkthrough
Source code paths:
- Launch:
~/microros_ws/src/microros_v2_mediapipe_pkg/launch/mediapipe_gesture.launch.py- Node:
~/microros_ws/src/microros_v2_mediapipe_pkg/microros_v2_mediapipe_pkg/mediapipe_gesture.py- Shared library:
~/microros_ws/src/microros_v2_mediapipe_pkg/microros_v2_mediapipe_pkg/media_library.py
1. Core Node Analysis
x# Source file: ~/microros_ws/src/microros_v2_mediapipe_pkg/microros_v2_mediapipe_pkg/mediapipe_gesture.pyclass MediapipeGestureNode(Node): def __init__(self): super().__init__("mediapipe_gesture_node") self.declare_parameter("rgb_topic", "/camera/image_raw") self.declare_parameter("static_image_mode", False) self.declare_parameter("max_hands", 1) self.declare_parameter("detector_con", 0.7) self.declare_parameter("track_con", 0.7) self.declare_parameter("print_gesture", False) # Use the shared library HandDetector (wraps MediaPipe Hands + finger state determination) self.hand_detector = HandDetector( static_image_mode=False, max_hands=1, detector_con=0.7, track_con=0.7) def image_callback(self, msg): frame = self.bridge.imgmsg_to_cv2(msg, 'bgr8') frame = self.hand_detector.findHands(frame) fingers_up = self.hand_detector.fingersUp() gesture = self.hand_detector.get_gesture(fingers_up) if gesture and self.print_gesture: self.get_logger().info(f'Gesture: {gesture}')Key logic:
HandDetectorcomes from the shared librarymedia_library.py, encapsulating MediaPipe Hands and the gesture recognition logicfingersUp(): compares the fingertip y and pip joint y of the 5 fingers, returning a 5-bit array (1=extended, 0=bent)get_gesture(): classifies based onfingersUp+ thumb-index distance into one of the 13 gesturesdetector_con=0.7: higher than the 0.5 used in basic hand detection, ensuring gesture recognition accuracyprint_gesture: when enabled, the recognized gesture name is printed to the ROS2 log (for debugging)
2. Key Parameters
Parameter definition files:
- Launch:
~/microros_ws/src/microros_v2_mediapipe_pkg/launch/mediapipe_gesture.launch.py- Node:
~/microros_ws/src/microros_v2_mediapipe_pkg/microros_v2_mediapipe_pkg/mediapipe_gesture.py
| Parameter | Type | Default | Description |
|---|---|---|---|
max_hands | int | 1 | Maximum number of hands to detect |
detector_con | float | 0.7 | Detection confidence threshold (higher than the base 0.5) |
track_con | float | 0.7 | Tracking confidence threshold |
print_gesture | bool | false | Whether to output the gesture name to the ROS2 log |
3. Node Description
| Node | Function |
|---|---|
mediapipe_gesture_node | MediaPipe Hands + 13-gesture classification + semi-transparent overlay display |
6. Frequently Asked Questions
| Issue | Cause | Solution |
|---|---|---|
| Gesture misrecognized | Fingers are not fully extended or bent | Make the gesture properly, with clear extended/bent finger states |
| High recognition latency | max_hands > 1 increases computation | Set max_hands:=1 |