πŸ€– LateAI
Home β€Ί Tutorials β€Ί Gesture Volume Control
πŸ”Š

Gesture Volume Control

Beginner Β· 2 hours
πŸ“Ά Beginner ⏱ 2 hours πŸ’° Free (software only) 🏷 CV Zone

πŸ“Œ Overview

Pinch in front of the camera: the distance between your thumb and index finger controls the computer's volume in real time.

The pipeline is simple and direct - hand landmark distance, mapped to a volume range, fed into the system volume API. It is the bridge project from gesture detection to gesture control, and the standard example of an interactive application.

🧰 What you need

πŸ”§ Step by step

1

Install the dependencies

On Windows use pycaw for volume, on macOS osascript is a workable substitute

Test that the volume API works before going further

2

Detect the hand landmarks

Use HandTrackingModule to get the thumb and index fingertips

Draw the connecting line and the distance text between them

3

Compute the distance

Use the Euclidean distance formula on the two fingertips (in pixels)

Moving nearer or further from the camera changes the absolute value, so normalise first

4

Map it to a volume range

Map the pixel distance linearly onto a volume of 0-100

Use numpy clip/interp to handle the ends of the range

5

Set the system volume

Write the mapped value to the system volume API

Draw the volume bar on the frame for immediate feedback

6

Smooth and finish

Apply a smoothing filter to the volume value so it does not jump

Refactor it into a reusable volume-control function

πŸ’‘ Tips

View original β†— ← Back to LateAI home