Drowsiness detection is a safety technology that can prevent accidents that are caused by drivers who fell asleep while driving. The objective of this project is to build a drowsiness detection system that will detect drowsiness through the implementation of computer vision system that automatically detects drowsiness in real-time from a live video stream and then alert the user with an alarm notification.
According to the National Highway Traffic Safety Administration, every year about 100,000 police-reported crashes involve drowsy driving. These crashes result in more than 1,550 fatalities and 71,000 injuries. The real number may be much higher, however, as it is difficult to determine whether a driver was drowsy at the time of a crash. So, we tried to build a system, that detects whether a person is drowsy and alert him.
- OpenCV Library - Most used computer vision library. Highly efficient. Facilitates real-time image processing.
- imutils library - A collection of helper functions and utilities to make working with OpenCV easier.
- Dlib library - Implementations of state-of-the-art CV and ML algorithms (including face recognition).
- scikit-learn library - Machine learning in Python. Simple. Efficient. Beautiful, easy to use API.
- Numpy - NumPy is the fundamental package for scientific computing with Python.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Install and set up Python 3.
- Install cmake in your system
-
Clone the repository.
git clone https://github.com/AnshumanSrivastava108/Real-Time-Drowsiness-Detection-System
-
Move into the project directory.
cd Real-Time-Drowsiness-Detection-System
-
(Optional) Running it in a virtual environment.
- Downloading and installing virtualenv.
pip install virtualenv
- Create the virtual environment in Python 3.
virtualenv -p C:\Python37\python.exe test_env
-
Activate the test environment.
- For Windows:
test_env\Scripts\Activate
- For Unix:
source test_env/bin/activate
-
Install all the required libraries, by installing the requirements.txt file.
pip install -r requirements.txt
-
Installing the dlib library.
-
If you are using a Unix machine, and are facing some issues while trying to install the dlib library, follow this guide.
-
If you are using a Windows machine, install cmake and restart your terminal.
-
-
Run the application.
python Real-Time-Drowsiness-Detection-System.py --shape-predictor shape_predictor_68_face_landmarks.dat --alarm Alert.wav
- Capture the image of the driver from the camera.
- Send the captured image to haarcascade file for face detection.
- If the face is detected then crop the image consisting of the face only. If the driver is distracted then a face might not be detected, so play the buzzer.
- Send the face image to haarcascade file for eye detection.
- If the eyes are detected then crop only the eyes and extract the left and right eye from that image. If both eyes are not found, then the driver is looking sideways, so sound the buzzer.
- The cropped eye images are sent to the hough transformations for detecting pupils, which will determine whether they are open or closed.
- If they are found to be closed for five continuous frames, then the driver should be alerted by playing the buzzer.
For a more detailed explanation of this project check Real_Time_Drowsiness_Detection_System.pdf.
The tests were conducted in various conditions including:
- Different lighting conditions.
- Drivers posture and position of the automobile drivers face.
- Drivers with spectacles.
Test case 1: When there is ambient light
Result: As shown above, when there is ambient amount of light, the automobile driver's face and eyes are successfully detected.
Test case 2: Position of the automobile drivers face
- Centre Positioned
Result: As shown in above, When the automobile driver's face is positioned at the Centre, the face, eyes, eye blinks, and drowsiness was successfully detected.
- Right Positioned
Result: As shown in above, When the automobile driver's face is positioned at the Right, the face, eyes, eye blinks, and drowsiness was successfully detected.
- Left Positioned
Result: As shown in screen snapshot in above, when the automobile driver's face is positioned at the Left, the face, eyes, eye blinks, and drowsiness was successfully detected.
Test case 3: When the automobile driver is wearing spectacles
Result: As shown in screen snapshot in above, When the automobile driver is wearing spectacles, the face, eyes, eye blinks, and drowsiness was successfully detected.
Test case 4: When the automobile driver’s head s tilted
Result: As shown in screen snapshot in above, when the automobile driver's face is tilted for more than 30 degrees from vertical plane, it was observed that the detection of face and eyes failed.
The system was extensively tested even in real world scenarios, this was achieved by placing the camera on the visor of the car, focusing on the automobile driver. It was found that the system gave positive output unless there was any direct light falling on the camera.
Smart phone application: It can be implemented as a smart phone application, which can be installed on smart phones. And the automobile driver can start the application after placing it at a position where the camera is focused on the driver.
IEEE standard Journal Paper,
[1] Facial Features Monitoring for Real Time Drowsiness Detection by Manu B.N, 2016 12th International Conference on Innovations in Information Technology (IIT) [Pg. 78-81] (https://ieeexplore.ieee.org/document/7880030)
[2] Real Time Drowsiness Detection using Eye Blink Monitoring by Amna Rahman Department of Software Engineering Fatima Jinnah Women University 2015 National Software Engineering Conference (NSEC 2015) (https://ieeexplore.ieee.org/document/7396336)
Websites referred:
- https://www.codeproject.com/Articles/26897/TrackEye-Real-Time-Tracking-Of-Human-Eyes-
- https://realpython.com/face-recognition-with-python/
- https://www.pyimagesearch.com/2017/04/03/facial-landmarks-dlib-opencv
- https://www.pyimagesearch.com/2017/04/10/detect-eyes-nose-lips-jaw-dlib-opencv
- https://www.codeproject.com/Articles/26897/TrackEye-Real-Time-Tracking-Of-HumanEyesUsing-a
- https://docs.opencv.org/3.4/d7/d8b/tutorial_py_face_detection.html
- https://www.learnopencv.com/training-better-haar-lbp-cascade-eye-detector-opencv/
Anshuman Srivastava
- Twitter: @Anshuman_121
- Github: @AnshumanSrivastava108
- LinkedIn: @AnshumanSrivastava108