Hand Tracking
Real-time hand tracking using MediaPipe and OpenCV. Detects hands via webcam and processes 21 hand landmarks per hand in real time.
Demo
| Feature | Status |
|---|---|
| Webcam capture | ✅ |
| Hand detection | ✅ |
| Landmark processing | ✅ |
| Live display window | ✅ |
How It Works
- Webcam frame captured via OpenCV (
cv2.VideoCapture) - Frame converted BGR → RGB for MediaPipe
- MediaPipe Hands model detects up to 2 hands and returns 21 3D landmarks per hand
- Processed frame rendered in an OpenCV window
MediaPipe Hand Landmarks
MediaPipe tracks 21 keypoints per hand:
8 12 16 20
| | | |
7 11 15 19
| | | |
6 10 14 18
| | | |
5 9 13 17
\ | | /
4 | | 4
\| |/
3 3
| |
2 2
| |
1 1
\ /
0 (WRIST)
Landmark indices map to: 0 = Wrist, 1-4 = Thumb, 5-8 = Index, 9-12 = Middle, 13-16 = Ring, 17-20 = Pinky.
Requirements
- Python 3.11+
- Webcam / camera device
- uv (recommended) or pip
Installation
Install as package via pip
pip install git+https://github.com/muhammadsufiyanbaig/hand-tracking.git
Install as package via uv
uv add git+https://github.com/muhammadsufiyanbaig/hand-tracking.git
Local development with uv (Recommended)
git clone https://github.com/muhammadsufiyanbaig/hand-tracking.git
cd hand-tracking
uv sync
Local development with pip
git clone https://github.com/muhammadsufiyanbaig/hand-tracking.git
cd hand-tracking
python -m venv venv
# Windows
venv\Scripts\activate
# macOS / Linux
source venv/bin/activate
pip install -e .
Usage
CLI (after package install)
hand-tracking
Module
python -m hand_tracking
Script (local dev)
# uv
uv run main.py
# activated venv
python main.py
Press Q to quit.
Project Structure
hand-tracking/
├── hand_tracking/
│ ├── __init__.py # Package init, exposes __version__
│ └── __main__.py # Core tracking logic + CLI entry point
├── main.py # Thin shim for direct script execution
├── hand_landmarker.task # MediaPipe hand landmark model (task file)
├── pyproject.toml # Package metadata, dependencies, build config
├── uv.lock # Locked dependency versions
├── .python-version # Pinned Python version (3.11)
└── README.md
Dependencies
| Package | Version | Purpose |
|---|---|---|
mediapipe |
0.10.9 | Hand landmark detection model |
opencv-python |
≥4.13.0 | Webcam capture and image rendering |
Configuration
mpHands.Hands() accepts optional parameters:
| Parameter | Default | Description |
|---|---|---|
static_image_mode |
False |
True for images, False for video stream |
max_num_hands |
2 |
Maximum number of hands to detect |
min_detection_confidence |
0.5 |
Minimum score to consider detection valid |
min_tracking_confidence |
0.5 |
Minimum score to keep tracking (video mode) |
Example with custom config:
hands = mpHands.Hands(
max_num_hands=1,
min_detection_confidence=0.7,
min_tracking_confidence=0.6
)
Extending the Project
Common next steps:
Draw landmarks on frame:
mpDraw = mp.solutions.drawing_utils
if results.multi_hand_landmarks:
for handLms in results.multi_hand_landmarks:
mpDraw.draw_landmarks(img, handLms, mpHands.HAND_CONNECTIONS)
Read a specific landmark (e.g. index fingertip = landmark 8):
if results.multi_hand_landmarks:
for handLms in results.multi_hand_landmarks:
h, w, _ = img.shape
lm = handLms.landmark[8]
cx, cy = int(lm.x * w), int(lm.y * h)
Display FPS:
pTime = 0
# inside loop:
cTime = time.time()
fps = 1 / (cTime - pTime)
pTime = cTime
cv2.putText(img, f"FPS: {int(fps)}", (10, 70),
cv2.FONT_HERSHEY_PLAIN, 3, (255, 0, 255), 3)
License
MIT
Metadata
Release files for hand-tracking-mp 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hand_tracking_mp-0.1.0.tar.gz | 5.9 MB | Without provenance | Details for hand_tracking_mp-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hand_tracking_mp-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for hand_tracking_mp-0.1.0-py3-none-any.whl |
Total release size: 5.9 MB
Release files / hand_tracking_mp-0.1.0.tar.gz
| Download URL | hand_tracking_mp-0.1.0.tar.gz |
|---|---|
| Size | 5.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aa16887153cc5317e930aa947bff96cc0376ed3131b8198cb9266c2bd92e8471
|
|
BLAKE2b-256 checksum How to use checksums |
ee5b1f020a746effd0682a3fc61e8e8f5e2c9ce9f6b4e191ea3fa5269f3eacfd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / hand_tracking_mp-0.1.0-py3-none-any.whl
| Download URL | hand_tracking_mp-0.1.0-py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
179330ed3b5176fa3715dd52f03c3190950ef16b4b7e2b207767f0cccec402a6
|
|
BLAKE2b-256 checksum How to use checksums |
d53c85aaa24bb9f8ff2edb2c2d949ef412e8d2847612e0fccd3758a0c0ee0384
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for hand-tracking-mp 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.