Skip to content

DrowsinessGuard: A real-time drowsiness detection system that enhances driver safety using computer vision and facial landmark analysis. Features precise eye tracking, face direction monitoring, and yawn detection to alert drivers of fatigue, helping prevent accidents caused by drowsy driving.

License

Notifications You must be signed in to change notification settings

LohiyaH/DrowsinessGuard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Driver Drowsiness Detection System

A real-time system for detecting driver drowsiness using computer vision and facial landmarks detection. This system monitors a driver's eyes and alerts them when signs of drowsiness are detected.

Features

  • Real-time face detection using Haar Cascades and dlib
  • Eye state monitoring using Eye Aspect Ratio (EAR)
  • Facial landmarks detection for precise eye tracking
  • Audio alerts when drowsiness is detected
  • Multiple detection methods (Haar Cascade and dlib) for comparison
  • Face direction monitoring for distraction detection
  • Yawn detection for additional drowsiness indicators

Project Structure

driver-drowsiness-detection/
├── data/
│   ├── alert_sounds/         # Alert sound files
│   │   ├── alert-sound.mp3
│   │   ├── focus.mp3
│   │   └── take_a_break.mp3
│   ├── database/            # Shape predictor data file
│   │   └── shape_predictor_68_face_landmarks.dat
│   ├── images/             # Output directory for eye images
│   └── xml/                # Haar cascade classifier files
│       ├── haarcascade_eye.xml
│       ├── haarcascade_frontalface_alt.xml
│       ├── haarcascade_frontalface_alt2.xml
│       ├── haarcascade_frontalface_alt_tree.xml
│       └── haarcascade_frontalface_default.xml
└── src/                    # Source code
    ├── final_integration.py  # Main implementation with all features
    ├── main.py              # Basic implementation using Haar cascades
    ├── main_dlib.py         # Implementation using dlib
    └── train.py             # Training utility for eye state detection

Dependencies

  • Python 3.x
  • OpenCV (cv2)
  • dlib
  • numpy
  • imutils
  • matplotlib
  • python-vlc

Installation

  1. Clone the repository:
git clone https://github.com/LohiyaH/DrowsinessGuard.git
cd driver-drowsiness-detection
  1. Install the required dependencies:
pip install opencv-python dlib numpy imutils matplotlib python-vlc
  1. Download the shape predictor file:
  • Download shape_predictor_68_face_landmarks.dat from dlib's official website
  • Place it in the data/database/ directory

Usage

The project provides three different implementations:

  1. Basic Implementation (main.py)
python src/main.py
  • Uses Haar cascades for face and eye detection
  • Saves detected eye images to data/images/
  1. Dlib Implementation (main_dlib.py)
python src/main_dlib.py
  • Uses dlib for facial landmark detection
  • More accurate than Haar cascade method
  • Includes basic drowsiness detection
  1. Full Featured Implementation (final_integration.py)
python src/final_integration.py
  • Combines all features including:
    • Face direction monitoring
    • Yawn detection
    • Advanced drowsiness detection
    • Multiple alert thresholds
    • Audio alerts

How It Works

  1. Face Detection: The system first detects the driver's face using either Haar cascades or dlib's face detector.

  2. Facial Landmarks: Using dlib's facial landmark predictor, 68 points on the face are detected, including 6 points for each eye.

  3. Eye Aspect Ratio (EAR): The system calculates the eye aspect ratio to determine if the eyes are closed:

    EAR = (||p2-p6|| + ||p3-p5||) / (2||p1-p4||)
    

    where p1, ..., p6 are the 2D landmark points around the eye.

  4. Drowsiness Detection: If the EAR falls below a threshold for a certain number of consecutive frames, the system triggers an alert.

  5. Additional Features:

    • Face direction monitoring to detect distraction
    • Yawn detection using mouth aspect ratio
    • Multiple alert levels based on drowsiness severity

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is under MIT License.

Acknowledgments

  • The shape predictor model is provided by dlib
  • Haar cascade classifiers are from OpenCV's repository

About

DrowsinessGuard: A real-time drowsiness detection system that enhances driver safety using computer vision and facial landmark analysis. Features precise eye tracking, face direction monitoring, and yawn detection to alert drivers of fatigue, helping prevent accidents caused by drowsy driving.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages