Welcome to DOFBOT-JetsonNANO repository
13.Palm Targeting
Palm Targeting
1. Introduction
MediaPipe is a data stream processing machine learning application development framework developed and open-sourced by Google. It is a graph-based data processing pipeline used to build applications that use 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 languages such as Java and Objective C. The main concepts of MediaPipe include Packet, Stream, Calculator, Graph, and Subgraph.
Features of MediaPipe:
- End-to-end acceleration: Built-in fast ML inference and processing accelerates even on ordinary hardware.
- Build once, deploy anywhere: Unified solution for Android, iOS, desktop/cloud, web and IoT.
- Ready-to-use solutions: Cutting-edge ML solutions that showcase the full capabilities of the framework.
- Free and open source: Framework and solutions under Apache2.0, fully scalable and customizable.
2. Launch
2.1. Program Description
After the program runs, the camera captures image frames, the program detects the palm, and prints the palm's center coordinates to the terminal.

2.2. Program Launch
- Enter the following command to start the program
xxxxxxxxxxros2 run dofbot_mediapipe 13_FindHand
Press the q key in the image or press Ctrl+c in the terminal to exit the program.
2.3. Source Code
Code path:
x# need to enter the docker container to view~/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 CvBridgefrom dofbot_interface.msg import PointArrayfrom Arm_Lib import Arm_DeviceArm = Arm_Device()init_joints = [90.0, 150.0, 10.0, 10.0, 90.0, 0.0]Arm.Arm_serial_servo_write6_array(init_joints,2000)sys.path.append('/root/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()