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 🙏

© 2024 – Pkg Stats / Ryan Hefner

fingerpose

v0.1.0

Published

Finger pose classifier for hand landmarks detected by TensorFlow.js handpose model

Downloads

1,632

Readme

Fingerpose

Finger gesture classifier for hand landmarks detected by MediaPipe Handpose. It detects gestures like "Victory" ✌️or "Thumbs Up" 👍inside a source image or video stream. You can define additional hand gestures using simple gesture descriptions.

"Thumbs up" and "Victory" gestures detected

Usage

How it works

Gesture detection works in three steps:

  1. Detect the hand landmarks inside the video picture
  2. Estimating the direction and curl of each individual finger
  3. Comparing the result to a set of gesture descriptions

Step (1) is performed by MediaPipe Handpose, Step (2) and (3) are handled by this library.

Installation

  1. Install MediaPipe Handpose
  2. Install the module via NPM or Yarn:
npm i --save fingerpose

Demo

1. Web Browser

A fully working example can be found inside the dist folder. The basic steps are outlined below:

Include MediaPipe Handpose and its prerequisites (TFJS >= 2.1.0)

<!-- this example uses TFJS 3.7.0 - older versions back to 2.1.0 are supported -->
<script src="https://unpkg.com/@tensorflow/[email protected]/dist/tf-core.js"></script>
<script src="https://unpkg.com/@tensorflow/[email protected]/dist/tf-converter.js"></script>

<!-- use the WebGL backend (recommended) - you can alternatively use the WASM backend -->
<script src="https://unpkg.com/@tensorflow/[email protected]/dist/tf-backend-webgl.js"></script>

<script src="https://unpkg.com/@tensorflow-models/[email protected]/dist/handpose.js"></script>

Include this library

<script src="fingerpose.js" type="text/javascript"></script>

Add the gestures you want do detect

// add "✌🏻" and "👍" as sample gestures
const GE = new fp.GestureEstimator([
    fp.Gestures.VictoryGesture,
    fp.Gestures.ThumbsUpGesture
]);

Use Handpose to estimate the landmarks

const model = await handpose.load();
const predictions = await model.estimateHands(video, true);

Estimate the gestures

// using a minimum match score of 8.5 (out of 10)
const estimatedGestures = GE.estimate(predictions.landmarks, 8.5);

The result is an object containing possible gestures and their match score, for example:

{
    poseData: [ ... ],
    gestures: [
        { name: 'thumbs_up', score: 9.25 },
        { ... }
    ]
}

In addition you receive the poseData array including the raw curl and direction information for each finger. This is useful for debugging purposes as it can help you understand how an individual finger is "seen" by the library.

