Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Tencent Ncnn SimplePose Example

From Leeroopedia
Revision as of 16:50, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Tencent_Ncnn_SimplePose_Example.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Vision, Pose Estimation
Last Updated 2026-02-09 19:00 GMT

Overview

Concrete tool for human pose estimation using the Simple Baseline model from GluonCV with ncnn, detecting 17 body keypoints via heatmap regression.

Description

This example demonstrates top-down human pose estimation using the Simple Baseline model (originally exported from MXNet via mxnet2ncnn). It loads the pose model, resizes input to 192x256 with ImageNet normalization (mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), and extracts heatmaps from the "conv3_fwd" output layer. For each of the 17 body keypoints, it finds the maximum activation in the corresponding heatmap channel and maps it back to original image coordinates. The visualization draws both joint points (green circles) and skeleton connections (blue lines) for 16 predefined bone pairs. Keypoints with probability below 0.2 are filtered out.

Usage

Use this example for single-person pose estimation from a cropped image of a person. It is suitable for fitness tracking, gesture recognition, or action analysis applications. The model expects a pre-cropped person image; for multi-person scenarios, combine with a person detector first.

Code Reference

Source Location

Signature

static int detect_posenet(const cv::Mat& bgr, std::vector<KeyPoint>& keypoints);
static void draw_pose(const cv::Mat& bgr, const std::vector<KeyPoint>& keypoints);
int main(int argc, char** argv);

Import

#include "net.h"

I/O Contract

Inputs

Name Type Required Description
image_path const char* Yes Path to input image of a person (passed as command-line argument)
bgr const cv::Mat& Yes BGR image loaded by OpenCV, converted to RGB and resized to 192x256

Outputs

Name Type Description
keypoints std::vector<KeyPoint> 17 detected body keypoints, each with a cv::Point2f position and float probability
Visual output cv::imshow window Image with green joint circles and blue skeleton lines (threshold > 0.2)

Model Files

File Description
pose.param Simple Baseline pose model parameter file
pose.bin Simple Baseline pose model weight file

Preprocessing

  • Color conversion: BGR to RGB via ncnn::Mat::PIXEL_BGR2RGB
  • Resize: Input resized to 192x256
  • Mean values: [0.485*255, 0.456*255, 0.406*255] = [123.675, 116.28, 103.53]
  • Norm values: [1/0.229/255, 1/0.224/255, 1/0.225/255] = [0.01712, 0.01751, 0.01742]

Keypoint Layout

The model detects 17 COCO-format keypoints with the following skeleton connections (16 bone pairs):

static const int joint_pairs[16][2] = {
    {0, 1}, {1, 3}, {0, 2}, {2, 4}, {5, 6}, {5, 7},
    {7, 9}, {6, 8}, {8, 10}, {5, 11}, {6, 12}, {11, 12},
    {11, 13}, {12, 14}, {13, 15}, {14, 16}
};

Usage Examples

Running the Example

./simplepose person.jpg

Key Code Pattern

ncnn::Net posenet;
posenet.opt.use_vulkan_compute = true;

posenet.load_param("pose.param");
posenet.load_model("pose.bin");

ncnn::Mat in = ncnn::Mat::from_pixels_resize(bgr.data, ncnn::Mat::PIXEL_BGR2RGB,
    w, h, 192, 256);

const float mean_vals[3] = {0.485f * 255.f, 0.456f * 255.f, 0.406f * 255.f};
const float norm_vals[3] = {1 / 0.229f / 255.f, 1 / 0.224f / 255.f, 1 / 0.225f / 255.f};
in.substract_mean_normalize(mean_vals, norm_vals);

ncnn::Extractor ex = posenet.create_extractor();
ex.input("data", in);

ncnn::Mat out;
ex.extract("conv3_fwd", out);

// Resolve keypoints from heatmap channels
for (int p = 0; p < out.c; p++)
{
    const ncnn::Mat m = out.channel(p);
    // Find max activation location in heatmap
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment