This project implements a drowsiness detection system using Python, OpenCV, and Dlib. The system detects the drowsiness of a driver by monitoring their eye aspect ratio (EAR) and displays a warning message on the screen when drowsiness is detected.
- Real-time drowsiness detection using a webcam.
- Uses Dlib's pre-trained facial landmark predictor.
- Calculates the eye aspect ratio to detect drowsiness.
- Displays warning messages on the screen when drowsiness is detected.
For a detailed explanation of the code, see Code Explanation
- Python 3.x
- OpenCV
- Dlib
- Scipy
- Time
-
Clone this repository to your local machine:
https://github.com/prakash-kannaiah/Drowsiness_Detection.git cd drowsiness-detection
-
Create and activate a new Python virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install the required packages:
pip install -r requirements.txt
-
Download the facial landmark predictor model and place it in the
shape
directory: -
Extract the
.bz2
file:On Windows:
-
Using 7-Zip:
- Right-click the
.bz2
file in File Explorer. - Select
7-Zip
>Extract to "shape_predictor_68_face_landmarks.dat\"
.
- Right-click the
-
Using WinRAR:
- Right-click the
.bz2
file in File Explorer. - Select
Extract Here
orExtract to "shape_predictor_68_face_landmarks.dat\"
.
- Right-click the
Alternatively, you can use the following command in a command prompt if you have
bzip2
installed:bzip2 -d shape/shape_predictor_68_face_landmarks.dat.bz2
This will extract the file directly into the
shape
folder asshape_predictor_68_face_landmarks.dat
.If you don’t have
bzip2
installed, you can download it from the GnuWin32 project or use the GUI tools mentioned above. -
drowsiness-detection/
- shape/shape_predictor_68_face_landmarks.dat
- drowsiness_detection.py
- requirements.txt
Run the drowsiness detection script:
python drowsiness_detection.py
We welcome contributions to improve this project! Here are some guidelines to get started:
-
Fork the Repository: Click on the "Fork" button at the top right of this repository page to create a copy of this repository under your GitHub account.
-
Clone the Repository: Use
git clone
to clone the forked repository to your local machine.git clone https://github.com/your-username/drowsiness-detection.git cd drowsiness-detection
-
Create a New Branch: Create a new branch for your feature or bugfix.
git checkout -b my-new-feature
-
Make Changes: Make your changes to the codebase, ensuring you follow the existing code style and add appropriate tests if needed.
-
Commit Your Changes: Commit your changes with a meaningful commit message.
git commit -m "Add a meaningful commit message here"
-
Push to Your Fork: Push your changes to your forked repository.
git push origin my-new-feature
-
Open a Pull Request: Go to the original repository on GitHub and open a pull request with a clear description of your changes.
Thank you for contributing!
This project is licensed under a custom license. You are free to use, copy, modify, and distribute the code and associated documentation, provided that you include the original copyright notice and adhere to the following condition:
- Non-Commercial Use: This project may not be sold or otherwise used for commercial purposes. Redistribution or use of this project for commercial purposes, including but not limited to selling or licensing, is not permitted.
For more details, please refer to the LICENSE file in this repository.