A real-time drowsiness and yawn detection system built with Python, OpenCV, and dlib to help prevent accidents caused by driver fatigue.
- Eye Drowsiness Detection: Monitors eye aspect ratio (EAR) to detect when a person's eyes are closed for too long
- Yawn Detection: Measures lip distance to identify when a person is yawning
- Real-time Alerts: Visual alerts on screen and audio alerts via system speakers
- Easy-to-use Interface: Simple command-line application with webcam support
- Python 3.6+
- OpenCV (
cv2
) - dlib
- imutils
- numpy
- scipy
- espeak (for audio alerts)
-
Clone this repository:
git clone https://github.com/9keystrokes/Driver-Drowsiness-Detection-System.git cd Driver-Drowsiness-Detection-System
-
Install the required packages:
pip install opencv-python dlib imutils numpy scipy
-
Download the shape predictor file:
- Download the 68 facial landmark predictor from dlib's model repository
- Extract the file and place it in the project directory
-
Install espeak for audio alerts:
- Windows: Download and install from espeak official website
- Linux:
sudo apt-get install espeak
- macOS:
brew install espeak
Run the program with:
python drowsiness_yawn.py --webcam 0
Where:
--webcam
(or-w
): specifies the webcam index (default is 0 for the built-in webcam)
- Face Detection: Uses a Haar Cascade classifier to detect faces in the video stream
- Facial Landmarks: Uses dlib's 68-point facial landmark detector to identify key points on the face
- Eye Aspect Ratio (EAR): Calculates the ratio of distances between facial landmarks to determine if eyes are closed
- Lip Distance: Measures the distance between upper and lower lips to detect yawning
- Alert System: Triggers visual and audio alerts when drowsiness or yawning is detected
- Press
q
to quit the application
- EYE_AR_THRESH: 0.3 (Eye aspect ratio threshold below which eyes are considered closed)
- EYE_AR_CONSEC_FRAMES: 30 (Number of consecutive frames eyes must be closed to trigger drowsiness alert)
- YAWN_THRESH: 20 (Lip distance threshold above which a yawn is detected)
haarcascade_frontalface_default.xml
: Haar Cascade classifier for face detectionshape_predictor_68_face_landmarks.dat
: Trained model for facial landmark detection
- This project uses the facial landmark detection algorithm from dlib
- Inspired by various computer vision techniques for fatigue detection
- Richardson, Matt, and Shawn Wallace. Getting Started with Raspberry Pi. O'Reilly Media, 2012.
- Zhao, C. W., Jegatheesan, J., & Loon, S. C. (2015). Exploring IoT with Raspberry Pi.
- Halfacree, Gareth, and Eben Upton. Raspberry Pi User Guide. John Wiley & Sons, 2012.
- Blood Cell Counting Using Image Processing
- Drowsiness Detection Study - NCBI