Alert drowsy driver using OpenCV
Accidents due to driver being drowsy are very frequent and a major reasons for a lot of deaths. With computer vision, machine learning advancing we can use this knowledge to help avoid these accidents. Our program will find whether the driver is drowsy/eyes closed for more than a threshold value (we gave it 20 seconds) and if it crosses the threshold a loud sounding alarm will be played helping/causing driver to wake up and then do appropriate actions. A very useful project in real world.
Code Description & Execution
So, we have used *Convolutional neural networks* to identify whether a person is drowsy or not, as we all know, how sophisticated CNNs are and how they can learn almost anything like a brain does, this can help us save a lot of time and also giving almost accurate predictions for the disease. As we discussed convolutional neural networks are very sophisticated and more advanced version of neural networks, these are very superior to other neural networks which works better with images and audio/speech input signal. A CNN network comprises of 3 important layers such as a convolutional layer, pooling layer and fully connected layer. we can have as many layers as possible depending on the domain and project we are working on.
How to Execute?
So, before execution we have some pre-requisites that we need to download or install i.e., anaconda environment, python and a code editor.
Anaconda: Anaconda is like a package of libraries and offers a great deal of information which allows a data engineer to create multiple environments and install required libraries easy and neat.
Refer to this link, if you are just starting and want to know how to install anaconda.
If you already have anaconda and want to check on how to create anaconda environment, refer to this article set up jupyter notebook. You can skip the article if you have knowledge of installing anaconda, setting up environment and installing requirements.txt
1. Install necessary libraries from requirements.txt file provided.
2. Go to the directory where your requirement.txt file is present.
CD<>. E.g, If my file is in d drive, then
- CD D:
- CD D:\License-Plate-Recognition-main #CHANGE PATH AS PER YOUR PROJECT, THIS IS JUST AN EXAMPLE
If your project is in c drive, you can ignore step 1 and go with step 2.
Eg. cd C:\Users\Hi\License-Plate-Recognition-main #CHANGE PATH AS PER YOUR PROJECT, THIS IS JUST AN EXAMPLE
3. Run command pip install -r requirements.txt or conda install requirements.txt
(Requirements.txt is a text file consisting of all the necessary libraries required for executing this python file. If it gives any error while installing libraries, you might need to install them individually.)
All the necessary files will get downloaded. To run the code, open anaconda prompt. Go to virtual environment if created or operate from the base itself and start jupyter notebook, open folder where your code is present.
Open “Drowsiess_detection.ipynb” to get the results.
If you want to build your own model for detection, you can go through “drowsiness_detector_using_cnn.ipynb”
The dataset was downloaded from the internet. After going through them, we see that there are a total of 4 categories.
- Closed 2. Open 3. Yawn 4. No_yawn
The dataset has been split into train, test folders containing images of people in different lighting conditions.
Our program will find whether the driver is drowsy/eyes closed for more than a threshold value (we gave it 20 seconds) and if it crosses the threshold a loud sounding alarm will be played helping/causing driver to wake up and then do appropriate actions.
- Ensure you have all libraries installed.
- Give correct paths wherever necessary.
- Make sure you have the appropriate versions of tensorflow and keras.