CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-tensorflow-models--posenet

Pretrained PoseNet model in TensorFlow.js for real-time human pose estimation from images and video streams

Pending
Overview
Eval results
Files

single-pose.mddocs/

Single Person Pose Estimation

Fast pose detection algorithm optimized for single person scenarios. Ideal when only one person is expected in the image.

Capabilities

Estimate Single Pose

Detects and estimates a single pose from input image using the fastest decoding algorithm.

/**
 * Estimate single person pose from input image
 * @param input - Input image (various formats supported)
 * @param config - Configuration options for inference
 * @returns Promise resolving to single detected pose
 */
estimateSinglePose(
  input: PosenetInput,
  config?: SinglePersonInterfaceConfig
): Promise<Pose>;

Usage Examples:

import * as posenet from '@tensorflow-models/posenet';

// Load model
const net = await posenet.load();

// Basic single pose estimation
const imageElement = document.getElementById('person-image') as HTMLImageElement;
const pose = await net.estimateSinglePose(imageElement);

console.log('Overall pose confidence:', pose.score);
console.log('Number of keypoints detected:', pose.keypoints.length);

// With horizontal flipping (for webcam feeds)
const webcamPose = await net.estimateSinglePose(videoElement, {
  flipHorizontal: true
});

// Process high-confidence keypoints
const highConfidenceKeypoints = pose.keypoints.filter(kp => kp.score > 0.7);
highConfidenceKeypoints.forEach(keypoint => {
  console.log(`${keypoint.part}: (${keypoint.position.x}, ${keypoint.position.y}) confidence: ${keypoint.score}`);
});

// Access specific body parts
const nose = pose.keypoints.find(kp => kp.part === 'nose');
const leftWrist = pose.keypoints.find(kp => kp.part === 'leftWrist');
if (nose && leftWrist) {
  const distance = Math.sqrt(
    Math.pow(nose.position.x - leftWrist.position.x, 2) + 
    Math.pow(nose.position.y - leftWrist.position.y, 2)
  );
  console.log('Distance from nose to left wrist:', distance);
}

Single Person Configuration

Configuration options for single person pose estimation.

/**
 * Configuration interface for single person pose estimation
 */
interface SinglePersonInterfaceConfig {
  /** Whether to flip poses horizontally (useful for webcam feeds) */
  flipHorizontal: boolean;
}

Default Configuration

const SINGLE_PERSON_INFERENCE_CONFIG: SinglePersonInterfaceConfig = {
  flipHorizontal: false
};

Input Types

Single pose estimation supports multiple input formats:

type PosenetInput = 
  | ImageData        // Canvas ImageData object
  | HTMLImageElement // HTML img element  
  | HTMLCanvasElement // HTML canvas element
  | HTMLVideoElement // HTML video element
  | tf.Tensor3D;     // TensorFlow.js 3D tensor

Input Examples:

// HTML Image Element
const img = document.getElementById('photo') as HTMLImageElement;
const pose1 = await net.estimateSinglePose(img);

// HTML Video Element (for real-time processing)
const video = document.getElementById('webcam') as HTMLVideoElement;
const pose2 = await net.estimateSinglePose(video, { flipHorizontal: true });

// HTML Canvas Element
const canvas = document.getElementById('drawing') as HTMLCanvasElement;
const pose3 = await net.estimateSinglePose(canvas);

// ImageData from canvas
const ctx = canvas.getContext('2d')!;
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
const pose4 = await net.estimateSinglePose(imageData);

Return Value

Single pose estimation returns a Promise that resolves to a Pose object:

/**
 * Detected pose with keypoints and confidence score
 */
interface Pose {
  /** Array of 17 keypoints representing body parts */
  keypoints: Keypoint[];
  /** Overall pose confidence score (0-1) */
  score: number;
}

/**
 * Individual body part keypoint with position and confidence
 */
interface Keypoint {
  /** Confidence score for this keypoint (0-1) */
  score: number;
  /** 2D position in image coordinates */
  position: Vector2D;
  /** Body part name (e.g., 'nose', 'leftWrist') */
  part: string;
}

interface Vector2D {
  x: number;
  y: number;
}

Body Parts Detected

Single pose estimation detects 17 standard keypoints:

IDPart NameDescription
0noseNose tip
1leftEyeLeft eye center
2rightEyeRight eye center
3leftEarLeft ear
4rightEarRight ear
5leftShoulderLeft shoulder
6rightShoulderRight shoulder
7leftElbowLeft elbow
8rightElbowRight elbow
9leftWristLeft wrist
10rightWristRight wrist
11leftHipLeft hip
12rightHipRight hip
13leftKneeLeft knee
14rightKneeRight knee
15leftAnkleLeft ankle
16rightAnkleRight ankle

Algorithm Details

The single pose estimation algorithm:

  1. Input Processing: Resizes and normalizes input image
  2. Neural Network Inference: Processes image through selected architecture (MobileNetV1/ResNet50)
  3. Heatmap Analysis: Finds maximum confidence locations for each body part
  4. Offset Application: Applies offset vectors to refine keypoint positions
  5. Coordinate Transformation: Scales positions back to original image coordinates

Performance Characteristics

  • Speed: Fastest pose estimation algorithm in PoseNet
  • Accuracy: Good for single person scenarios
  • Limitations: May conflate keypoints when multiple people are present
  • Memory: Lower memory usage compared to multi-person estimation
  • Real-time: Suitable for real-time applications on moderate hardware

Install with Tessl CLI

npx tessl i tessl/npm-tensorflow-models--posenet

docs

advanced-apis.md

index.md

keypoints.md

model-loading.md

multi-pose.md

pose-utilities.md

single-pose.md

tile.json