Skip to content
AP

Gaze-Tracker

Real-time driver drowsiness detection from facial landmarks on CPU.

30+ FPS

Real-time inference on CPU

0.22

EAR threshold for drowsiness flag

MediaPipeOpenCVPythonpygame

Overview

Gaze-Tracker is a real-time driver drowsiness detection system. It watches a camera feed, tracks facial landmarks, and raises an audio-visual alarm when the driver's eyes have been closed for long enough to be unsafe. The whole pipeline runs at 30+ FPS on CPU, with no GPU, no CMake compilation, and no training data required: pure pip-installable dependencies.

Background

The U.S. National Highway Traffic Safety Administration attributes roughly 100,000 crashes a year to drowsy driving. A detection system that is cheap, latency-tolerant, and runs on commodity hardware has a low bar to deployment.

Eye Aspect Ratio (EAR) is a simple geometric measure that quantifies eye openness from six landmark points around each eye. Proposed by Soukupova and Cech in 2016, it sidesteps both learning-based classifiers and custom calibration. The measure drops below 0.2 when an eye closes and sits between 0.25 and 0.35 when it is open.

Pipeline

Each frame is passed through MediaPipe's 478-point face landmarker. Six landmarks per eye are selected and the EAR is computed as the ratio of vertical eye height to horizontal eye width. When the running EAR falls below a configurable threshold (default 0.22) for three or more consecutive seconds, an alarm triggers through a non-blocking pygame audio sink.

The runtime overlay shows the face bounding box, eye contours, live EAR value, frames-per-second counter, and a drowsiness progress bar. Session events (alerts, blink counts, timestamps) are logged for post-hoc analysis.

Design decisions

The project favours operational simplicity over peak accuracy. A learned blink/drowsiness classifier would likely shave false positives but at the cost of training data, a model file, and portability. EAR with a thresholded temporal filter is transparent, hackable, and trivially deployable.

Tech stack

Python 3.10+
Primary runtime.
MediaPipe Tasks API
478-point facial landmark detection at 30+ FPS on CPU.
OpenCV 4.x
Frame capture, geometry, and overlay rendering.
pygame
Non-blocking audio alarm when drowsiness is sustained.
pytest
Regression tests for the EAR computation and threshold logic.

References

  1. [1]Soukupová, T., & Cech, J. (2016). Real-Time Eye Blink Detection using Facial Landmarks. Computer Vision Winter Workshop.
  2. [2]NHTSA. Drowsy Driving research & statistics.