A Python project using OpenCV and MediaPipe for real-time hand and face detection via webcam.
- Hand Detection: Detection and tracking of up to 4 hands simultaneously
- Face Detection: Face detection with bounding boxes
- Gesture Recognition: Real-time gesture recognition using LSF (Langue des Signes Française)
- Real-time Interface: Live display via webcam
cam.py: Complete version with hand AND face detectioncamera.py: Simplified version with hand detection onlysigne.py: Gesture recognition using MediaPipe Gesture Recognizerpredict.py: Sign language prediction using trained ML modelhand_detection.py: Data collection tool for capturing hand landmarkstrain.py: Train the LSF classifier modeldownload_models.py: Download required MediaPipe models
- Python 3.7 or higher
- Connected webcam
- Internet connection (for downloading MediaPipe models)
-
Clone or download this project
-
Run the installation script:
Windows:
install.bat
Linux/macOS:
chmod +x install.sh ./install.sh
This will:
- Create a Python virtual environment
- Install all required dependencies
- Download MediaPipe model files (hand_landmarker.task, gesture_recognizer.task)
Windows:
python -m venv venv
venv\Scripts\activateLinux/macOS:
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtpython download_models.pyThis downloads:
hand_landmarker.task- Hand landmark detection modelgesture_recognizer.task- Gesture recognition model
python cam.pypython camera.pypython signe.pyRequires a trained model (lsf_model.pkl). Train it first with:
python hand_detection.py
python train.py
python predict.py-
Collect hand landmark data:
python hand_detection.py
- Press 's' to save hand positions
- Press 'a' to quit
- Data saved to
data/folder
-
Train the model:
python train.py
- Creates
lsf_model.pkl - Displays training accuracy
- Creates
-
Use the trained model:
python predict.py
- Press 'a' to quit the application
- Press 's' (in hand_detection.py) to capture hand landmarks
- Camera window displays in real-time
- OpenCV: Image processing and video capture
- MediaPipe: Hand, face, and gesture detection
- NumPy: Numerical computations
- scikit-learn: Machine learning models
- Default resolution: 640x480 pixels
- Hand detection confidence: 0.7
- Hand tracking confidence: 0.4
- Support for up to 4 hands simultaneously
- ML Model: Random Forest Classifier with 200 estimators
- "No module named mediapipe": Run
pip install -r requirements.txt - "hand_landmarker.task not found": Run
python download_models.py - Camera not working: Ensure webcam is connected and not in use by another app
- Slow performance: Reduce video resolution or decrease detection confidence