Skip to content

Latest commit

 

History

History
83 lines (58 loc) · 2.59 KB

File metadata and controls

83 lines (58 loc) · 2.59 KB

Hand Gesture Volume Controller

Overview

This project implements a real-time hand gesture volume controller using a webcam. It detects the pinch gesture between your thumb and index finger with "MediaPipe", calculates the pinch distance, and maps it to system volume control using "Pycaw" on Windows. Visual feedback is provided via "OpenCV".

Features

  • Real-time hand landmark detection with MediaPipe.
  • Pinch distance computation for smooth volume adjustment.
  • System volume control integration using Pycaw (Windows only).
  • Visual overlays for landmarks and volume bar.
  • Easy-to-use Python script with minimal setup.

Setup Instructions

-->Prerequisites

  • Python 3.x installed on Windows.
  • Webcam connected and accessible.
  • Recommended to use a virtual environment.

--> Install Dependencies

Run this command in your terminal or command prompt:

Code Details

Hand Detection and Tracking

  • Uses MediaPipe Hands model to detect 21 keypoints per hand.
  • Captures frames from the webcam via OpenCV.
  • Converts frames to RGB for MediaPipe processing.
  • Detects thumb tip (landmark 4) and index finger tip (landmark 8).

Pinch Distance Calculation

  • Computes Euclidean distance between thumb and index fingertips.
  • Distance formula:
    [ \text{distance} = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2} ]
  • Clamps distance between calibrated minimum and maximum pinch distances.

Volume Mapping

  • Maps clamped pinch distance linearly to system volume range supported by Pycaw.
  • Volume level set via Pycaw's Core Audio API bindings.
  • Provides volume percentage for user interface feedback.

Visual Feedback

  • OpenCV displays webcam feed with:
    • Hand landmarks and connections.
    • Circles on thumb and index finger tips.
    • Line connecting thumb and index for pinch visualization.
    • Volume bar indicating current volume percentage.
    • Color changes when pinch distance is near minimum (mute signal).

Running the Project

  1. Save the Python script (e.g., hand_gesture.py).

  2. Connect your webcam.

  3. Run the script:

  4. Use the pinch gesture in view of the webcam to control volume.

  5. Press ESC to exit the program.

Troubleshooting & Tips

  • Adjust minimum and maximum pinch distances if volume reacts too fast or slow.
  • Ensure proper lighting for better hand detection.
  • Use a plain background for improved landmark accuracy.
  • Pycaw works only on Windows; Linux/macOS support requires other audio libraries.

Technologies Used

  • Python 3.x
  • MediaPipe (hand keypoint detection)
  • OpenCV (video capture and UI)
  • Pycaw (Windows audio control)
  • NumPy (math and array operations)