Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿค– Gesture Detection System

Python OpenCV MediaPipe License

A real-time gesture detection system with hand and face landmark visualization using MediaPipe and OpenCV

Features โ€ข Installation โ€ข Usage โ€ข Project Structure โ€ข Contributing


๐ŸŽฏ Overview

This project provides a real-time gesture detection system that combines hand gesture recognition and face landmark visualization in a single application. Built with MediaPipe and OpenCV, it offers high accuracy, smooth gesture transitions, and comprehensive landmark visualization for both hands and faces.

๐Ÿš€ Key Highlights

  • Dual Detection: Simultaneous hand gesture recognition and face landmark detection
  • Real-time Performance: Optimized for live webcam feed processing
  • Video Recording: Automatically saves output as output.mp4
  • Fullscreen Display: Optimized for gesture recognition
  • Modular Design: Clean, well-organized codebase for easy extension

โœจ Features

๐Ÿ–๏ธ Hand Gesture Recognition

  • โœŠ Fist Detection - Closed hand recognition
  • ๐Ÿ–๏ธ Open Palm - Extended hand recognition (3+ fingers up with thumb up)
  • ๐Ÿ‘ Thumbs Up - Thumb extended with no other fingers up
  • ๐Ÿ‘Ž Thumbs Down - Thumb pointing down with no other fingers up
  • โ˜๏ธ Index Pointing - Single finger extended (index only)
  • โœŒ๏ธ Peace Sign - Two-finger gesture (index and middle)
  • ๐Ÿค˜ Rock Sign - Index and pinky extended

๐Ÿ‘ค Face Landmark Visualization

  • 468 Face Landmarks - Complete facial feature detection
  • Visual Connections - Lines connecting facial features
  • Real-time Tracking - Live face landmark visualization
  • Green Dots - Same visual style as hand landmarks

๐Ÿ”ง Technical Features

  • Real-time Processing - Live webcam feed support with fullscreen display
  • Video Recording - Automatically saves session as output.mp4
  • Confidence Scoring - 0.0 to 1.0 confidence levels for each gesture
  • Multi-hand Support - Detects up to 2 hands simultaneously
  • FPS Counter - Real-time performance monitoring
  • Landmark Visualization - Complete overlay system

๐Ÿ› ๏ธ Installation

Prerequisites

  • Python 3.8 or higher
  • Webcam or video input device
  • Windows/Linux/macOS

Quick Setup

  1. Clone the repository

    git clone https://github.com/your-username/Hand-gesture-detection.git
    cd Gesture-Detection
  2. Create virtual environment (recommended)

    # Windows
    python -m venv env
    env\Scripts\activate
    
    # Linux/macOS
    python -m venv env
    source env/bin/activate
  3. Install dependencies

    pip install -r requirements.txt

Dependencies

  • opencv-python==4.10.0.84 - Computer vision library
  • mediapipe==0.10.14 - Google's ML framework for pose/face/hand detection
  • numpy==1.26.4 - Numerical computing

โ–ถ๏ธ Usage

Basic Usage

python main.py

Controls

  • Press 'q' to quit the application
  • Fullscreen mode for better visibility
  • Video Recording - Automatically saves as output.mp4

What You'll See

  • Hand Gestures: Real-time detection with confidence scores
  • Face Landmarks: 468 facial points with connections
  • FPS Counter: Performance monitoring
  • Gesture Labels: Current detected gestures
  • Hand Count: Number of detected hands

System Requirements

  • Camera: Built-in webcam or external USB camera
  • Performance: 30+ FPS on modern hardware
  • Memory: ~200MB RAM usage

๐Ÿ—๏ธ Project Structure

Gesture-Detection/
โ”œโ”€โ”€ main.py                     # Main application entry point
โ”œโ”€โ”€ hand_gesture/
โ”‚   โ”œโ”€โ”€ __init__.py            # Package initialization
โ”‚   โ”œโ”€โ”€ capture.py             # Video capture handling
โ”‚   โ”œโ”€โ”€ detection.py           # Hand detection with MediaPipe
โ”‚   โ”œโ”€โ”€ gestures.py            # Hand gesture classification
โ”‚   โ”œโ”€โ”€ face_detection.py      # Face detection with MediaPipe
โ”‚   โ””โ”€โ”€ overlay.py             # UI overlay and visualization
โ”œโ”€โ”€ requirements.txt           # Python dependencies
โ””โ”€โ”€ README.md                  # This file

Key Components

Main Application (main.py)

  • HandGestureApp Class: Main application controller
  • FaceDetector: Face landmark detection
  • Video Recording: Automatic MP4 output
  • FPSCounter: Performance monitoring
  • Fullscreen Display: Optimized for gesture recognition

Detection Pipeline

  1. VideoCapture โ†’ HandDetector โ†’ Landmark Extraction
  2. FaceDetector โ†’ Face Landmark Extraction
  3. Gesture Classification โ†’ Confidence Scoring โ†’ UI Overlay
  4. Video Recording โ†’ Display

โš™๏ธ Configuration

Hand Gesture Thresholds (hand_gesture/gestures.py)

finger_tolerance = 0.04      # Finger detection sensitivity
thumb_clearance = 0.02      # Thumb detection threshold
fist_fold_threshold = 0.5   # Fist detection sensitivity
min_fingers_folded = 2      # Minimum fingers for fist detection

Face Detection Settings (main.py)

max_num_faces = 1           # Maximum faces to detect
min_detection_confidence = 0.5  # Face detection confidence
min_tracking_confidence = 0.5   # Face tracking confidence

Video Recording Settings

output_filename = "output.mp4"  # Output video file
fps = 30.0                     # Recording frame rate
codec = 'mp4v'                 # Video codec

๐ŸŽฎ Demo Results

Hand Gestures

Gesture Detection Method Confidence Range
โœŠ Fist Finger fold detection 0.80-0.85
๐Ÿ–๏ธ Open Palm 3+ fingers + thumb up 0.85+
๐Ÿ‘ Thumbs Up Thumb up only 0.80+
๐Ÿ‘Ž Thumbs Down Thumb down only 0.80+
โ˜๏ธ Index Pointing Index finger only 0.80+
โœŒ๏ธ Peace Sign Index + middle 0.70-0.80
๐Ÿค˜ Rock Sign Index + pinky 0.70-0.75

Face Landmarks

  • 468 Total Landmarks: Complete facial feature detection
  • Key Features: Eyes, eyebrows, nose, mouth, face outline
  • Visual Style: Green dots with red connections (matching hand landmarks)
  • Real-time: Live tracking and visualization

๐Ÿ› Troubleshooting

Common Issues

Camera not detected

# Check camera availability
python -c "import cv2; print(cv2.VideoCapture(0).isOpened())"

Video recording not working

  • Check write permissions in project directory
  • Ensure sufficient disk space
  • Verify MP4 codec support

Low FPS performance

  • Close other applications
  • Ensure good lighting for better detection
  • Check camera focus and positioning

Hand gestures not detected

  • Keep hands clearly visible
  • Ensure good contrast with background
  • Check hand positioning relative to camera

Face landmarks not showing

  • Ensure face is clearly visible
  • Check lighting conditions
  • Verify MediaPipe installation

Installation issues

# Update pip and reinstall
pip install --upgrade pip
pip install -r requirements.txt --force-reinstall

๐Ÿค Contributing

We welcome contributions! Here's how you can help:

Ways to Contribute

  • ๐Ÿ› Bug Reports - Report issues and bugs
  • ๐Ÿ’ก Feature Requests - Suggest new gestures or improvements
  • ๐Ÿ”ง Code Contributions - Submit pull requests
  • ๐Ÿ“– Documentation - Improve documentation and examples
  • ๐Ÿงช Testing - Test on different devices and environments

Development Setup

# Fork the repository
git clone https://github.com/your-username/Hand-gesture-detection.git
cd Gesture-Detection

# Create feature branch
git checkout -b feature/new-gesture

# Make changes and test
python main.py

# Commit and push
git add .
git commit -m "Add new gesture detection"
git push origin feature/new-gesture

Adding New Features

  1. Hand Gestures: Modify hand_gesture/gestures.py
  2. Face Features: Modify hand_gesture/face_detection.py
  3. UI Overlays: Modify hand_gesture/overlay.py
  4. Update Tests: Add test cases for new features
  5. Update Documentation: Update README and comments

๐Ÿ“Š Performance Metrics

System Performance

  • FPS: 30+ FPS on modern hardware
  • Latency: <50ms gesture detection delay
  • Accuracy: 95%+ for common gestures
  • Memory: ~200MB RAM usage
  • CPU: 20-40% CPU usage (depends on hardware)

Video Recording

  • Format: MP4 (MP4V codec)
  • Resolution: Matches camera input (640x480 default)
  • Frame Rate: 30 FPS
  • File Size: ~10-50MB per minute (depends on content)

Supported Platforms

  • โœ… Windows 10/11
  • โœ… macOS 10.15+
  • โœ… Linux (Ubuntu 18.04+)

๐Ÿ“œ License

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


๐Ÿ“ž Support


โญ Star this repository if you found it helpful!

Made with โค๏ธ By [Shazim Javed]

About

A real-time Hand Gesture Detection system built using OpenCV and MediaPipe. It detects multiple gestures

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages