Detects driver drowsiness in real-time using eye movement analysis, facial landmarks, and Machine Learning.
Driver fatigue is one of the major causes of road accidents worldwide. Fatigued drivers often experience slower reaction times, reduced attention, and impaired decision-making.
DriverGuard AI addresses this problem through a low-cost, camera-based solution that uses Computer Vision and Machine Learning to detect fatigue-related eye behavior.
The system continuously analyzes:
- Eye Aspect Ratio (EAR)
- Blink Rate
- Eye Closure Duration
- PERCLOS
These features are processed by a trained Random Forest model to classify the driver as:
π’ Focused
or
π΄ Drowsy
When drowsiness is detected, the system triggers an audio alarm and displays real-time fatigue metrics on an interactive dashboard.
Driver drowsiness is a significant contributor to road accidents and fatalities worldwide.
- Fatigue symptoms often go unnoticed by drivers.
- Driver alertness continuously decreases during long journeys.
- Commercial fatigue monitoring systems are expensive.
- Many existing solutions require dedicated sensors and specialized hardware.
Develop a low-cost, real-time fatigue detection system capable of:
- Monitoring driver alertness continuously
- Detecting signs of drowsiness early
- Providing immediate warnings
- Improving overall road safety
DriverGuard AI uses a standard webcam and AI-powered analysis to monitor driver fatigue in real time.
- Capture live video from webcam.
- Detect facial landmarks using MediaPipe Face Mesh.
- Extract eye-related fatigue parameters.
- Compute fatigue indicators.
- Predict driver condition using Machine Learning.
- Trigger alarm when drowsiness is detected.
- Display results on a real-time dashboard.
β Real-Time Webcam Monitoring
β Facial Landmark Detection
β Eye Aspect Ratio (EAR) Calculation
β Blink Rate Analysis
β Eye Closure Duration Monitoring
β PERCLOS Calculation
β Random Forest Prediction Model
β Audio Alarm System
β Fatigue Score Generation
β Confidence Score
β Driver Recommendation System
β Interactive Streamlit Dashboard
flowchart LR
A[π· Driver Webcam]
--> B[π₯ OpenCV Frame Capture]
B
--> C[π§ MediaPipe Face Mesh]
C
--> D[ποΈ Facial Landmark Detection]
D
--> E[π Feature Extraction]
E
--> F1[EAR]
E
--> F2[Blink Rate]
E
--> F3[Eye Closure Duration]
E
--> F4[PERCLOS]
F1 --> G[π€ Random Forest Classifier]
F2 --> G
F3 --> G
F4 --> G
G --> H{Driver State}
H -->|Focused| I[π’ Safe Driving]
H -->|Drowsy| J[π΄ Fatigue Detected]
J --> K[π Audio Alarm]
I --> L[π Dashboard]
J --> L
L --> M[Fatigue Score]
L --> N[Confidence]
L --> O[Recommendation]
EAR measures how open or closed the eye is.
EAR = (A + B) / (2 Γ C)
Where:
- A = First vertical eye distance
- B = Second vertical eye distance
- C = Horizontal eye distance
| EAR Value | State |
|---|---|
| > 0.20 | Eye Open |
| < 0.20 | Eye Closed |
Measures the number of blinks per minute.
Blink Rate = Total Blinks / Time
Higher blink frequency can indicate fatigue.
Measures how long the eyes remain continuously closed.
Closure Duration =
Current Time - Eye Closed Start Time
Longer durations indicate increased drowsiness.
Percentage of Eye Closure.
PERCLOS =
(Closed Eye Frames / Total Frames)
Γ 100
PERCLOS is one of the most widely accepted indicators of driver fatigue.
Random Forest Classifier
- Eye Aspect Ratio (EAR)
- Blink Rate
- Eye Closure Duration
- PERCLOS
| Class | Meaning |
|---|---|
| 0 | Focused |
| 1 | Drowsy |
models/
βββ fatigue_model.pkl
Stored using Joblib for efficient deployment.
DriverGuardAI/
β
βββ app.py
β
βββ models/
β βββ fatigue_model.pkl
β
βββ assets/
β βββ alarm.wav
β
βββ src/
β βββ utils.py
β βββ alarm.py
β
βββ requirements.txt
β
βββ README.md
Download Python 3.11:
https://www.python.org/downloads/release/python-3110/
Verify installation:
python --versionExpected Output:
Python 3.11.x
Some dependencies (such as simpleaudio) may require Microsoft Visual C++ Build Tools during installation.
π https://visualstudio.microsoft.com/visual-cpp-build-tools/
- Open the download link.
- Download Build Tools for Visual Studio.
- Launch the installer.
- Select:
β Desktop development with C++
- In the Installation Details panel, ensure these components are selected:
- MSVC v143 - VS 2022 C++ x64/x86 build tools
- Windows 10 SDK (or Windows 11 SDK)
- C++ CMake tools for Windows
- Click Install.
- Restart your system after installation completes.
Open Command Prompt and run:
clIf installed correctly, you should see output similar to:
Microsoft (R) C/C++ Optimizing Compiler
Version 19.xx.xxxxx for x64
Certain Python packages contain native C/C++ extensions that must be compiled during installation.
Without Build Tools, you may encounter errors such as:
error: Microsoft Visual C++ 14.0 or greater is required
Installing the Build Tools resolves this issue.
git clone <repository-url>cd DriverGuardAIpython -m pip install --upgrade pippy -3.11 -m venv venvActivate Environment:
venv\Scripts\activatesource venv/bin/activatepip install -r requirements.txtstreamlit run app.pyWhen the model predicts:
DROWSY
The system:
- Activates an audio alarm
- Continuously warns the driver
- Stops automatically when the driver returns to a focused state
The dashboard displays:
π’ Focused
π΄ Drowsy
0% β Fully Alert
100% β Highly Fatigued
Prediction confidence produced by the model.
Measures eye openness.
Number of blinks per minute.
Continuous duration of eye closure.
Percentage of time eyes remain closed.
β Face Detection
β Facial Landmark Tracking
β EAR Calculation
β Blink Detection
β Eye Closure Monitoring
β PERCLOS Calculation
β Random Forest Classification
β Audio Alert System
β Real-Time Dashboard
The system successfully detects fatigue-related eye behavior and provides visual and audio alerts to improve driver safety.
- Yawn Detection
- Head Pose Estimation
- Mobile Application
- Cloud Deployment
- Hardware Optimization
- LSTM-Based Temporal Analysis
- Fleet Monitoring Dashboard
- GPS-Based Emergency Alerts
- Night-Time Driver Monitoring
- Lavanya Bani
- Warisha Khan
- Sukriti Singhal
- Aafreen
Dr. Ankit Dixit