Pose Recognition Example
Pose recognition reads pose IDs, names and coordinates via serial, like a smart camera tagging each body in view, counting people and tracking poses; it’s like a teacher calling roll by position and name
1.Pose Recognition Code Example
Before You Start:
1.1 Recognize Human Body and Output Relevant Data
HUSKYLENS 2 can recognize human bodies within its field of view and print the relevant data through the serial port. The readable data includes: the posture ID of the human body near the center of the HUSKYLENS 2 camera screen, name, width, height, and center X and Y coordinates, the total number of detected humans, and the relevant data of the first detected posture, etc.
Sample program as follows.
#include "DFRobot_HuskylensV2.h"
// Create object
HuskylensV2 huskylens;
// Main program starts
void setup() {
Serial.begin(9600);
Wire.begin();
while (!huskylens.begin(Wire)) {
delay(100);
}
huskylens.switchAlgorithm(ALGORITHM_POSE_RECOGNITION);
}
void loop() {
huskylens.getResult(ALGORITHM_POSE_RECOGNITION);
if ((huskylens.available(ALGORITHM_POSE_RECOGNITION))) {
Serial.println((String("Total number of detected human bodies: ") + String((huskylens.getCachedResultNum(ALGORITHM_POSE_RECOGNITION)))));
Serial.println((String("ID of the human body near the center: ") + String((RET_ITEM_NUM(huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION), Result, ID)))));
Serial.println((String("Name of the human body near the center: ") + String((RET_ITEM_STR(huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION), Result, name)))));
Serial.println((String("ID of the 1st detected human body: ") + String((RET_ITEM_NUM(huskylens.getCachedResultByIndex(ALGORITHM_POSE_RECOGNITION, 1-1), Result, ID)))));
}
delay(500);
}
After the program is successfully uploaded, the HUSKYLENS 2 enters the Pose Recognition function. Align the camera of HUSKYLENS 2 with the human pose in the image for learning. For detailed steps on learning poses, please refer to: Pose Recognition
After learning is complete, open the Serial Monitor to observe the output results.
Running Result: The total number of detected humans will be output; the corresponding human pose ID will be output as required. The learned human poses will be assigned IDs in the order of learning, and unlearned ones will have an ID of 0.
1.2 Acquire Relevant Data of Specified Pose in Image
After HUSKYLENS 2 recognizes human poses, it can obtain relevant data of specified poses in the image. For example, it can determine whether a learned pose exists in the image, identify the name of the specified pose, and count the number of the same pose in the image. When multiple identical poses appear in the image, one can specify to obtain the parameters of one of them, including name, X/Y coordinates, width, and height.
Sample program as follows
#include "DFRobot_HuskylensV2.h"
// Create object
HuskylensV2 huskylens;
// Main program starts
void setup() {
Serial.begin(9600);
Wire.begin();
while (!huskylens.begin(Wire)) {
delay(100);
}
huskylens.switchAlgorithm(ALGORITHM_POSE_RECOGNITION);
}
void loop() {
huskylens.getResult(ALGORITHM_POSE_RECOGNITION);
if ((huskylens.available(ALGORITHM_POSE_RECOGNITION))) {
Serial.println((String("Total number of detected human bodies: ") + String((huskylens.getCachedResultNum(ALGORITHM_POSE_RECOGNITION)))));
Serial.println((String("ID of the human body near the center: ") + String((RET_ITEM_NUM(huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION), Result, ID)))));
Serial.println((String("Name of the human body near the center: ") + String((RET_ITEM_STR(huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION), Result, name)))));
Serial.println((String("ID of the 1st detected human body: ") + String((RET_ITEM_NUM(huskylens.getCachedResultByIndex(ALGORITHM_POSE_RECOGNITION, 1-1), Result, ID)))));
}
delay(500);
}
Running Result: As shown in the figure, you can retrieve the total number of poses, the count of ID1 poses, the names of the ID1 poses, and the coordinates of the first detected ID1 pose.
Was this article helpful?
