Welcome to ROSMASTER A1 repository
1.Hand detection
Hand detection
1. Content Description
This course implements the function of acquiring color images and using the MediaPipe framework to detect hand joints. This section requires entering commands in the terminal. The appropriate terminal will be selected based on the motherboard type. This section uses a Raspberry Pi 5 as an example.
For Raspberry Pi and Jetson Nano boards, you need to open a terminal on the host computer and enter the command to enter the Docker container. Once inside the Docker container, enter the commands mentioned in this section in the terminal. For instructions on entering the Docker container from the host computer, refer to [01. Robot Configuration and Operation Guide] --[5.Enter Docker (For JETSON Nano and RPi 5)].
For Orin and RDK motherboards, simply open the terminal and enter the commands mentioned in this section.
2. Program Startup
For the Raspberry Pi 5 and jetson nano controller, you must first enter the Docker container. For the Orin and RDK controller, this is not necessary.
Entering a Docker container (see [Docker Course] --- [4. Docker Startup Script] for steps).
All the following commands must be executed within the same Docker container.(See [Docker Course] --- [3. Docker Commit and Multi-Terminal Entry] for steps.)
First, in the terminal, enter the following command to start the camera.
xxxxxxxxxx#usb cameraros2 launch usb_cam camera.launch.py#nuwa cameraros2 launch ascamera hp60c.launch.pyAfter successfully starting the camera, open another terminal and enter the following command to start the hand detection program.
xxxxxxxxxxros2 run yahboomcar_mediapipe 01_HandDetectorAfter running the program, the following image appears. The detected hand joints are displayed on the right side of the image.

3. Core Code Analysis
Program Code Path:
Raspberry Pi 5 and Jetson Nano Board
The program code is running in Docker. The path in Docker is
/root/yahboomcar_ros2_ws/yahboomcar_ws/src/yahboomcar_mediapipe/yahboomcar_mediapipe/01_HandDetector.pyOrin board
The program code path is
/home/jetson/yahboomcar_ros2_ws/yahboomcar_ws/src/yahboomcar_mediapipe/yahboomcar_mediapipe/01_HandDetector.pyRDK X5 board
The program code path is
/home/sunrise/yahboomcar_ros2_ws/yahboomcar_ws/src/yahboomcar_mediapipe/yahboomcar_mediapipe/01_HandDetector.py
Import the required library files.
xxxxxxxxxximport rclpyfrom rclpy.node import Nodeimport mediapipe as mpimport cv2 as cvimport numpy as npimport timeimport osfrom cv_bridge import CvBridgefrom sensor_msgs.msg import Imagefrom arm_msgs.msg import ArmJointsimport cv2Initialize data and define publishers and subscribers,
xxxxxxxxxxdef __init__(self): super().__init__('hand_detector') self.mpHand = mp.solutions.hands self.mpDraw = mp.solutions.drawing_utils self.hands = self.mpHand.Hands( static_image_mode=False, max_num_hands=2, min_detection_confidence=0.5, min_tracking_confidence=0.5 ) self.bridge = CvBridge() self.publisher_ = self.create_publisher(PointArray, '/mediapipe/points', 10) self.lmDrawSpec = mp.solutions.drawing_utils.