Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DriverFatigueSystem

Real-time driver fatigue and attention monitor. Tracks facial landmarks to detect drowsiness and inattention, calibrates automatically to each driver, and raises a live three-tier risk alert as fatigue builds over time.

How it works

  1. Face landmark trackingface_detector.py uses MediaPipe Face Mesh to locate facial landmarks each frame, feeding eye and mouth geometry into the analysis stage.
  2. EAR / MAR computationfatigue_analyzer.py computes the Eye Aspect Ratio (EAR) and Mouth Aspect Ratio (MAR) from those landmarks — EAR drops as eyes close (drowsiness), MAR rises during yawns (fatigue).
  3. Per-user head-pose calibration — Rather than relying on fixed thresholds, the system automatically calibrates to each driver's baseline head pose and eye geometry at the start of a session, so detection accuracy holds up across different face shapes and camera angles.
  4. Duration-based scoring — Instead of flagging on a single bad frame, fatigue/attention is scored based on how long eyes stay closed or head pose stays off-center, filtering out normal blinks and brief glances.
  5. Three-tier risk classification — The duration-based score is bucketed into SAFE, WARNING, and DANGER, with sound_manager.py triggering an audio alert as risk escalates and overlay.py rendering live metrics onto the video feed.

Project structure

DriverFatigueSystem/
├── audio/
│   └── sound_manager.py     # Plays audio alerts per risk tier
├── core/
│   ├── face_detector.py     # MediaPipe Face Mesh landmark detection
│   ├── fatigue_analyzer.py  # EAR/MAR computation, calibration, risk scoring
│   └── video_stream.py      # Threaded video frame source
├── ui/
│   └── overlay.py           # Renders live HUD onto the video frame
├── utils/
│   ├── drawing_utils.py     # Overlay drawing helpers
│   └── math_utils.py        # EAR/MAR and geometry helper functions
├── test_videos/
│   └── driver_test_clip.mp4 # Sample footage for testing without a live camera
├── config.py                 # Thresholds, calibration, and runtime settings
└── main.py                   # Entry point — runs the full detection pipeline

Requirements

  • Python 3.9+
  • OpenCV (opencv-python)
  • MediaPipe
  • NumPy

Install dependencies:

pip install opencv-python mediapipe numpy

Usage

python main.py

By default the pipeline can run against a live webcam or test_videos/driver_test_clip.mp4 — check main.py / config.py for the active source setting. Press q to exit.

Risk tiers

Tier Meaning
SAFE Eyes open, head pose centered, no sustained fatigue signal
WARNING Early signs of drowsiness or inattention sustained over a short window
DANGER Sustained eye closure, yawning, or head-pose deviation — immediate alert

Configuration

All tunable behavior lives in config.py, including:

  • EAR/MAR thresholds for eye-closure and yawn detection
  • Duration windows used to escalate SAFE → WARNING → DANGER
  • Per-user calibration behavior at session start

Notes

This is an independent/research project — a proof of concept for driver-monitoring technology, not a certified safety system. Detection reliability depends on camera placement, lighting, and calibration quality, and it should not be relied on as a sole safety mechanism in a real vehicle.

License

TBD

About

Real-time driver drowsiness detection with EAR/MAR tracking and tiered risk alerts.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages