Made with ❤️ by Niraj Lunavat
We will be making a drowsiness detection system.Drowsiness detection is a safety technology that can prevent accidents that are caused by drivers who fell asleep while driving. A countless number of people drive on the highway day and night. Taxi drivers, bus drivers, truck drivers and people traveling long-distance suffer from lack of sleep. Due to which it becomes very dangerous to drive when feeling sleepy. The majority of accidents happen due to the drowsiness of the driver. Its computer vision system that can detect driver drowsiness in a real-time video stream and then play an alarm if the driver appears to be drowsy. This code can detect your eyes and alert when the user is drowsy.
The system analyzes the video frames to detect facial landmarks and track eye movements and blinks. Based on these features, it estimates the driver's or user's level of drowsiness and triggers an alert if it detects signs of fatigue or inattention.
The system includes two main components:
- Face detection and landmarks: This component uses a pre-trained Haar cascade classifier to detect the face region in each video frame. Then, it applies a facial landmarks detector to identify the key points in the face, such as the eyes, eyebrows, nose, and mouth.
- Drowsiness detection: This component tracks the eye aspect ratio (EAR), which is a measure of how open or closed the eyes are. When the eyes close or blink, the EAR drops significantly, indicating drowsiness or fatigue. The system also measures the time between blinks and the duration of closed eyes to estimate the user's level of drowsiness.
The example code is in Python (version 3.5 or higher will work). You can download a trained facial shape predictor from here. If you face any problem then raise an issue.
- OpenCV
- Scipy
- Imutils
- Dlib
Each eye is represented by 6 (x, y)-coordinates, starting at the left-corner of the eye (as if you were looking at the person), and then working clockwise around the eye.
It checks 22 consecutive frames and if the Eye Aspect ratio is less than 0.25, Alert is generated.
To run the code, type python Drowsiness Detection.py
If you want to contribute to the project, feel free to submit issues, feature requests, or pull requests on the GitHub repository.
- Adrian Rosebrock, PyImageSearch Blog
- Driver Drowsiness Detection System with OpenCV & Keras
- for Dataset, Checkout Kaggle