A real-time hand-tracking project built using OpenCV, MediaPipe, and Python. This system uses your webcam to detect hand landmarks and perform actions like:
- Volume Control (thumb–index distance)
- Zoom Simulation (digital zoom effect via pinch gesture)
- Drawing Mode (index finger tracking)
- Can be extended with more gestures
- Real-time hand landmark detection using MediaPipe (21 points on each hand).
- Modular design with separate files:
main.py→ Entry point for the apphand_tracking.py→ Handles camera & landmark detectiongestures.py→ Defines custom gestures (volume, zoom, drawing, etc.)
- Easy to extend: Add new gestures with just a function!
- Cross-platform (Windows/Linux/Mac) — OS-specific volume control included.
📦 hand-tracking-gesture-control
├── main.py # Main script (runs the system)
├── hand_tracking.py # HandTracker class (camera + mediapipe processing)
├── gestures.py # Gesture functions (volume, zoom, draw, etc.)
├── requirements.txt # Python dependencies
└── README.txt # Documentation (this file)
- Clone the repository:
git clone https://github.com/your-username/hand-tracking-gesture-control.git
cd hand-tracking-gesture-control- Install dependencies:
pip install -r requirements.txt- Run the project:
python main.pyYour requirements.txt should contain:
opencv-python
mediapipe
numpy
pycaw # (for Windows volume control)
MediaPipe uses 21 hand landmarks:
| ID | Landmark | Description |
|---|---|---|
| 0 | Wrist | Base of palm |
| 1-4 | Thumb joints | CMC → MCP → IP → Tip |
| 5-8 | Index finger | MCP → PIP → DIP → Tip |
| 9-12 | Middle finger | MCP → PIP → DIP → Tip |
| 13-16 | Ring finger | MCP → PIP → DIP → Tip |
| 17-20 | Pinky finger | MCP → PIP → DIP → Tip |
📌 Example:
4→ Thumb Tip8→ Index Tip- These two are used for pinch gestures (zoom/volume control).
- OpenCV captures webcam frames.
- MediaPipe processes frames to detect 21 landmarks per hand.
- Gestures are recognized by measuring distances between key landmarks.
- Actions are triggered:
- Volume Control: Distance between thumb tip (
4) and index tip (8). - Zoom: Pinch distance mapped to digital zoom effect.
- Draw: Tracks index tip (
8) on the canvas.
- Volume Control: Distance between thumb tip (
- Multi-hand gesture support
- Gesture recognition with ML model (custom gestures)
- System-level integration (brightness, media control, etc.)
- Export as a desktop app with PyInstaller
Feel free to fork this project, open issues, and submit pull requests.