Skip to main content

A Jupyter anywidget that streams live MediaPipe hand-landmark and gesture data from your webcam into Python.

Project description

gesture-recognizer-widget

A Jupyter anywidget that runs the MediaPipe Gesture Recognizer on your webcam and streams the results straight into Python. Each of the 21 hand landmarks is a live traitlet, so you can read finger positions, the recognized gesture, and handedness directly in a notebook — and drive anything you like with them (plots, robots, a Blender rig, …).

All inference happens in the browser via @mediapipe/tasks-vision; Python just receives the numbers.

Install

pip install gesture-recognizer-widget

Use it in a notebook

from gesture_widget import GestureRecognizerWidget

w = GestureRecognizerWidget()
w                       # display the cell, then click "Start Camera"
# Individual landmarks as [x, y, z], normalized 0..1 (empty list when no hand):
w.index_finger_tip      # -> [0.51, 0.42, 0.0]
w.thumb_tip
w.wrist

# High-level result for the primary (most confident) hand:
w.gesture               # -> "Victory"
w.confidence            # -> 0.93
w.handedness            # -> "Right"
w.num_hands             # -> 1

# Everything at once:
w.finger_positions()    # {"wrist": [...], "thumb_cmc": [...], ...}  (21 entries)
w.hands                 # full per-hand data for every detected hand

# React to changes:
w.observe(lambda ch: print(ch["new"]), "index_finger_tip")

# Control from Python:
w.start(); w.stop()     # toggle the camera
w.mirror = False
w.max_num_hands = 1
w.sync_interval_ms = 50 # how often landmarks are pushed to Python (default 100ms)

Camera access requires a browser context: start it from the rendered widget's button (a user gesture) or via w.start(). The model and WASM runtime are fetched from the MediaPipe CDN on first load, so the first run needs internet.

Using the development version

If you've cloned the repo and want to run against your local checkout (e.g. to hack on the widget while using the notebook), install it in editable mode after building the front-end bundle:

npm install
npm run build:widget    # bundles src/widget.ts -> src_widget/gesture_widget/static/widget.js
pip install -e .        # editable install of the local package

pip install -e . makes from gesture_widget import GestureRecognizerWidget resolve to your working tree, so Python changes are picked up immediately and rebuilding the bundle refreshes the front-end. If you're working inside an embedded interpreter (such as Blender's bundled Python), point its pip at the repo instead:

import subprocess, sys
subprocess.check_call([sys.executable, "-m", "pip", "install", "-e", "/path/to/caputre_motion"])

License

MIT

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

gesture_recognizer_widget-0.1.0.tar.gz (50.7 kB view details)

Uploaded Source

Built Distribution

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

gesture_recognizer_widget-0.1.0-py3-none-any.whl (51.8 kB view details)

Uploaded Python 3

File details

Details for the file gesture_recognizer_widget-0.1.0.tar.gz.

File metadata

File hashes

Hashes for gesture_recognizer_widget-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ea73e79ac8bd1a562101e76128f5d63949298b953c8fa9cdd19d3b35d8189989
MD5 d3b4e6250328a518e1a9baf18163dbd1
BLAKE2b-256 b5f785bfdefa8a67bc938c982e45a777f3bcdebd8da79c05b47359ecbc7d70c7

See more details on using hashes here.

File details

Details for the file gesture_recognizer_widget-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gesture_recognizer_widget-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 970bb76e240a2fd47d271584af0372a3b50c5c36c0c0ea1497e633cc1d1a2360
MD5 478af64d84a89fb4fe4e78d663b54f09
BLAKE2b-256 0b320d803931f9ebc2ec2cf2eb09119011958df0c048e97dc7bca7f3b3718141

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