Drowsiness Detection System: A Step-by-Step Guide

Jan 25, 2022 | Programming

Drowsiness while driving is a serious issue that can lead to severe accidents. According to the National Highway Traffic Safety Administration, about 100,000 police-reported crashes each year involve drowsy driving. This guide will help you install and run a Drowsiness Detection System that alerts users if they are drowsy. So, let’s get started!

Motivation Behind the Project

Our aim is to create an effective system that can detect drowsiness based on facial landmarks. This system will not only enhance road safety but also potentially save lives by providing timely alerts.

Installing and Configuring dlib

To get started with our Drowsiness Detection System, we need to install dlib, which cannot be installed directly via pip. Follow these straightforward commands to set it up in your Anaconda environment:

Step 1: Update conda

conda update conda

Step 2: Update Anaconda

conda update anaconda

Step 3: Create a Virtual Environment

conda create -n env_dlib

Step 4: Activate the Virtual Environment

conda activate env_dlib

Step 5: Install dlib

conda install -c conda-forge dlib

If all steps are completed successfully, dlib will be installed in your virtual environment env_dlib. Make sure to use this environment for the entire project.

Deactivating the Virtual Environment

conda deactivate

Running the System

Now that we have everything set up, follow these steps to run the Drowsiness Detection System:

Step 1: Clone the repository

git clone https://github.com/fear-the-lord/Drowsiness-Detection.git

You can also download the ZIP file directly.

Step 2: Download the Required File

Get the file bshape_predictor_68_face_landmarks.dat here. Make sure to place it in the same folder as the project.

Step 3: Install System Requirements

pip install -r requirements.txt

Step 4: Run the Application

python app1.py

Step 5: Access the Web Application

Open your browser and type localhost:8000 in the search bar. If this port isn’t available, the Flask application will switch to another port, which you can find in your command prompt. Simply enter that port in your browser.

Understanding the Drowsiness Detection Mechanism

Let’s delve into how the Drowsiness Detection System works, akin to a vigilant gardener observing your garden:

  • The system acts like a gardener who first detects the plants (faces) in the garden (video input) using a frontal face detector.
  • Next, it inspects the health of those plants (facial landmarks) using a landmark predictor that provides critical coordinates for specific facial features, similar to checking the branches (eyebrows and eyes) and leaves (mouth).
  • Only the most important features, the eyes and mouth, are monitored closely to check for signs of drowsiness.
  • The eye aspect ratio (EAR) is calculated with a specific formula just like a gardener measures the growth of plants, helping to decide if the eyes are open or closed.
  • Sufficiently similar methods are applied to calculate the mouth aspect ratio (MAR) to detect yawning.

Results and Output

The GUI is crafted with basic HTML, CSS, and JavaScript using Flask to render the Python code in a web interface. The output monitors and stores frames when drowsiness is detected, helping keep a record of sleepy periods.

Drowsiness Detection Output

Click here to see the demo.

Troubleshooting

Here are some tips if you encounter issues:

  • Ensure your environment is activated properly.
  • Double-check that the required file shape_predictor_68_face_landmarks.dat is in the correct folder.
  • If the web application does not open, verify that Flask is correctly installed, and the right port is being accessed.
  • If your application crashes, consider checking your dependencies in requirements.txt for any specific version requirements.
  • For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Future Scope

We believe this system has immense potential. Future enhancements could involve real-time hosting of the Flask app or integrating advanced machine learning models for better accuracy.

References

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox