Dhruvraj Singh Shekhawat

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
View repositoryWatch the demo on YouTube
Eye aspect ratio from six eye landmarks, and an EAR trace over time where short blinks stay above the threshold and a long closure triggers the alarm. p1p4 p2p3 p6p5 EAR = (|p2−p6| + |p3−p5|) / 2|p1−p4| threshold alarm blinks EAR over time
Concept schematic drawn for this page, not a screenshot.

Repository

Live from GitHub

Real-time driver drowsiness detection using computer vision and an integrated alarm system.

Language
Python
Stars
2
Forks
1
Last push
License
MIT

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

  1. CameraUSB webcam, Pi camera or recorded video, read on a background thread
  2. Pre-processingAuto-gamma and CLAHE for uneven lighting
  3. Face meshMediaPipe, 478 landmarks
  4. MetricsEAR, MAR and head pitch/yaw via solvePnP
  5. Temporal analysisBlinks, PERCLOS, yawns, nods and face loss, all time-based
  6. Scoring and decisionAcute plus capped history score, with hysteresis and minimum alarm time
  7. 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.

SignalDefault rule
Continuous eye closure1.8 s raises the alarm on its own
YawnMouth open beyond threshold for at least 1.5 s
Head drop18 degrees below neutral; 2.0 s raises the alarm on its own
Alarm releaseEyes 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.

1000 characters left. Plain text; links are allowed but limited.

Loading comments…