Skip to main content

Fastest MediaPipe-compatible hand tracker: hand landmarks on the Apple Neural Engine at 0.7 ms/frame

Project description

fasthands

The fastest MediaPipe-compatible hand tracker. MediaPipe Hands' official models running on the Apple Neural Engine via CoreML — 0.55 ms per tracked frame on Apple Silicon (1800 FPS), ~6× faster than MediaPipe itself, with a faithful port of the full HandLandmarker pipeline (SSD anchors, weighted NMS, ROI tracking, landmark projection, deduplication).

macOS / Apple Silicon only.

Install

pip install fasthands

Use

import cv2
import fasthands

tracker = fasthands.load(num_hands=1)

image = cv2.cvtColor(cv2.imread("hand.jpg"), cv2.COLOR_BGR2RGB)
hands = tracker(image)                 # single image
# hands = tracker.detect_video(frame)  # video: tracks between frames, ~0.7 ms

for hand in hands:
    print(hand["handedness"], hand["score"])
    print(hand["landmarks"])        # 21 x (x, y, z), normalized image coords
    print(hand["world_landmarks"])  # 21 x (x, y, z), meters, hand-centered

Pipelined streaming (overlaps CPU pre/post with Neural Engine inference, ~15% faster end-to-end — see below):

import cv2, fasthands
tracker = fasthands.load(num_hands=1)
cap = cv2.VideoCapture(0)
def frames():
    while True:
        ok, f = cap.read()
        if not ok: break
        yield f
for frame_bgr, hands in fasthands.stream(tracker, frames()):
    ...  # draw/use hands; this runs concurrently with the next inference

Or from the command line:

fasthands photo.jpg --out annotated.jpg
fasthands-webcam --mirror     # live demo (pipelined) with FPS overlay

Detector

As of 0.4.0 the default detector is WHIM — a fine-tuned full-hand-box detector that's steadier and more robust than MediaPipe's palm detector (which targets a smaller palm box and is more easily lost on rotated or partially-occluded hands). It feeds the same MediaPipe landmark model through a re-tuned ROI, and on the test image its landmarks match the original pipeline to ~0.2%. To use the original palm detector:

tracker = fasthands.load(detector="mediapipe")
fasthands photo.jpg --detector mediapipe

Speed (Apple M4, 540×720 frame, one hand)

tracking detect + track
fasthands (ANE) 0.55 ms (1800 FPS) 1.65 ms (600 FPS)
mediapipe (XNNPACK CPU) 3.25 ms (310 FPS) 8.77 ms (115 FPS)
5.9× faster 5.3× faster

Landmarks agree with MediaPipe to ~9e-4 (Neural Engine fp16); the pipeline logic itself is verified to MediaPipe's own float32 reproducibility floor.

How

The hand_landmarker.task models are converted to CoreML, and every MediaPipe calculator in the pipeline (anchors, decode, weighted NMS, rect transforms, rotated crops, projections, VIDEO-mode ROI tracking, dedup) is reimplemented in numpy with float32 op-order fidelity. Model weights © Google, Apache 2.0.

Source, the PyTorch reference implementation, and the full verification harness: https://github.com/VimalMollyn/Mediapipe-Hands-PyTorch-CoreML

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fasthands-0.4.0.tar.gz (7.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fasthands-0.4.0-py3-none-any.whl (8.0 MB view details)

Uploaded Python 3

File details

Details for the file fasthands-0.4.0.tar.gz.

File metadata

  • Download URL: fasthands-0.4.0.tar.gz
  • Upload date:
  • Size: 7.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for fasthands-0.4.0.tar.gz
Algorithm Hash digest
SHA256 ede3089130784c9eb99e39fafbc11c687f31f6e6dfecabb760fb428be4284472
MD5 541495a26299f5938f340b08e0d69b1c
BLAKE2b-256 0db4b28f7a14a24ce1e1681293c49bd99d2557ab93aa50e89e3fd830d8267ef7

See more details on using hashes here.

File details

Details for the file fasthands-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: fasthands-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for fasthands-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7a28329dc309125721d873bbbac960d3fb2d44cd1ddf050dc17093d933098448
MD5 e0c2c437bec36dd5f7519e11d37d8e01
BLAKE2b-256 1e725481abb0cbb22ef0eaed0b6a38eee08248143b2dc37b1d6c0160b9a52619

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page