npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

body-measurement-ai

v1.0.1

Published

AI model to capture body measurements and determine clothing size

Downloads

7

Readme

Body Measurement AI

body-measurement-ai is a lightweight package that leverages TensorFlow.js and PoseNet to estimate body measurements (shoulder width, hip width, and height) from a live video feed. This package can be easily integrated into React and Next.js applications to provide accurate body measurements for various applications like clothing size recommendations.

Features

  • Pose Detection: Uses PoseNet to detect key points on the human body from a live video feed.
  • Real-Time Measurements: Estimates shoulder width, hip width, and height in real-time.
  • Simple Integration: Easily integrate with React or Next.js apps.

Installation

To install the package, use NPM or Yarn:

npm install body-measurement-ai

or

yarn add body-measurement-ai

Usage

Basic Setup in React/Next.js

Here is an example of how to use body-measurement-ai in a React or Next.js application:

import React, { useEffect, useRef, useState } from 'react';
import { setupCamera, loadPosenet, detectPose, PoseResult } from 'body-measurement-ai';

const BodyMeasurementComponent: React.FC = () => {
  const videoRef = useRef<HTMLVideoElement>(null); // Reference to the video element
  const [result, setResult] = useState<PoseResult | null>(null); // Store pose results or errors

  useEffect(() => {
    const setup = async () => {
      if (videoRef.current) {
        // Setup the camera
        const cameraResult = await setupCamera(videoRef.current);
        if ('success' in cameraResult && !cameraResult.success) {
          console.error(cameraResult.message); // Handle camera setup errors
          return;
        }

        // Load PoseNet model
        const netResult = await loadPosenet();
        if ('success' in netResult && !netResult.success) {
          console.error(netResult.message); // Handle PoseNet model load errors
          return;
        }

        // Start pose detection and updating measurements every second
        setInterval(async () => {
          const poseResult = await detectPose(videoRef.current!, netResult);
          if ('success' in poseResult && !poseResult.success) {
            console.error(poseResult.message); // Handle pose detection errors
          } else {
            setResult(poseResult); // Update the measurement result
          }
        }, 1000); // Run every 1 second
      }
    };

    setup(); // Initialize the camera and model when the component mounts
  }, []);

  return (
    <div>
      <h1>AI Body Measurement Tool</h1>
      <video ref={videoRef} width="640" height="480" autoPlay muted></video> {/* Video element for webcam */}
      {result && 'success' in result && !result.success ? (
        <p>Error: {result.message}</p> // Display error messages if any
      ) : result ? (
        <div>
          <p>Shoulder Width: {result.shoulderWidth}px</p> {/* Display shoulder width */}
          <p>Hip Width: {result.hipWidth}px</p> {/* Display hip width */}
          <p>Height: {result.height}px</p> {/* Display height */}
        </div>
      ) : null}
    </div>
  );
};

export default BodyMeasurementComponent;

Functions

  1. setupCamera(video: HTMLVideoElement): Promise<HTMLVideoElement | ErrorResult>

    • Sets up the user's webcam and returns the video element with the live stream.
    • Handles potential errors, such as permission denial or device issues.
  2. loadPosenet(): Promise<posenet.PoseNet | ErrorResult>

    • Loads the PoseNet model used for pose detection.
    • Returns either the loaded model or an error if something goes wrong.
  3. detectPose(video: HTMLVideoElement, net: posenet.PoseNet): Promise<PoseResult>

    • Detects key points from the video stream and calculates shoulder width, hip width, and height.
    • Returns an object with the measurements or an error if detection fails.

Example Error Handling

All functions return either a success result or an error result. Here’s how to handle errors effectively:

const cameraResult = await setupCamera(videoRef.current);
if ('success' in cameraResult && !cameraResult.success) {
  console.error(cameraResult.message); // Log or display the error message
  return;
}

Types

  • Measurements: Object containing the body measurements.

    interface Measurements {
      shoulderWidth: number;
      hipWidth: number;
      height: number;
    }
  • ErrorResult: Object returned when an error occurs during camera setup, model loading, or pose detection.

    interface ErrorResult {
      success: false;
      message: string;
    }
  • PoseResult: Union type that either contains Measurements or ErrorResult to ensure robust error handling.

    type PoseResult = Measurements | ErrorResult;

Example PoseResult Object

If the pose detection is successful:

{
  shoulderWidth: 300,
  hipWidth: 250,
  height: 600
}

If an error occurs:

{
  success: false,
  message: "Pose estimation failed. Could not detect key points."
}

Running Locally

You can run the project locally using a simple local server such as http-server.

  1. Build the project:

    npm run build
  2. Start a local server:

    npx http-server
  3. Navigate to http://localhost:8080 in your browser to see the body measurement tool in action.

License

This project is licensed under the MIT License. See the LICENSE file for details.