Skip to content

About

AI-Based Driver Drowsiness Detection and Monitoring System

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

19 Commits

Folders and files

Repository files navigation

Presentation

πŸš— DriverGuard AI

Real-Time Driver Fatigue Detection System using Computer Vision & Machine Learning

Detects driver drowsiness in real-time using eye movement analysis, facial landmarks, and Machine Learning.

Python OpenCV MediaPipe Scikit-Learn Streamlit


πŸ“Œ Abstract

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.


🎯 Problem Statement

Driver drowsiness is a significant contributor to road accidents and fatalities worldwide.

Challenges

  • 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.

Objective

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

πŸ’‘ Proposed Solution

DriverGuard AI uses a standard webcam and AI-powered analysis to monitor driver fatigue in real time.

Core Functionality

  1. Capture live video from webcam.
  2. Detect facial landmarks using MediaPipe Face Mesh.
  3. Extract eye-related fatigue parameters.
  4. Compute fatigue indicators.
  5. Predict driver condition using Machine Learning.
  6. Trigger alarm when drowsiness is detected.
  7. Display results on a real-time dashboard.

✨ Features

βœ… 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


πŸ—οΈ DriverGuard AI Architecture

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]
Loading

🧠 Fatigue Parameters

1️⃣ Eye Aspect Ratio (EAR)

EAR measures how open or closed the eye is.

Formula

EAR = (A + B) / (2 Γ— C)

Where:

  • A = First vertical eye distance
  • B = Second vertical eye distance
  • C = Horizontal eye distance

Interpretation

EAR Value State
> 0.20 Eye Open
< 0.20 Eye Closed

2️⃣ Blink Rate

Measures the number of blinks per minute.

Blink Rate = Total Blinks / Time

Higher blink frequency can indicate fatigue.


3️⃣ Eye Closure Duration

Measures how long the eyes remain continuously closed.

Closure Duration =
Current Time - Eye Closed Start Time

Longer durations indicate increased drowsiness.


4️⃣ PERCLOS

Percentage of Eye Closure.

PERCLOS =
(Closed Eye Frames / Total Frames)
Γ— 100

PERCLOS is one of the most widely accepted indicators of driver fatigue.


πŸ€– Machine Learning Model

Algorithm Used

Random Forest Classifier

Input Features

  • Eye Aspect Ratio (EAR)
  • Blink Rate
  • Eye Closure Duration
  • PERCLOS

Output Classes

Class Meaning
0 Focused
1 Drowsy

Model Storage

models/
└── fatigue_model.pkl

Stored using Joblib for efficient deployment.

πŸ› οΈ Technology Stack

πŸ“‚ Project Structure

DriverGuardAI/
β”‚
β”œβ”€β”€ app.py
β”‚
β”œβ”€β”€ models/
β”‚   └── fatigue_model.pkl
β”‚
β”œβ”€β”€ assets/
β”‚   └── alarm.wav
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ utils.py
β”‚   └── alarm.py
β”‚
β”œβ”€β”€ requirements.txt
β”‚
└── README.md

βš™οΈ Installation Guide

Step 1: Install Python 3.11

Download Python 3.11:

https://www.python.org/downloads/release/python-3110/

Verify installation:

python --version

Expected Output:

Python 3.11.x

Step 2: Install Microsoft C++ Build Tools (Required)

Some dependencies (such as simpleaudio) may require Microsoft Visual C++ Build Tools during installation.

Download

πŸ”— https://visualstudio.microsoft.com/visual-cpp-build-tools/

Installation Steps

  1. Open the download link.
  2. Download Build Tools for Visual Studio.
  3. Launch the installer.
  4. Select:

βœ… Desktop development with C++

  1. 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
  1. Click Install.
  2. Restart your system after installation completes.

Verify Installation

Open Command Prompt and run:

cl

If installed correctly, you should see output similar to:

Microsoft (R) C/C++ Optimizing Compiler
Version 19.xx.xxxxx for x64

Why is this required?

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.

Step 3: Clone Repository

git clone <repository-url>
cd DriverGuardAI

Step 4: Create Virtual Environment & Upgrade pip

python -m pip install --upgrade pip
py -3.11 -m venv venv

Activate Environment:

Windows

venv\Scripts\activate

Linux / MacOS

source venv/bin/activate

Step 5: Install Dependencies

pip install -r requirements.txt

Step 6: Run Application

streamlit run app.py

πŸ”Š Alarm System

When the model predicts:

DROWSY

The system:

  • Activates an audio alarm
  • Continuously warns the driver
  • Stops automatically when the driver returns to a focused state

πŸ“Š Dashboard Metrics

The dashboard displays:

Driver Status

🟒 Focused

πŸ”΄ Drowsy


Fatigue Score

0% β†’ Fully Alert
100% β†’ Highly Fatigued

Confidence Score

Prediction confidence produced by the model.


EAR

Measures eye openness.


Blink Rate

Number of blinks per minute.


Eye Closure Duration

Continuous duration of eye closure.


PERCLOS

Percentage of time eyes remain closed.


πŸ“ˆ Results

Successfully Implemented

βœ… Face Detection

βœ… Facial Landmark Tracking

βœ… EAR Calculation

βœ… Blink Detection

βœ… Eye Closure Monitoring

βœ… PERCLOS Calculation

βœ… Random Forest Classification

βœ… Audio Alert System

βœ… Real-Time Dashboard

Outcome

The system successfully detects fatigue-related eye behavior and provides visual and audio alerts to improve driver safety.


πŸš€ Future Scope

  • 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

πŸ‘¨β€πŸ’» Team Members

  • Lavanya Bani
  • Warisha Khan
  • Sukriti Singhal
  • Aafreen

πŸŽ“ Project Guide

Dr. Ankit Dixit


πŸš— DriverGuard AI

Real-Time Driver Fatigue Detection System

Built using Python, OpenCV, MediaPipe and Machine Learning

Safe Driving Saves Lives

About

AI-Based Driver Drowsiness Detection and Monitoring System

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages