Skip to content

LUV-07/Computer-Vision

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

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)

About

This project implements a real-time system to control your computer's audio volume using hand gestures detected via a webcam. Leveraging MediaPipe's hand landmark detection, the distance between the thumb and index finger (pinch gesture) is tracked and mapped dynamically to the system volume in Windows using Pycaw.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages