A real-time system for detecting driver drowsiness using computer vision and facial landmarks detection. This system monitors a driver's eyes and alerts them when signs of drowsiness are detected.
- Real-time face detection using Haar Cascades and dlib
- Eye state monitoring using Eye Aspect Ratio (EAR)
- Facial landmarks detection for precise eye tracking
- Audio alerts when drowsiness is detected
- Multiple detection methods (Haar Cascade and dlib) for comparison
- Face direction monitoring for distraction detection
- Yawn detection for additional drowsiness indicators
driver-drowsiness-detection/ ├── data/ │ ├── alert_sounds/ # Alert sound files │ │ ├── alert-sound.mp3 │ │ ├── focus.mp3 │ │ └── take_a_break.mp3 │ ├── database/ # Shape predictor data file │ │ └── shape_predictor_68_face_landmarks.dat │ ├── images/ # Output directory for eye images │ └── xml/ # Haar cascade classifier files │ ├── haarcascade_eye.xml │ ├── haarcascade_frontalface_alt.xml │ ├── haarcascade_frontalface_alt2.xml │ ├── haarcascade_frontalface_alt_tree.xml │ └── haarcascade_frontalface_default.xml └── src/ # Source code ├── final_integration.py # Main implementation with all features ├── main.py # Basic implementation using Haar cascades ├── main_dlib.py # Implementation using dlib └── train.py # Training utility for eye state detection - Python 3.x
- OpenCV (
cv2) - dlib
- numpy
- imutils
- matplotlib
- python-vlc
- Clone the repository:
git clone https://github.com/LohiyaH/DrowsinessGuard.git cd driver-drowsiness-detection- Install the required dependencies:
pip install opencv-python dlib numpy imutils matplotlib python-vlc- Download the shape predictor file:
- Download
shape_predictor_68_face_landmarks.datfrom dlib's official website - Place it in the
data/database/directory
The project provides three different implementations:
- Basic Implementation (main.py)
python src/main.py- Uses Haar cascades for face and eye detection
- Saves detected eye images to data/images/
- Dlib Implementation (main_dlib.py)
python src/main_dlib.py- Uses dlib for facial landmark detection
- More accurate than Haar cascade method
- Includes basic drowsiness detection
- Full Featured Implementation (final_integration.py)
python src/final_integration.py- Combines all features including:
- Face direction monitoring
- Yawn detection
- Advanced drowsiness detection
- Multiple alert thresholds
- Audio alerts
-
Face Detection: The system first detects the driver's face using either Haar cascades or dlib's face detector.
-
Facial Landmarks: Using dlib's facial landmark predictor, 68 points on the face are detected, including 6 points for each eye.
-
Eye Aspect Ratio (EAR): The system calculates the eye aspect ratio to determine if the eyes are closed:
EAR = (||p2-p6|| + ||p3-p5||) / (2||p1-p4||)where p1, ..., p6 are the 2D landmark points around the eye.
-
Drowsiness Detection: If the EAR falls below a threshold for a certain number of consecutive frames, the system triggers an alert.
-
Additional Features:
- Face direction monitoring to detect distraction
- Yawn detection using mouth aspect ratio
- Multiple alert levels based on drowsiness severity
Contributions are welcome! Please feel free to submit a Pull Request.
This project is under MIT License.
- The shape predictor model is provided by dlib
- Haar cascade classifiers are from OpenCV's repository