Pose Recognition Example

Pose recognition with HuskyLens 2 reads pose IDs and joint coordinates in real time. It’s like a smart camera that tags each body as a stick figure with numbered joints, then streams total people, center pose ID, keypoints like nose, shoulders, knees and specific learned pose names to the UNIHIKER K10 display.

1. Pose Recognition Example

Before You Start:

1.1 Output Data for Human Pose Recognition

HUSKYLENS 2 can recognize human poses within its field of view and acquire related pose data. The identifiable data includes: total number of detected humans, the ID of the human pose closest to the center of the camera's field of view, and the ID of the first detected pose.

Example program is provided below:


#include "DFRobot_HuskylensV2.h"
#include "unihiker_k10.h"  // 
// Create objects (Huskylens: pose recognition; UNIHIKER K10: screen)
HuskylensV2  huskylens;
UNIHIKER_K10 k10;
uint8_t      screen_dir = 2;  // Screen display direction


// Main program initialization
void setup() {
  k10.begin();          // Initialize UNIHIKER K10 hardware
  Wire.begin();         // Initialize I2C communication for Huskylens

  // Wait for Huskylens connection (retry every 100ms until success)
  while (!huskylens.begin(Wire)) {
    delay(100);
  }

  k10.initScreen(screen_dir);       // Initialize screen with set direction
  k10.creatCanvas();                // Create canvas for screen display
  huskylens.switchAlgorithm(ALGORITHM_POSE_RECOGNITION);  // Set to pose recognition mode
}

void loop() {
  huskylens.getResult(ALGORITHM_POSE_RECOGNITION);  // Fetch latest pose recognition data

  if (huskylens.available(ALGORITHM_POSE_RECOGNITION)) {
    // Simplify index: 1-1 → 0 (more intuitive, same meaning)
    k10.canvas->canvasText(String("Total poses: ") + String(huskylens.getCachedResultNum(ALGORITHM_POSE_RECOGNITION)), 1, 0xFF0000);
    k10.canvas->canvasText(String("Center pose ID: ") + String(RET_ITEM_NUM(huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION), Result, ID)), 3, 0xFF0000);
    k10.canvas->canvasText(String("First pose ID: ") + String(RET_ITEM_NUM(huskylens.getCachedResultByIndex(ALGORITHM_POSE_RECOGNITION, 0), Result, ID)), 5, 0xFF0000);
    
    k10.canvas->updateCanvas();  // Refresh screen to show latest data 
  }
}

After uploading the program, HuskyLens 2 will enter the Pose Recognition function. Align the camera of HuskyLens 2 with the human pose in the image and learn it. For detailed steps on learning a pose, please refer to: Pose Recognition - Learning a Pose:Pose Recognition.

Once learning completes, point the camera at the pose, and you can view the output results on the UNIHIKER K10 screen.

Running Result:The total number of detected humans and the ID number of a specified human pose can be output. The learned human poses will be assigned IDs in the order of learning, and unlearned poses will have an ID number of 0.

Interface Diagram

1.2 Acquire Human Key Point Data

Pose Recognition feature can obtain data on key points such as the ID, name, facial features, and body joints of a specified human posture. Detailed data includes: human ID, posture name, center point coordinates (X/Y), width, height, X/Y coordinates of eyes, ears, nose on both sides, and X/Y coordinates of shoulder, elbow, wrist, hip, knee, and ankle joints on both sides. For detailed information, please refer to the Pose Recognition block instructions.

The following example program can obtain the X/Y coordinates of the nose, left shoulder, elbow, hip, knee, and ankle of a human body close to the center of the camera screen. Unlearned human postures can also be recognized and data obtained.

#include "unihiker_k10.h"
#include "DFRobot_HuskylensV2.h"
// Create objects (Huskylens: pose recognition; UNIHIKER K10: screen)
HuskylensV2  huskylens;
UNIHIKER_K10 k10;
uint8_t      screen_dir = 2;  // Screen display direction


// Main program initialization
void setup() {
  k10.begin();          // Initialize UNIHIKER K10
  Wire.begin();         // Initialize I2C communication

  // Wait for Huskylens connection (retry every 100ms)
  while (!huskylens.begin(Wire)) {
    delay(100);
  }

  k10.initScreen(screen_dir);       // Init screen with set direction
  k10.creatCanvas();                // Create drawing canvas
  huskylens.switchAlgorithm(ALGORITHM_POSE_RECOGNITION);  // Set to pose recognition mode
}

void loop() {
  huskylens.getResult(ALGORITHM_POSE_RECOGNITION);  // Get latest pose recognition data

  if (huskylens.available(ALGORITHM_POSE_RECOGNITION)) {
    // Store center pose data to simplify repeated calls (improve efficiency)
    auto centerPose = huskylens.getCachedCenterResult(ALGORITHM_POSE_RECOGNITION);
    
    // Display pose info (red color: 0xFF0000)
    k10.canvas->canvasText(String("Center pose ID: ") + String(RET_ITEM_NUM(centerPose, Result, ID)), 1, 0xFF0000);
    k10.canvas->canvasText(String("Nose: ") + String(RET_ITEM_NUM(centerPose, PoseResult, nose_x)) + String(",") + String(RET_ITEM_NUM(centerPose, PoseResult, nose_y)), 3, 0xFF0000);
    k10.canvas->canvasText(String("L Shoulder: ") + String(RET_ITEM_NUM(centerPose, PoseResult, lshoulder_x)) + String(",") + String(RET_ITEM_NUM(centerPose, PoseResult, lshoulder_y)), 5, 0xFF0000);
    k10.canvas->canvasText(String("L Elbow: ") + String(RET_ITEM_NUM(centerPose, PoseResult, lelbow_x)) + String(",") + String(RET_ITEM_NUM(centerPose, PoseResult, lelbow_y)), 7, 0xFF0000);
    k10.canvas->canvasText(String("L Hip: ") + String(RET_ITEM_NUM(centerPose, PoseResult, lhip_x)) + String(",") + String(RET_ITEM_NUM(centerPose, PoseResult, lhip_y)), 9, 0xFF0000);
    k10.canvas->canvasText(String("L Knee: ") + String(RET_ITEM_NUM(centerPose, PoseResult, lknee_x)) + String(",") + String(RET_ITEM_NUM(centerPose, PoseResult, lknee_y)), 11, 0xFF0000);
    k10.canvas->canvasText(String("L Ankle: ") + String(RET_ITEM_NUM(centerPose, PoseResult, lankle_x)) + String(",") + String(RET_ITEM_NUM(centerPose, PoseResult, lankle_y)), 13, 0xFF0000);
    
    k10.canvas->updateCanvas();  // Refresh screen to show latest data
  }
}

Running Result:As shown in the following figure, running the program causes the K10 screen to display the human body ID number and the coordinates of the human's nose and some body key points.

Interface Diagram

1.3 Obtaining Specified Pose Data

In addition to the above data, more human pose information can be retrieved. For instance, you can determine if a specified ID pose is present in the frame, get the name of the specified pose, and count the number of identical poses in the画面. When multiple instances of the same pose appear, you can specify to obtain the parameters of one of them, including its name, X/Y coordinates, width, height, and human body key point coordinate data.

Example program as follows:

#include "unihiker_k10.h"
#include "DFRobot_HuskylensV2.h"
// Create objects (Huskylens: pose recognition; UNIHIKER K10: screen)
HuskylensV2  huskylens;
UNIHIKER_K10 k10;
uint8_t      screen_dir = 2;  // Screen display direction


// Main program initialization
void setup() {
  k10.begin();          // Initialize UNIHIKER K10
  Wire.begin();         // Initialize I2C communication

  // Wait for Huskylens connection (retry every 100ms)
  while (!huskylens.begin(Wire)) {
    delay(100);
  }

  k10.initScreen(screen_dir);       // Init screen with set direction
  k10.creatCanvas();                // Create drawing canvas
  huskylens.switchAlgorithm(ALGORITHM_POSE_RECOGNITION);  // Set to pose recognition mode
}

void loop() {
  huskylens.getResult(ALGORITHM_POSE_RECOGNITION);  // Get latest pose recognition data

  if (huskylens.available(ALGORITHM_POSE_RECOGNITION)) {
    // Check if ID1 pose exists and display its info
    if (huskylens.getCachedResultByID(ALGORITHM_POSE_RECOGNITION, 1) != NULL) {
      // Simplify index: 1-1 → 0 (more intuitive, same meaning)
      k10.canvas->canvasText(String("ID1 pose count: ") + String(huskylens.getCachedResultNumByID(ALGORITHM_POSE_RECOGNITION, 1)), 1, 0xFF0000);
      k10.canvas->canvasText(String("ID1 pose name: "), 3, 0xFF0000);
      k10.canvas->canvasText(String(RET_ITEM_STR(huskylens.getCachedResultByID(ALGORITHM_POSE_RECOGNITION, 1), Result, name)), 4, 0xFF0000);
      k10.canvas->canvasText("First ID1 pose", 5, 0xFF0000);
      k10.canvas->canvasText(String("Coords: ") + String(RET_ITEM_NUM(huskylens.getCachedIndexResultByID(ALGORITHM_POSE_RECOGNITION, 1, 0), Result, xCenter)) + String(",") + String(RET_ITEM_NUM(huskylens.getCachedIndexResultByID(ALGORITHM_POSE_RECOGNITION, 1, 0), Result, yCenter)), 6, 0xFF0000);
      
      k10.canvas->updateCanvas();  // Refresh screen to show latest data
    }
  }
}

Running Result:As shown in the figure, the number and name of ID1 posture in the image, as well as the coordinate position of the first detected ID1 posture, can be obtained.

Interface Diagram

Was this article helpful?

TOP