A real-time computer vision system that leverages facial feature analysis and machine learning to detect driver/operator fatigue and prevent accidents through timely alerts
A real-time computer vision system for detecting driver fatigue using facial landmarks, eye tracking, and drowsiness detection.
This system monitors a person's face in real-time to detect signs of fatigue by:
- Tracking eye closure patterns
- Calculating Eye Aspect Ratio (EAR)
- Detecting yawning using Mouth Aspect Ratio (MAR)
- Providing real-time audio-visual alerts
- Logging drowsiness events and capturing screenshots
fatigue_detection/
├── data/
│ ├── raw/
│ │ └── CEW Dataset/ # Dataset for validation
│ └── processed/
│ ├── logs/ # Event logs
│ ├── screenshots/ # Drowsiness event captures
│ └── validation/ # Validation results
├── src/
│ └── feature_extraction.py # Main detection code
├── requirements.txt
└── alert.wav # Alert sound file
- Webcam
- Audio output device
- Minimum 4GB RAM
- CPU with SSE4.1 or higher support
- Python 3.8 or higher
- pip (Python package installer)
- Clone the repository:
git clone https://github.com/Aarchishya/fatigue_detection.git
cd fatigue_detection- Create and activate a virtual environment:
# Windows
python -m venv venv
venv\Scripts\activate
# Linux/Mac
python -m venv venv
source venv/bin/activate- Install required packages:
pip install -r requirements.txtopencv-python==4.8.0
mediapipe==0.10.0
numpy==1.24.3
scipy==1.11.1
pygame==2.5.0
tqdm==4.65.0
For validation, the system uses the CEW (Closed Eyes in the Wild) dataset:
- Download from: https://www2.fpce.uc.pt/~lmv/downloads/databases/CEW_v2/
- Extract to:
data/raw/CEW Dataset/ - Structure:
CEW Dataset/ ├── Open Eyes/ └── Closed Eyes/
python src/feature_extraction.pypython src/feature_extraction.py --validate- Press 'q' to quit
- Press 'p' to pause/resume
- Press 'm' to toggle metrics display
- Face mesh detection using MediaPipe
- Eye closure monitoring
- Yawn detection
- Visual alerts on screen
- Audio alerts for drowsiness
- Timestamps of drowsy events
- EAR and MAR values
- Screenshots of drowsy moments
- Validation metrics
- Dataset-based validation
- Accuracy metrics
- Threshold optimization
- Performance analysis
- Location:
data/processed/logs/drowsiness_log.csv - Format: CSV with columns:
- Timestamp
- Event Type
- EAR Value
- Screenshot Path
- Location:
data/processed/screenshots/ - Format: JPEG images
- Naming:
drowsy_YYYYMMDD_HHMMSS.jpg
- Location:
data/processed/validation/validation_results.txt - Contains:
- Accuracy metrics
- EAR statistics
- Suggested thresholds
-
Camera not detected
- Check camera connections
- Verify camera permissions
- Try different camera index in code
-
Audio alerts not working
- Check audio device
- Verify 'alert.wav' exists
- Check pygame installation
-
High CPU usage
- Lower camera resolution
- Increase frame skip
- Close background applications
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request