// example for raw pose data
poseData: [
    ['Thumb', 'No Curl', 'Vertical Up],
    ['Index', 'Half Curl', 'Diagonal Up Right'],
    ...
]

Define your own gestures

You can create any number of hand gestures for this library to recognize. To see how a gesture is described, have a look at the included sample gestures Victory and Thumbs Up.

A gesture is defined by describing the expected curl and direction of each individual finger. For example for a "Thumbs Up" gesture is defined by a stretched out thumb pointing up while all other fingers are curled and pointing to the left or right 👍.

To describe gestures, you can use the provided Finger Description Constants:

| Finger | Name | |--|--| | 0 | Finger.Thumb | | 1 | Finger.Index | | 2 | Finger.Middle | | 3 | Finger.Ring | | 4 | Finger.Pinky |

Probably no further explanation is required for finger names... 👋

| Curl | Name | |--|--| | 0 | FingerCurl.NoCurl | | 1 | FingerCurl.HalfCurl | | 2 | FingerCurl.FullCurl |

You can refer to the images below for an example how the index finger is curled (no curl, half curl, full curl): | enter image description here | enter image description here | enter image description here | |--|--|--| | No curl | Half curl | Full curl |

| Direction | Name | |--|--| | 0 | Vertical Up 👆 | | 1 | Vertical Down 👇| | 2 | Horizontal Left 👈| | 3 | Horizontal Right 👉 | | 4 | Diagonal Up Right ↗️ | | 5 | Diagonal Up Left ↖️ | | 6 | Diagonal Down Right ↘️ | | 7 | Diagonal Down Left ↙️ |

Example: Thumbs down gesture description 👎

First create a new GestureDescription object:

const thumbsDownGesture = new fp.GestureDescription('thumbs_down');

Expect the thumb to be stretched out and pointing down:

thumbsDownGesture.addCurl(fp.Finger.Thumb, fp.FingerCurl.NoCurl);
thumbsDownGesture.addDirection(fp.Finger.Thumb, fp.FingerDirection.VerticalDown, 1.0);

This will define that a thumb pointing downwards will result in the highest score (1.0) for this gesture. If the thumb is angled to diagonal down left / right we can somehow still accept it, albeit with a lower score (0.9).

thumbsDownGesture.addDirection(fp.Finger.Thumb, fp.FingerDirection.DiagonalDownLeft, 0.9);
thumbsDownGesture.addDirection(fp.Finger.Thumb, fp.FingerDirection.DiagonalDownRight, 0.9);

All other fingers are expected to be fully curled. For this gesture it doesn't really matter which direction the curled fingers are pointing at therefore only the curl description is added. Same as above, it's recommended to accept half curled fingers too, with a little bit lower score.

// do this for all other fingers
for(let finger of [fp.Finger.Index, fp.Finger.Middle, fp.Finger.Ring, fp.Finger.Pinky]) {
  thumbsUpDescription.addCurl(finger, FingerCurl.FullCurl, 1.0);
  thumbsUpDescription.addCurl(finger, FingerCurl.HalfCurl, 0.9);
}

Tips to improve detection

Experiment with scores and weights

The "score" is a number between 0 and 10 which describes how good a given combination of finger curl / positions matches a predefined gesture. A perfect match will result in a score of 10.

  • The score threshold should be set rather high (at least 8, better 8.5). If you want to distinguish very similar gestures like "Thumbs up" and "Thumbs down", then add more constraints to your gesture descriptions.
  • Try to experiment with the score for individual fingers. You can add more (or less) weight to single curl / direction by settng the third parameter to a value lower or higher than 1.0.

Check if you really need a finger pointing direction

Many poses do not require fingers pointing in a specific direction but are defined by curls only. In these cases just do not add direction constraints to your pose. This also makes it easier to account for left-/right-handed persons.

Also note: Unless you're Houdini, you can not fully curl your thumb.

Pre-process your input data

  • Consider running another model like PoseNet to detect the hand position(s) first, then crop your input image to only contain the hand. This will not only significantly reduce false detections but also speed up Handpose inference as much less image data needs to be processed (PoseNet is cheap in comparison).
  • MediaPipe Handpose does not offer much customization. Still you can try playing with the model parameters, especially detectionConfidence and iouThreshold which can improve accuracy under some lighting conditions.

Post-process your detections

You should treat your detections as a "noisy signal" and add some smoothing / filtering. For example:

  • Easy: Use an average of (for example) three consecutive detections (basically a high pass filter)
  • Advanced: Use filters like One-Euro filters

Debug your gestures

Look at the raw pose data result in GestureEstimator::estimate() to understand the detected curls / directions for each finger to the console. This way you can verify if your assumed curls / directions match with what the estimator actually sees.

Known issues and limitations

  • Currently only one hand is supported at the same time. This is a limitation of the underlying handpose model and may or may not change in the future.
  • The handpose model has issues detecting a single stretched out finger (for example index finger). It will occasionally not detect a finger going from "curled" to "not curled" or vice-versa.

Credits

The hand gesture recognition module is based on the amazing work by Prasad Pai. This module is more or less a straight JavaScript port of his FingerPoseEstimate Python module.