Pose Recognition Example
Pose recognition on HuskyLens 2 reads learned and unlearned human poses, counts bodies, and returns pose IDs plus keypoint coordinates. It’s like giving the camera a digital skeleton map so projects can track noses, shoulders, knees, and named poses in real time.
1.Pose Recognition
Before You Start:
1.1 Recognize Human Pose and Output Relevant Data
Through the example program below, it's possible to recognize human poses within the HuskyLens 2 field of view and acquire pose-related data. Readable data includes: the total number of bodies detected, the total count of learned pose IDs; the ID of the human pose closest to the center of the HuskyLens 2 camera frame, and the ID of the first detected pose.
Example Program:
from unihiker import GUI
from pinpong.board import Board
from dfrobot_huskylensv2 import *
u_gui=GUI()
Board().begin()
huskylens = HuskylensV2_I2C()
huskylens.knock()
huskylens.switchAlgorithm(ALGORITHM_POSE_RECOGNITION)
line1=u_gui.draw_text(text="",x=0,y=0,font_size=15, color="#0000FF")
line2=u_gui.draw_text(text="",x=0,y=40,font_size=15, color="#0000FF")
line3=u_gui.draw_text(text="",x=0,y=80,font_size=15, color="#0000FF")
line4=u_gui.draw_text(text="",x=0,y=120,font_size=15, color="#0000FF")
while True:
huskylens.getResult(ALGORITHM_POSE_RECOGNITION)
if (huskylens.available(ALGORITHM_POSE_RECOGNITION)):
line1.config(text=(str("Body count:") + str((huskylens.getCachedResultNum(ALGORITHM_POSE_RECOGNITION)))))
line2.config(text=(str("Learned body count:") + str((huskylens.getCachedResultMaxID(ALGORITHM_POSE_RECOGNITION)))))
line3.config(text=(str("Center body ID:") + str(huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION).ID if huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION) else -1)))
line4.config(text=(str("First body ID:") + str(huskylens.getCachedResultByIndex(ALGORITHM_POSE_RECOGNITION, 1-1).ID if huskylens.getCachedResultByIndex(ALGORITHM_POSE_RECOGNITION, 1-1) else -1)))
Click 'Run' in Mind+ and wait for the program to upload.
Enter the Pose Recognition function on HuskyLens 2. Point the HuskyLens 2 camera at the human pose in the frame to learn it. For detailed instructions on how to learn poses, refer to: Pose Recognition .
Once learning is complete, aim at the pose and observe the output results on the M10 screen.
Output Result: It can output the total number of bodies detected and the total count of learned pose IDs; it can output the specified human pose ID. Learned human poses are assigned IDs in learning order, while unlearned poses have an ID of 0.
12.2 Get Data for a Specific Pose in the Frame
It can acquire keypoint data for a specific human pose, such as its ID, Name, facial features, and body joints. Detailed data includes: Human ID, Human Pose Name, X and Y coordinates of the human's center point, Width, Height, X/Y coordinates for left/right eyes, ears, and nose, and X/Y coordinates for left/right shoulders, elbows, wrists, hips, knees, and ankles. For details, please see the Pose Recognition Blocks Description.
The example program below shows how to get the X/Y coordinate data for the nose, left shoulder, elbow, hip, knee, and ankle of the human body closest to the center of the camera frame. This data can also be obtained for unlearned human poses.
from unihiker import GUI
from pinpong.board import Board
from dfrobot_huskylensv2 import *
u_gui=GUI()
Board().begin()
huskylens = HuskylensV2_I2C()
huskylens.knock()
huskylens.switchAlgorithm(ALGORITHM_POSE_RECOGNITION)
line1=u_gui.draw_text(text="",x=0,y=0,font_size=12, color="#0000FF")
line2=u_gui.draw_text(text="",x=0,y=40,font_size=12, color="#0000FF")
line3=u_gui.draw_text(text="",x=0,y=80,font_size=12, color="#0000FF")
line4=u_gui.draw_text(text="",x=0,y=120,font_size=12, color="#0000FF")
line5=u_gui.draw_text(text="",x=0,y=160,font_size=12, color="#0000FF")
line6=u_gui.draw_text(text="",x=0,y=200,font_size=12, color="#0000FF")
line7=u_gui.draw_text(text="",x=0,y=240,font_size=12, color="#0000FF")
while True:
huskylens.getResult(ALGORITHM_POSE_RECOGNITION)
if (huskylens.available(ALGORITHM_POSE_RECOGNITION)):
line1.config(text=(str("Center body ID:") + str(huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION).ID if huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION) else -1)))
line2.config(text=(str("Nose coords:") + str((str(huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION).nose_x if huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION) else -1) + str((str(",") + str(huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION).nose_y if huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION) else -1)))))))
line3.config(text=(str("Lshoulder coords:") + str((str(huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION).lshoulder_x if huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION) else -1) + str((str(",") + str(huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION).lshoulder_y if huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION) else -1)))))))
line4.config(text=(str("Rshoulder coords:") + str((str(huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION).rshoulder_x if huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION) else -1) + str((str(",") + str(huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION).rshoulder_y if huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION) else -1)))))))
line5.config(text=(str("Lelbow coords:") + str((str(huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION).lelbow_x if huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION) else -1) + str((str(",") + str(huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION).lelbow_y if huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION) else -1)))))))
line6.config(text=(str("Relbow coords") + str((str(huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION).relbow_x if huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION) else -1) + str((str(",") + str(huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION).relbow_y if huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION) else -1)))))))
line7.config(text=(str("Lknee coords:") + str((str(huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION).lknee_x if huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION) else -1) + str((str(",") + str(huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION).lknee_y if huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION) else -1)))))))
Output Result: As shown below, after running the program, the M10 (User provided K10, but document context is M10) screen displays the Human ID and the coordinate data for the nose and other key body points. Since this human pose has not been learned, the Human ID is 0.
In addition to the data above, more human pose data can be acquired. For example, determining if a pose with a specific ID is in the frame, the name of a specific pose, or the count of identical poses in the frame. When multiple identical poses appear, it's possible to specify and acquire parameters for one of them, including Name, X/Y coordinates, Width, Height, and key body point coordinate data.
Example Program:
from unihiker import GUI
from pinpong.board import Board
from dfrobot_huskylensv2 import *
u_gui=GUI()
Board().begin()
huskylens = HuskylensV2_I2C()
huskylens.knock()
huskylens.switchAlgorithm(ALGORITHM_POSE_RECOGNITION)
line1=u_gui.draw_text(text="",x=0,y=0,font_size=15, color="#0000FF")
line2=u_gui.draw_text(text="",x=0,y=40,font_size=15, color="#0000FF")
line3=u_gui.draw_text(text="",x=0,y=80,font_size=15, color="#0000FF")
line4=u_gui.draw_text(text="",x=0,y=120,font_size=15, color="#0000FF")
while True:
huskylens.getResult(ALGORITHM_POSE_RECOGNITION)
if (huskylens.available(ALGORITHM_POSE_RECOGNITION)):
line1.config(text=(str("Body ID1 count:") + str((huskylens.getCachedResultNumByID(ALGORITHM_POSE_RECOGNITION, 1)))))
line2.config(text=(str("Body ID1 name:") + str(huskylens.getCachedResultByID(ALGORITHM_POSE_RECOGNITION, 1).name if huskylens.getCachedResultByID(ALGORITHM_POSE_RECOGNITION, 1) else -1)))
line3.config(text="First bodt ID1")
line4.config(text=(str("Coords") + str((str(huskylens.getCachedIndexResultByID(ALGORITHM_POSE_RECOGNITION, 1, 1-1).xCenter if huskylens.getCachedIndexResultByID(ALGORITHM_POSE_RECOGNITION, 1, 1-1) else -1) + str((str(",") + str(huskylens.getCachedIndexResultByID(ALGORITHM_POSE_RECOGNITION, 1, 1-1).yCenter if huskylens.getCachedIndexResultByID(ALGORITHM_POSE_RECOGNITION, 1, 1-1) else -1)))))))
Output Result: As shown, it can acquire the count and name of Pose ID 1 in the frame, and the coordinate position of the first detected Pose ID 1.
Was this article helpful?
