Exit 1Test track
Driver drowsiness detection
Camera-based driver monitoring and alarm
A real-time driver-monitoring prototype that tracks eye closure, yawning and head pose from a camera and sounds an alarm when drowsiness persists.
- Status
- Prototype with automated tests
- Categories
- Computer vision, Embedded, Automotive, Electronics
- Built with
- Python, OpenCV, MediaPipe, NumPy, PyYAML, Raspberry Pi GPIO, picamera2, Arduino (C++), pyserial, unittest
views, counted on this site's server
Repository
Live from GitHubReal-time driver drowsiness detection using computer vision and an integrated alarm system.
Problem
Fatigue builds gradually and drivers are poor judges of it. A monitor has to catch prolonged eye closure and head drops without firing on every blink, yawn, conversation or glance at a mirror.
Solution
MediaPipe Face Mesh tracks 478 facial landmarks per frame. Eye and mouth aspect ratios and a solvePnP head pose feed a time-based analyser that turns frames into events: blinks, long blinks, micro-sleeps, yawns, nods and face loss.
Acute signs (continuous closure, sustained head drop) are combined with a capped history score (PERCLOS, yawns, nods, long blinks), so history alone can never trigger the alarm. A hysteresis decision layer then drives interchangeable alarm outputs: a speaker, a Raspberry Pi GPIO buzzer or relay, or an Arduino over USB serial.
Architecture
- CameraUSB webcam, Pi camera or recorded video, read on a background thread
- Pre-processingAuto-gamma and CLAHE for uneven lighting
- Face meshMediaPipe, 478 landmarks
- MetricsEAR, MAR and head pitch/yaw via solvePnP
- Temporal analysisBlinks, PERCLOS, yawns, nods and face loss, all time-based
- Scoring and decisionAcute plus capped history score, with hysteresis and minimum alarm time
- OutputsAlarm back-ends, live dashboard and CSV session log
Features
- Five-second per-driver calibration of eye and mouth thresholds and neutral head pose
- Frame-rate-independent timing, so results do not depend on camera FPS
- Face loss is treated as 'driver not visible', never as drowsiness
- Eye data is ignored when the head is turned more than 30 degrees
- Hardware abstraction: new alarm outputs implement on() and off()
- Every threshold lives in config.yaml and is validated at start-up
- Camera-free simulated drive and an automated test suite
Results
Default decision thresholds from the project configuration. The automated tests verify that the logic behaves as designed; real-world accuracy has not been measured yet, and the README defines the evaluation protocol for it.
| Signal | Default rule |
|---|---|
| Continuous eye closure | 1.8 s raises the alarm on its own |
| Yawn | Mouth open beyond threshold for at least 1.5 s |
| Head drop | 18 degrees below neutral; 2.0 s raises the alarm on its own |
| Alarm release | Eyes open 1.5 s, after at least 3 s of alarm |
Limitations
- The largest detected face is treated as the driver.
- The Arduino serial protocol has no command acknowledgement yet.
- Dark sunglasses and heavy occlusion make eye measurements unreliable.
- Thresholds and weights still need evaluation across people and conditions.
Sources: https://github.com/dhruxraj/drowsiness_detection (README)
Comments
Questions about the design or ideas for the next iteration are welcome.
Loading comments…