Welcome to DOFBOT SE repository
13.Palm Targeting
Palm Target Positioning
1. Introduction
MediaPipe is a machine learning application development framework for data stream processing, developed and open-sourced by Google. It is a graph-based data processing pipeline used to build applications that utilize various forms of data sources such as video, audio, sensor data, and any time series data.
MediaPipe is cross-platform and can run on embedded platforms (Jetson Nano, etc.), mobile devices (iOS and Android), workstations and servers, and supports mobile GPU acceleration. MediaPipe provides cross-platform, customizable ML solutions for real-time and streaming media.
The core framework of MediaPipe is implemented in C++ and provides support for Java and Objective C. The main concepts of MediaPipe include Packet, Stream, Calculator, Graph, and Subgraph.
MediaPipe features:
- End-to-end acceleration: Built-in fast ML inference and processing accelerate even on ordinary hardware.
- Build once, deploy anywhere: Unified solution works on Android, iOS, desktop/cloud, web, and IoT.
- Ready-to-use solutions: Cutting-edge ML solutions that demonstrate all the capabilities of the framework.
- Free and open source: Framework and solutions under Apache 2.0, fully extensible and customizable.
2. Startup
2.1. Program Description
After the program runs, the camera captures image frames, the program detects the palm, and prints the palm center coordinates to the terminal.

2.2. Program Startup
- Enter the following command to start the program
xxxxxxxxxxros2 run dofbot_mediapipe 13_FindHand
Press Ctrl+c in the terminal to exit the program.
2.3. Source Code
Code path:
xxxxxxxxxx/home/yahboom/dofbot_ws/src/dofbot_mediapipe/dofbot_mediapipe/13_FindHand.py
x#!/usr/bin/env python3# encoding: utf-8import threadingimport numpy as npimport timeimport osimport sysimport cv2 as cvfrom dofbot_utils.robot_controller import Robot_Controllerfrom dofbot_utils.fps import FPSimport rclpyfrom rclpy.node import Nodefrom sensor_msgs.msg import Imagefrom std_msgs.msg import Boolfrom geometry_msgs.msg import Twistfrom cv_bridge import CvBridgesys.path.append('/home/yahboom/dofbot_ws/src/dofbot_mediapipe/dofbot_mediapipe')from media_library import *class HandCtrlArmNode(Node): def __init__(self): super().__init__('hand_ctrl_arm_node') self.hand_detector = HandDetector() self.arm_status = True self.locking = True self.init = True self.pTime = 0 self.add_lock = self.remove_lock = 0 self.event = threading.Event() self.event.set() self.robot = Robot_Controller() self.robot.move_init_pose() self.bridge = CvBridge() self.publisher_ = self.create_publisher(Image, 'processed_image', 10) self.capture = cv.VideoCapture(0, cv.CAP_V4L2) self.capture.set(cv.CAP_PROP_FRAME_WIDTH, 640) self.capture.set(cv.CAP_PROP_FRAME_HEIGHT, 480) self.get_logger().info(f"Camera FPS: {self.capture.get(cv.CAP_PROP_FPS)}") self.timer = self.create_timer(0.1, self.timer_callback) def process(self, frame): frame, lmList, bbox = self.hand_detector.findHands(frame) if len(lmList) != 0: threading.Thread(target=self.find_hand_threading, args=(lmList, bbox)).start() return frame def find_hand_threading(self, lmList, bbox): fingers = self.hand_detector.fingersUp(lmList) angle = self.hand_detector.ThumbTOforefinger(lmList) value = np.interp(angle, [0, 70], [185, 20]) indexX = (bbox[0] + bbox[2]) / 2 indexY = (bbox[1] + bbox[3]) / 2 print("index X: %.1f, Y: %.1f" % (indexX, indexY)) def timer_callback(self): ret, frame = self.capture.read() if ret: frame = self.process(frame) processed_image_msg = self.bridge.cv2_to_imgmsg(frame, "bgr8") self.publisher_.publish(processed_image_msg) cv.imshow('frame', frame) if cv.waitKey(1) & 0xFF == ord('q'): self.capture.release() cv.destroyAllWindows() rclpy.shutdown()def main(args=None): rclpy.init(args=args) hand_ctrl_arm_node = HandCtrlArmNode() rclpy.spin(hand_ctrl_arm_node) hand_ctrl_arm_node.destroy_node() rclpy.shutdown()if __name__ == '__main__': main()