Skip to content

ameya1252/Driver-Drowsiness-Detection-System

Repository files navigation

Driver Drowsiness Detection System

Real-time driver drowsiness detector with two pipelines:

  • Facial-landmark EAR/MAR (default): Uses dlib 68-point landmarks to track eye aspect ratio (EAR) and mouth aspect ratio (MAR), triggering alarms when the driver appears drowsy or yawning.
  • Legacy CNN: Uses Haar cascades plus a lightweight CNN eye-state classifier for environments without dlib.

sleepy-mr-bean

Requirements

  • Python 3.9+ recommended
  • Install dependencies: pip install -r requirements.txt
  • dlib landmark model: Download shape_predictor_68_face_landmarks.dat from http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2 and place it in the project root.
  • Optional: Raspberry Pi with a buzzer connected to GPIO pin 11 (or choose another pin via CLI).

Quickstart (recommended landmark pipeline)

python final.py --help        # view options
python final.py               # run with default camera (index 0)
# Examples:
# python final.py --source path/to/video.mp4
# python final.py --no-sound --gpio --gpio-pin 11
# python final.py --mode either --mar-threshold 0.8   # include yawning trigger

Key flags:

  • --source: camera index or video file path
  • --no-sound: disable audio alarm (sound uses alarm.wav)
  • --gpio: enable GPIO alarm (Raspberry Pi only)
  • --ear-threshold / --mar-threshold: tweak sensitivity
  • --mode: ear (default), either, or mouth to choose triggering signal
  • --no-landmarks: hide landmark overlay

Defaults tuned for fewer false positives: EAR threshold 0.20, 16 consecutive frames, width 480. Increase --ear-frames or lower --ear-threshold further if you still get false alarms with eyes open.

Legacy CNN pipeline

python "drowsiness detection.py" --model models/eye_state_cnn.h5

Uses Haar cascades from haar cascade files/ and a trained eye-state CNN. Alarms when both eyes are predicted closed for sustained frames.

Training the CNN (optional)

Prepare data (eye open/closed) using the Kaggle dataset https://www.kaggle.com/datasets/serenaraju/yawn-eye-dataset-new or your own, with structure:

data/
  train/
    Open/
    Close/
  valid/
    Open/
    Close/

Then train:

python model.py

The trained model is saved to models/eye_state_cnn.h5.

Files

  • drowsiness_detector.py: Advanced EAR/MAR detector (used by final.py).
  • final.py: Entry point wrapper for the advanced detector.
  • drowsiness detection.py: Legacy CNN-based detector.
  • model.py: CNN training script.
  • alarm.wav: Alarm sound (used if --no-sound not set).
  • haar cascade files/: Haar classifiers for the legacy pipeline.
  • shape_predictor_68_face_landmarks.dat: Required dlib landmark model (download separately).

Notes

  • Press q to quit either detector window.
  • Tune thresholds to your camera setup and lighting if needed.
  • GPIO support gracefully disables if not on Raspberry Pi.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages