Skip to content

This project uses MediaPipe and OpenCV to detect hand gestures from a webcam and control the Windows system volume. It calculates the distance between thumb and index finger to set the volume level and displays a visual volume bar with feedback on the video feed.

License

Notifications You must be signed in to change notification settings

YoussefOsama12345/Gesture-volume-control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

๐Ÿค– Hand Gesture Recognition System

A real-time hand gesture recognition system that uses computer vision to control your computer's volume through hand gestures. Built with Python, OpenCV, and MediaPipe.

โœจ Features

  • Real-time Hand Detection: Uses MediaPipe for accurate hand landmark detection
  • Volume Control: Control system volume with simple hand gestures
  • Multiple Gestures: Support for index finger up and fist gestures
  • Live Video Feed: Real-time camera feed with hand landmark visualization
  • Cross-platform: Works on Windows, macOS, and Linux
  • Easy to Use: Simple setup and intuitive gesture controls

๐ŸŽฏ Supported Gestures

Gesture Action Description
๐Ÿ‘† Index Finger Up Increase Volume Point your index finger upward
โœŠ Fist Decrease Volume Make a fist with your hand

๐Ÿ“‹ Requirements

  • Python 3.9 or higher
  • Webcam
  • Windows OS (for volume control functionality)

๐Ÿš€ Installation

1. Clone the Repository

git clone <repository-url>
cd hand_gesture

2. Install Dependencies

pip install -r requirements.txt

3. Additional Dependencies

For volume control on Windows, install:

pip install pycaw

๐ŸŽฎ Usage

Basic Usage

python main.py

How to Use

  1. Start the Program: Run python main.py
  2. Show Your Hand: Position your hand in front of the camera
  3. Make Gestures:
    • Index finger up โ†’ Increase volume by 1%
    • Fist โ†’ Decrease volume by 1%
  4. Exit: Press ESC key to quit

Tips for Better Recognition

  • Ensure good lighting conditions
  • Keep your hand clearly visible to the camera
  • Maintain a reasonable distance from the camera (30-200cm)
  • Use clear, deliberate gestures

๐Ÿ—๏ธ Project Structure

hand_gesture/
โ”œโ”€โ”€ main.py                 # Main application entry point
โ”œโ”€โ”€ requirements.txt        # Python dependencies
โ”œโ”€โ”€ README.md              # Project documentation
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ __init__.py        # Package initialization
โ”‚   โ”œโ”€โ”€ camera.py          # Camera interface and frame capture
โ”‚   โ”œโ”€โ”€ hand_detector.py   # Hand detection using MediaPipe
โ”‚   โ”œโ”€โ”€ gesture_classifier.py # Gesture recognition logic
โ”‚   โ”œโ”€โ”€ volume_control.py  # System volume control interface
โ”‚   โ”œโ”€โ”€ config.py          # Configuration settings
โ”‚   โ””โ”€โ”€ utils.py           # Utility functions

๐Ÿ”ง Configuration

Edit src/config.py to customize settings:

# Camera settings
CAMERA_ID = 0              # Camera device ID
FRAME_WIDTH = 640          # Frame width
FRAME_HEIGHT = 480         # Frame height

# Hand detection settings
MAX_NUM_HANDS = 1          # Maximum hands to detect
DETECTION_CONFIDENCE = 0.7 # Detection confidence threshold
TRACKING_CONFIDENCE = 0.7  # Tracking confidence threshold

# Distance settings
MIN_DISTANCE = 30          # Minimum hand distance
MAX_DISTANCE = 200         # Maximum hand distance

๐Ÿ› ๏ธ Technical Details

Core Components

1. Camera Module (src/camera.py)

  • Handles webcam initialization and frame capture
  • Supports configurable resolution and camera selection

2. Hand Detector (src/hand_detector.py)

  • Uses MediaPipe for real-time hand landmark detection
  • Tracks 21 hand landmarks (fingertips, joints, etc.)
  • Provides hand skeleton visualization

3. Gesture Classifier (src/gesture_classifier.py)

  • Analyzes hand landmarks to classify gestures
  • Currently supports:
    • Index Finger Up: Landmark 8 (fingertip) above landmark 6 (joint)
    • Fist: All fingers closed

4. Volume Control (src/volume_control.py)

  • Interfaces with Windows audio system using pycaw
  • Provides volume get/set functionality
  • Handles volume range mapping (0-100%)

Hand Landmarks

MediaPipe detects 21 hand landmarks:

  • Landmarks 0-4: Thumb
  • Landmarks 5-8: Index finger
  • Landmarks 9-12: Middle finger
  • Landmarks 13-16: Ring finger
  • Landmarks 17-20: Pinky

๐Ÿ” Troubleshooting

Common Issues

1. Camera Not Found

Error: Could not open camera!

Solution: Check if your webcam is connected and not in use by another application.

2. MediaPipe Import Error

ModuleNotFoundError: No module named 'mediapipe'

Solution: Install MediaPipe for your Python version:

pip install mediapipe

3. Volume Control Not Working

Solution: Ensure you're running on Windows and have pycaw installed:

pip install pycaw

4. Poor Hand Detection

Solutions:

  • Improve lighting conditions
  • Keep hand clearly visible
  • Adjust distance from camera
  • Check detection confidence settings

Performance Tips

  • Use a good quality webcam for better detection
  • Ensure adequate lighting
  • Close unnecessary applications to free up system resources
  • Adjust confidence thresholds in config.py if needed

๐Ÿšง Future Enhancements

  • Support for more gestures (thumbs up, peace sign, etc.)
  • Gesture recording and custom gesture training
  • Support for multiple hands
  • Cross-platform volume control
  • GUI interface
  • Gesture history and statistics
  • Machine learning-based gesture recognition

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • MediaPipe - Hand tracking and detection
  • OpenCV - Computer vision library
  • pycaw - Windows audio control

๐Ÿ“ž Support

If you encounter any issues or have questions:

  1. Check the troubleshooting section above
  2. Search existing issues in the repository
  3. Create a new issue with detailed information

Made with โค๏ธ for computer vision enthusiasts

About

This project uses MediaPipe and OpenCV to detect hand gestures from a webcam and control the Windows system volume. It calculates the distance between thumb and index finger to set the volume level and displays a visual volume bar with feedback on the video feed.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages