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.
- Face landmark tracking —
face_detector.pyuses MediaPipe Face Mesh to locate facial landmarks each frame, feeding eye and mouth geometry into the analysis stage. - EAR / MAR computation —
fatigue_analyzer.pycomputes the Eye Aspect Ratio (EAR) and Mouth Aspect Ratio (MAR) from those landmarks — EAR drops as eyes close (drowsiness), MAR rises during yawns (fatigue). - 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.
- 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.
- Three-tier risk classification — The duration-based score is bucketed into SAFE, WARNING, and DANGER, with
sound_manager.pytriggering an audio alert as risk escalates andoverlay.pyrendering live metrics onto the video feed.
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
- Python 3.9+
- OpenCV (
opencv-python) - MediaPipe
- NumPy
Install dependencies:
pip install opencv-python mediapipe numpypython main.pyBy 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.
| 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 |
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
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.
TBD