Skip to content

Latest commit

ย 

History

19 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš— Driver Drowsiness Detection System

Real-time Driver Monitoring System using Python, OpenCV and MediaPipe FaceMesh


๐Ÿ“‘ Table of Contents

  • Project Overview
  • Features
  • Technologies Used
  • Project Workflow
  • Detection Parameters
  • Performance
  • Limitations
  • Project Structure
  • Installation
  • Usage
  • How It Works
  • Libraries
  • Roadmap
  • Future Improvements
  • Contributing
  • License

๐Ÿ“Œ Project Overview

Driver fatigue is one of the leading causes of road accidents worldwide. This project provides a real-time Driver Monitoring System (DMS) that continuously analyzes the driver's facial landmarks using MediaPipe FaceMesh.

The system estimates the driver's alertness using:

  • ๐Ÿ‘ Eye Aspect Ratio (EAR)
  • ๐Ÿ˜ฎ Mouth Aspect Ratio (MAR)
  • ๐Ÿ˜ด Percentage of Eye Closure (PERCLOS)
  • ๐Ÿง  Head Pose Estimation

If signs of drowsiness persist beyond predefined thresholds, the system automatically detects the driver's fatigue state and can trigger an alert.


โœจ Features

  • โœ… Real-time webcam monitoring
  • โœ… Face detection using MediaPipe FaceMesh
  • โœ… 468 facial landmark detection
  • โœ… Eye Aspect Ratio (EAR) calculation
  • โœ… Mouth Aspect Ratio (MAR) calculation
  • โœ… Percentage of Eye Closure (PERCLOS)
  • โœ… Head Pose estimation
  • โœ… Driver state classification
  • โœ… Lightweight and fast
  • โœ… Modular Python implementation
  • โœ… Easy to customize thresholds

๐Ÿ›  Technologies Used

  • Python
  • OpenCV
  • MediaPipe FaceMesh
  • NumPy

๐Ÿง  Project Workflow

            Webcam
               โ”‚
               โ–ผ
       Face Detection
               โ”‚
               โ–ผ
    MediaPipe FaceMesh
      (468 Landmarks)
               โ”‚
      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
      โ–ผ        โ–ผ        โ–ผ
    EAR       MAR   Head Pose
      โ”‚        โ”‚        โ”‚
      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ–ผ
      Driver State Analysis
               โ–ผ
      Drowsiness Detection
               โ–ผ
          Driver Alert

๐Ÿ“ Detection Parameters

๐Ÿ‘ Eye Aspect Ratio (EAR)

Measures eye openness.

Lower EAR values indicate prolonged eye closure and possible drowsiness.


๐Ÿ˜ฎ Mouth Aspect Ratio (MAR)

Measures mouth opening.

Higher MAR values indicate yawning.


๐Ÿ˜ด PERCLOS

Percentage of Eye Closure over time.

PERCLOS is one of the most reliable fatigue indicators used in modern Driver Monitoring Systems.


๐Ÿง  Head Pose Estimation

Tracks the driver's head orientation.

Detects excessive downward or sideways head movement indicating fatigue or distraction.


๐Ÿ“Š Performance

  • Real-time Processing
  • Approximately 25โ€“30 FPS
  • Detects 468 facial landmarks
  • Low latency
  • Lightweight implementation

โš ๏ธ Limitations

  • Works with one driver at a time
  • Requires sufficient lighting
  • Performance decreases if the face is heavily occluded
  • Requires a webcam

๐Ÿ“ Project Structure

Driving-Monitor-in-Python/
โ”‚
โ”œโ”€โ”€ calibration/
โ”œโ”€โ”€ detection/
โ”œโ”€โ”€ demo/
โ”‚   โ””โ”€โ”€ demo.gif
โ”œโ”€โ”€ images/
โ”‚   โ”œโ”€โ”€ banner.png
โ”‚   โ”œโ”€โ”€ face_detection.png
โ”‚   โ”œโ”€โ”€ landmarks.png
โ”‚   โ””โ”€โ”€ alert.png
โ”œโ”€โ”€ main.py
โ”œโ”€โ”€ state.py
โ”œโ”€โ”€ utils.py
โ”œโ”€โ”€ face_landmarker.task
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ LICENSE
โ””โ”€โ”€ README.md

๐Ÿš€ Installation

Clone the repository

git clone https://github.com/badivana/Driving-Monitor-in-Python.git

cd Driving-Monitor-in-Python

Install dependencies

pip install -r requirements.txt

โ–ถ๏ธ Usage

Run the application

python main.py

The application will:

  • Open your webcam
  • Detect facial landmarks
  • Calculate Eye Aspect Ratio (EAR)
  • Calculate Mouth Aspect Ratio (MAR)
  • Estimate Head Pose
  • Monitor driver fatigue
  • Display alerts when drowsiness is detected

Press Esc to exit.


โš™๏ธ How It Works

The Driver Monitoring System consists of three major components.

Face Detection

Uses MediaPipe FaceMesh to detect 468 facial landmarks in real time.


Head Pose Estimation

Calculates the driver's head orientation using facial landmarks.


Driver State Classification

Combines:

  • Eye Aspect Ratio (EAR)
  • Mouth Aspect Ratio (MAR)
  • PERCLOS
  • Head Pose

to classify the driver as:

๐ŸŸข Alert

๐Ÿ”ด Drowsy


๐Ÿ“š Libraries

  • OpenCV
  • MediaPipe
  • NumPy

๐Ÿ—บ Roadmap

  • Face Detection
  • Eye Aspect Ratio (EAR)
  • Mouth Aspect Ratio (MAR)
  • Head Pose Estimation
  • Driver State Classification
  • Drowsiness Detection
  • Audio Alarm
  • Mobile Notifications
  • Raspberry Pi Deployment
  • TensorFlow Lite Optimization
  • Multi-person Detection
  • Streamlit Dashboard

๐Ÿš€ Future Improvements

  • Audio warning system
  • Mobile notification support
  • TensorFlow Lite optimization
  • Raspberry Pi deployment
  • Infrared camera support
  • Driver identification
  • Performance benchmarking
  • Cloud logging
  • AI-based fatigue prediction

๐Ÿค Contributing

Contributions are welcome.

If you find a bug or have an improvement, feel free to:

  • Fork the repository
  • Create a new branch
  • Commit your changes
  • Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License.


โญ If you found this project useful

Please consider giving the repository a โญ on GitHub

About

Real-time Driver Drowsiness Detection System using Python, OpenCV and MediaPipe FaceMesh.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages