Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš— DrowsiGuard

AI-Powered Real-Time Driver Drowsiness Detection System

A real-time driver monitoring system that detects fatigue, distraction, and drowsiness using Computer Vision, MediaPipe Face Mesh, and a CNN-LSTM deep learning model.

Python TensorFlow OpenCV MediaPipe License


๐Ÿ“Œ Overview

Driver fatigue is one of the leading causes of road accidents worldwide. Traditional driver monitoring systems often rely on a single indicator such as eye closure, making them susceptible to false positives.

DrowsiGuard addresses this challenge by combining multiple physiological and behavioral indicators to provide more reliable driver state detection.

The system continuously analyzes:

  • ๐Ÿ‘๏ธ Eye closure
  • ๐Ÿ˜ฎ Yawning
  • โ†” Head movement
  • ๐Ÿง  CNN-LSTM temporal prediction

These signals are fused to classify the driver's condition and generate timely alerts before fatigue becomes dangerous.


๐ŸŒŸ Key Highlights

  • ๐Ÿš— Real-time driver monitoring
  • ๐Ÿง  CNN-LSTM temporal deep learning model
  • ๐Ÿ‘๏ธ MediaPipe Face Mesh based facial landmark detection
  • ๐Ÿ˜ด Multi-feature decision fusion
  • ๐Ÿšฆ Four-stage driver state classification
  • ๐Ÿ”Š Intelligent alert generation
  • โšก Low-latency webcam inference

โœจ Features

  • Real-time webcam monitoring
  • Eye Aspect Ratio (EAR) based eye closure detection
  • Mouth Aspect Ratio (MAR) based yawning detection
  • Head Yaw Angle estimation
  • CNN-LSTM based temporal drowsiness prediction
  • Driver distraction detection
  • Multi-stage driver state classification
  • Intelligent alert system

๐Ÿ“ธ System Output

The following screenshots demonstrate the different driver states detected by DrowsiGuard.

๐ŸŸข Alert / Vigilant ๐ŸŸก Slightly Drowsy
๐ŸŸ  Distracted ๐Ÿ”ด Critical Drowsy

๐Ÿ› ๏ธ Tech Stack

Category Technologies
Programming Language Python
Deep Learning TensorFlow, Keras
Computer Vision OpenCV
Facial Landmark Detection MediaPipe Face Mesh
Numerical Computing NumPy
Visualization Matplotlib
Development Environment Jupyter Notebook

๐Ÿ“‚ Project Structure

DrowsiGuard/
โ”‚
โ”œโ”€โ”€ model/
โ”‚   โ”œโ”€โ”€ cnn_lstm_model.py
โ”‚   โ””โ”€โ”€ drowsiguard_cnn_lstm.h5
โ”‚
โ”œโ”€โ”€ notebooks/
โ”‚   โ”œโ”€โ”€ data_preprocessing.ipynb
โ”‚   โ””โ”€โ”€ model_training_log.ipynb
โ”‚
โ”œโ”€โ”€ screenshots/
โ”‚   โ”œโ”€โ”€ alert_vigilant.jpg
โ”‚   โ”œโ”€โ”€ slightly_drowsy.jpg
โ”‚   โ”œโ”€โ”€ distracted.jpg
โ”‚   โ””โ”€โ”€ critical_drowsy.jpeg
โ”‚
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ alerts.py
โ”‚   โ”œโ”€โ”€ create_placeholder_data.py
โ”‚   โ”œโ”€โ”€ drowsiness_logic.py
โ”‚   โ”œโ”€โ”€ feature_functions.py
โ”‚   โ””โ”€โ”€ tracking_module.py
โ”‚
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ requirements.txt

โš™๏ธ Installation

Clone the Repository

git clone https://github.com/mik07005/DrowsiGuard.git

cd DrowsiGuard

Create a Virtual Environment

Windows

python -m venv venv

venv\Scripts\activate

Linux / macOS

python3 -m venv venv

source venv/bin/activate

Install Dependencies

pip install -r requirements.txt

๐Ÿ“ฆ Dataset

The training datasets are not included in this repository because of licensing restrictions and repository size limitations.

