App · Python
Hand Gesture Volume Control
Webcam hand-gesture volume control. Python, OpenCV, MediaPipe.
Why it exists
A university project to try real-time computer vision: use a ready hand-landmark model for something you can feel working straight away. It taught how to turn pixel coordinates into a control signal, and how fast a Windows audio API changes between releases (see the pycaw note under Design decisions).
What it does
- 01
Pinch-to-volume. the distance between thumb tip and index tip sets the master volume.
- 02
Smoothed volume. the pinch ratio goes through an exponential moving average (weight SMOOTHING_ALPHA, default 0.4), so landmark jitter does not shake the volume; the average restarts when the hand leaves the frame.
- 03
Volume lock. press L (change with LOCK_KEY) with the preview window focused to freeze the volume at its current value, so you can lower your hand during a call or a film; the window shows LOCKED and the hand is still drawn. Press the key again to follow your pinch again.
- 04
Calibration to your hand. press C (change with CALIBRATE_KEY) and open and close the pinch for 5 seconds; the 5th and 95th percentiles of your pinch become 0% and 100%, so a small hand or a stiff thumb still reaches both ends. Saved to ~/.hand-gesture-volume-control/calibration.json (CALIBRATION_FILE) and loaded at start; refused with a reason when fewer than 30 frames had a hand or the pinch barely moved.
- 05
Fist to mute. a fist held for 10 frames (about a third of a second, MUTE_HOLD_FRAMES) toggles mute once; release it before it can toggle again. While a fist is forming the volume holds still, so closing the hand does not first drag the volume to 0. Measured on 3,223 held-out hands: precision 0.934, recall 0.785 (see Engineering quality).
- 06
Open palm to play or pause. an open hand (all four fingers straight, thumb out) held still for 30 frames (about a second, PALM_HOLD_FRAMES), the knuckle drifting no more than a quarter of the hand size (PALM_STILL_MOVE), sends the Windows play/pause media key once; any player that listens for media keys reacts. Release the hand before it can fire again. While a palm is forming the volume holds still, because a fully open pinch looks like a palm. PALM_PLAY_PAUSE=0 turns it off. Measured on 3,223 held-out hands: precision 0.644, recall 0.751, and a relaxed open hand looks like a palm in a single photo (26.7% of resting hands), which is why the hold is required (see Engineering quality).
Next
cutline