2022

Hand gesture volume control

Pinch your thumb and finger closer or further apart in front of a webcam and the Mac volume follows.

  • Python
  • OpenCV
  • MediaPipe

Source on GitHub

A small computer vision project. The webcam watches your hand, and the distance between your thumb and index finger sets the system volume.

How it works

  • OpenCV captures the webcam feed.
  • MediaPipe's hand landmarker finds 21 keypoints per hand in real time, for up to two hands.
  • The distance between the thumb tip and the index fingertip is mapped onto a 0 to 100% volume range.
  • The Mac's volume is set through osascript, and only when the value actually changes, so it isn't spamming the system on every frame.
  • The distance, the current volume and the gesture midpoint are drawn over the video as you move.

I first wrote it in 2022 and reworked it in 2026 onto the current MediaPipe Tasks API.