Datasets used during development:

  • Closed Eyes in the Wild (CEW)
  • YawDD (Yawning Detection Dataset)

Data Preprocessing

Metric Value
Closed Eye Images 1500
Open Eye Images 1500
Total Processed Images 3000
Temporal Sequences Generated 2971
Sequence Length 30 Frames

๐Ÿง  Model

DrowsiGuard uses a hybrid CNN-LSTM architecture for temporal driver drowsiness detection.

The CNN extracts spatial features from consecutive eye images, while the LSTM learns temporal eye movement patterns across multiple frames to distinguish between alert and drowsy states.

Input Configuration

Parameter Value
Sequence Length 30 Frames
Image Resolution 64 ร— 64
Channels 1 (Grayscale)
Model CNN-LSTM

โ–ถ๏ธ Running the Project

python src/tracking_module.py

The webcam will automatically start and begin monitoring the driver's state.


๐Ÿ” System Pipeline

flowchart TD

A[Webcam Input]
B[MediaPipe Face Mesh]
C[Extract Facial Landmarks]
D[EAR โ€ข MAR โ€ข Head Pose]
E[CNN-LSTM Model]
F[Decision Fusion]
G[Driver State]
H[Audio Alert]

A --> B
B --> C
C --> D
D --> E
E --> F
F --> G
G --> H
Loading

๐Ÿ“Š Detection Parameters

The system continuously monitors multiple physiological and behavioral indicators.

Parameter Purpose
๐Ÿ‘๏ธ Eye Aspect Ratio (EAR) Detect prolonged eye closure
๐Ÿ˜ฎ Mouth Aspect Ratio (MAR) Detect yawning
โ†” Head Yaw Angle Detect driver distraction
๐Ÿง  CNN-LSTM Probability Predict temporal drowsiness
๐Ÿšจ Decision Fusion Combine all features for final prediction

๐Ÿ“ˆ Model Performance

Metric Value
Training Accuracy 98.95%
Best Validation Accuracy 99.33%
Validation Loss 0.0384
Training Epochs 50
Input Resolution 64 ร— 64
Sequence Length 30 Frames

๐Ÿšฆ Driver States

State Description
๐ŸŸข Alert / Vigilant Driver is attentive and no fatigue is detected.
๐ŸŸก Slightly Drowsy Early signs of fatigue are detected.
๐ŸŸ  Distracted Driver is looking away or appears distracted.
๐Ÿ”ด Critical Drowsy High-confidence drowsiness detected and immediate alert triggered.

๐Ÿ’ก Why DrowsiGuard?

Unlike conventional driver monitoring systems that rely on a single fatigue indicator, DrowsiGuard combines multiple complementary features to improve reliability.

The system fuses:

  • ๐Ÿ‘๏ธ Eye Aspect Ratio (EAR)
  • ๐Ÿ˜ฎ Mouth Aspect Ratio (MAR)
  • โ†” Head Pose Estimation
  • ๐Ÿง  CNN-LSTM Temporal Prediction

These signals are combined using a multi-feature decision fusion strategy to classify four driver states and trigger alerts only when necessary, reducing false alarms.


๐Ÿš€ Future Scope

  • Raspberry Pi deployment
  • Infrared camera support
  • Mobile application integration
  • Cloud dashboard
  • Driver fatigue analytics
  • Night-time performance optimization
  • Multi-driver support

๐Ÿค Contributing

Contributions are welcome.

  1. Fork the repository.

  2. Create a feature branch.

git checkout -b feature-name
  1. Commit your changes.
git commit -m "Add new feature"
  1. Push the branch.
git push origin feature-name
  1. Open a Pull Request.

๐Ÿ“„ License

This project is licensed under the MIT License.

See the LICENSE file for more details.


๐Ÿ‘จโ€๐Ÿ’ป Author

Mohammed Intekhab Khan

B.Tech Computer Science & Engineering (Artificial Intelligence & Machine Learning)

VIT-AP University

GitHub: https://github.com/mik07005


โญ If you found this project useful, consider giving it a Star!

About

AI-powered real-time driver drowsiness detection using CNN-LSTM, MediaPipe Face Mesh, OpenCV, and TensorFlow for enhanced road safety.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages