Driver Drowsiness Detection System โ Real-Time Monitoring
A comprehensive Deep Learning and Computer Vision project designed to detect and alert instances of driver drowsiness in real-time. The system leverages multiple detection mechanisms, including a Custom Convolutional Neural Network (CNN), MediaPipe Face Mesh for Eye Aspect Ratio (EAR), and Haar Cascades. It provides a robust and hybrid detection approach hosted on a responsive Flask-based web application.
๐ Features
- Multiple Detection Modes: Ability to switch between MediaPipe EAR, Haar Cascades, and Custom Keras CNN.
- Hybrid Approach: Combines multiple models together to guarantee high accuracy and avoid false positives.
- Custom Deep Learning Model: A tailored CNN architecture compiled to specifically classify eye images as Open or Closed.
- Real-Time Web Interface: Seamless interactive frontend built using HTML, CSS, and JS, communicating with a Flask API for frame processing.
๐ ๏ธ Technologies Used
- TensorFlow & Keras: For building, compiling, and predicting with the custom CNN.
- OpenCV & MediaPipe: For real-time face mesh landmark detection, eye cropping, and frame rendering.
- Flask & Python: Robust backend to receive camera feeds, process images securely, and return drowsiness statuses.
- HTML, CSS & JavaScript: Front-end stack used for the responsive UI and interacting with webcams.
๐ Project Structure
The project follows a standard and modular structure structure:
app.py- The Flask web server handling real-time video frame processing and logiccreate_cnn_model.py- Script used to build and compile the CNN architecturetemplates/index.html- The web application frontend UIdrowsiness_cnn_model.h5- Pre-trained model weights for drowsiness detection
๐ Getting Started & How It Works
1. The Tracking Mechanism
The system uses MediaPipe's Face Mesh to extract precise facial landmarks. It isolates the region of the eyes (LEFT_EYE and RIGHT_EYE coordinates) and calculates the Eye Aspect Ratio (EAR) based on Euclidean distances.
2. Neural Network Classification
If CNN mode is enabled, the system crops the precise location of the eyes, normalizes the frame, resizes it to 64x64, and passes it through the trained Keras CNN. The output accurately informs the system whether both eyes are closed.
3. Real-Time Processing
Captured webcam frames are converted into base64 images, sent via HTTP POST to the Flask server, processed for drowsiness detection, and returned alongside status markers and visual bounding boxes over the eyes.
๐งช Try It Live & View Code
Click here to try the Driver Drowsiness System Demo
View the source code on GitHub
๐ Final Thoughts
This project underscores the immense potential of integrating distinct machine learning techniques into a single, cohesive unit. Combining deep learning classifiers with classical computer vision and heuristic frameworks (EAR) provides a highly reliable safety system.
๐ Connect with Me
๐ www.tauqueeralam.com
๐ฑ LinkedIn | GitHub
View a live demo below:
View Demo
Discussion