Welcome to ROSMASTER M3 repository
03.Overall Detection
Overall Detection
1. Course Content
- Run example programs, use the mediapipe framework to detect the overall body, including face, hands, and torso.
2. Program Startup
For Raspberry Pi 5 users, if the ROS container is not started, you need to start the container first,
xxxxxxxxxxbringup_m3Open a terminal inside the container,
xxxxxxxxxxexec_m3- Start the example program
xxxxxxxxxxros2 launch m3_bringup mediapipe_demo.launch.py demo:=Holistic- After the program runs, as shown in the figure below, the detected overall points will be displayed on the right side of the image

3. Source Code Analysis
- Program code path:
xxxxxxxxxx~/yahboomM3_ws/code_ws/src/m3_common_demo/m3_common_demo/mediapipe/03_Holistic.py
- Import the required library files,
xxxxxxxxxximport rclpyfrom rclpy.node import Nodefrom geometry_msgs.msg import Pointimport 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 cv2print("import done")Initialize data and define publishers and subscribers,
xxxxxxxxxx def __init__(self, name,staticMode=False, landmarks=True, detectionCon=0.5, trackingCon=0.5): super().__init__(name) #Parameter declaration and acquisition self.declare_parameter('rgb_topic','/ascamera_hp60c/camera_publisher/rgb0/image') rgb_topic=self.get_parameter("rgb_topic").get_parameter_value().string_value self.mpHolistic = mp.solutions.holistic self.mpFaceMesh = mp.solutions.face_mesh self.mpHands = mp.solutions.hands self.mpPose = mp.solutions.pose self.mpDraw = mp.solutions.drawing_utils self.mpholistic = self.mpHolistic.Holistic( static_image_mode=staticMode, smooth_landmarks=landmarks, min_detection_confidence=detectionCon, min_tracking_confidence=trackingCon) self.lmDrawSpec = mp.solutions.drawing_utils.DrawingSpec(color=(0, 0, 255), thickness=-1, circle_radius=3) self.drawSpec = mp.solutions.drawing_utils.DrawingSpec(color=(0, 255, 0), thickness=2, circle_radius=2) #create a publisher self.rgb_bridge = CvBridge()Color image callback function,
xxxxxxxxxxdef get_RGBImageCallBack(self,msg): #Use CvBridge to convert color image message data to image data rgb_image = self.rgb_bridge.imgmsg_to_cv2(msg, "bgr8") #Pass the obtained image to the defined findHolistic function, draw=False means not drawing joint points on the original color image