A real-time computer vision application that uses hand gesture recognition to control system volume — no keyboard or mouse required.
Control your Mac's volume by pinching your thumb and index finger together or apart. The further apart your fingers, the higher the volume.
- Webcam captures a live video feed
- MediaPipe Tasks detects hand landmarks in real time (21 keypoints per hand)
- The Euclidean distance between the thumb tip (landmark 4) and index finger tip (landmark 8) is calculated
- That distance is mapped to a volume percentage (0–100%)
- System volume is updated instantly via
osascript(only when the value changes)
- Real-time hand detection and tracking at webcam framerate
- Visual feedback — distance and volume percentage rendered on-screen
- Midpoint overlay showing current gesture reading
- Supports up to 2 hands simultaneously
| Library | Purpose |
|---|---|
| Python 3 | Core language |
OpenCV (cv2) |
Webcam capture and image rendering |
| MediaPipe Tasks | Hand landmark detection (HandLandmarker) |
| osascript | macOS system volume control |
| math | Euclidean distance calculation |
- macOS (volume control uses
osascript) - Python 3.x
- Webcam
git clone https://github.com/Artlenhavis123/Handtracking_Volume_Change.git
cd Handtracking_Volume_Change
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python main.pyOn first run, the MediaPipe hand_landmarker.task model (~8 MB) is downloaded automatically into the project directory.
- Run the script and allow webcam access
- Hold your hand in front of the camera
- Pinch thumb and index finger together → volume decreases
- Pull them apart → volume increases
- Distance and volume % are shown on screen in real time
- Press
qto quit
| Finger Distance | Volume |
|---|---|
| < 50px | 0% (mute) |
| 50–300px | Scaled linearly |
| > 300px | 100% |
- Currently macOS only — Windows support via
pycawis a planned improvement - Volume mapping is linear; a smoothing function would reduce abrupt jumps
- Cross-platform support (Windows via
pycaw, Linux viaamixer) - Gesture smoothing to reduce volume flickering
- Additional gesture commands (mute toggle, play/pause)
- Configurable sensitivity settings
Oliver Havis — GitHub