Driver Sleep Detection is a computer vision-based project designed to monitor driver alertness by detecting signs of drowsiness. This system can be deployed on a Raspberry Pi with a camera mounted on the dashboard to help ensure driver safety during long trips, especially at night.
The primary goal of this project is to enhance road safety by alerting drivers who may be falling asleep. The system is equipped with two key detection features:
- Eye Closure Detection: Alerts are triggered if the driver’s eyes remain closed for a prolonged period.
- Yawn Detection: Warnings are issued if the driver yawns frequently, indicating high levels of fatigue.
This project extends previous work on drowsiness detection by incorporating an additional yawn detection feature.
-
Face Detection: Uses the dlib library to identify faces in the video feed.
-
Eye Coordinates: Determines the coordinates of the eyes on the face. Refer to the image below for details on eye coordinates:
-
Eye Aspect Ratio (EAR): Computes the EAR for each eye using the formula:
-
EAR Calculation: Takes the average EAR for both eyes. If the average EAR falls below a predefined threshold for a specified number of consecutive frames, an alarm is triggered.
-
Threshold Determination: Run the main program (
python main.py
) to record EAR values and adjust the EAR threshold accordingly. Refer to theGraphs\EAR.png
file for a visual representation:
- Yawn Detection: Monitors yawning by calculating the Mouth Aspect Ratio (MAR) and comparing it to a threshold. If MAR exceeds the threshold and multiple yawns are detected within a defined frame range, a warning is issued.
- Parameter Configuration: Adjust yawn detection parameters in the
config.json
file.
- CMake: Download and install CMake and ensure it is added to your Environment Variables.
- Visual Studio: Install Visual Studio from here along with the
CMake tools for Windows
package.
-
Virtual Environment: It is recommended to use a virtual environment. For guidance, refer to this Medium article.
-
Download dlib Models: Obtain the dlib model for face detection from this link.
-
Install Dependencies: Use pip to install the required packages:
pip install -r requirements.txt
-
Run the Code: Execute the following command to start the application:
python main.py
This project was developed using Python 3.7.7 and pip 19.2.3.
For any issues or questions, please reach out to me on LinkedIn: Adnan