TAPS is a real-time Advanced Driver Assistance System (ADAS) prototype written in Python. It combines an in-cabin Driver Monitoring System (DMS) with a forward-facing Road Perception System using cross-camera sensor fusion to detect collision hazards and driver inattention.
Each camera pipeline runs in an independent OS process via multiprocessing to avoid GIL contention during concurrent neural inference.
- Python 3.11 - 3.12: Core runtime and process orchestration.
- OpenCV (
cv2): Video capture, optical flow odometry, and dashboard rendering. - MediaPipe: 478-point Face Landmarker for eye closure (EAR), mouth opening (MAR), 3D head pose, and iris gaze projection.
- Ultralytics (YOLO11 + ByteTrack): Multi-object detection and tracking across CUDA, OpenVINO, and ONNX Runtime backends.
- uv: Dependency and virtual environment management.
TAPS/
├── main.py # Application entry point
├── pyproject.toml # Project metadata and dependencies
├── road_camera_videos/ # Curated forward-road ADAS test scenarios
├── weights/ # YOLO11 and MediaPipe model weights
├── taps/ # Core package
│ ├── __init__.py
│ ├── __main__.py # Module execution (`python -m taps`)
│ ├── app.py # TAPSApplication: process lifecycle and UI loop
│ ├── config/
│ │ └── settings.py # DMSConfig, RoadConfig, DashboardConfig
│ ├── models/
│ │ └── telemetry.py # Telemetry dataclasses and enums
│ ├── driver/
│ │ ├── geometry.py # FacialGeometryAnalyzer: EAR, MAR, gaze, head pose
│ │ ├── calibration.py # DriverCalibrator: neutral baseline estimation
│ │ └── monitor.py # DriverMonitor: in-cabin worker process
│ ├── road/
│ │ ├── detector.py # ModelLoader: hardware backend discovery
│ │ ├── odometry.py # VisualOdometry: Lucas-Kanade ego-motion
│ │ ├── geometry.py # RoadGeometry: lane polygon, distance, traffic lights
│ │ ├── tracker.py # HazardTracker: kinematics, TTC, cut-in prediction
│ │ └── monitor.py # RoadMonitor: forward perception worker process
│ ├── fusion/
│ │ └── evaluator.py # ThreatFusionEvaluator: cross-camera threat matrix
│ └── ui/
│ ├── audio.py # AudioAlertService: debounced audio alerts
│ └── dashboard.py # DashboardRenderer: OpenCV HUD compositor
└── tests/ # Unit test suite
- Eye Aspect Ratio (EAR): Auto-calibrates against the driver's open-eye baseline to detect prolonged eye closure, smoothed with an exponential moving average (EMA).
- Mouth Aspect Ratio (MAR): Tracks inner-lip vertical opening to detect yawning.
- Head Pose and Gaze: Extracts 3D Euler angles (Pitch, Yaw, Roll) from the facial transformation matrix and projects iris centers onto anatomical eye axes for roll-invariant gaze tracking.
- Occlusion / Absence: Alerts when no face is detected within the time threshold.
- Object Tracking: Tracks vehicles, cyclists, pedestrians, traffic lights, and stop signs with ByteTrack.
- Ego-Motion Odometry: Uses sparse Lucas-Kanade optical flow on lower road patches to determine whether the host vehicle is moving or stopped.
- Distance and TTC: Estimates monocular distance using a hybrid pinhole model (height and width) and computes Time-To-Collision (TTC) from longitudinal closing speed.
- Cut-In Prediction: Projects 2D lateral velocities to flag vehicles or pedestrians entering the ego lane trapezoid.
- Traffic Infrastructure: Classifies active traffic light states (Red/Yellow/Green) in HSV space weighted by vertical zone.
- Level 0 (NORMAL): Lane clear and driver attentive (or host vehicle stationary).
- Level 1 (CAUTION): Lead vehicle in range, upcoming traffic control, or early fatigue indicators.
- Level 2 (WARNING): Active collision/cut-in hazard OR sustained driver distraction/drowsiness.
- Level 3 (CRITICAL): Active forward collision/cut-in hazard occurring simultaneously with driver inattention. Reduces TTC/distance thresholds and triggers an audio warning.
- View Modes:
Split 62/38(Default): Road-dominant view with in-cabin panel.Split 50/50: Balanced dual-camera split.Picture-in-Picture (PiP): Full road view with top-right driver inset.
| Key | Action |
|---|---|
v |
Cycle dashboard layout (Split 62/38 -> Split 50/50 -> PiP) |
n |
Switch to the next road test video in road_camera_videos/ |
c |
Recalibrate neutral driver baseline (head pose, gaze, EAR) |
p |
Cycle facial landmark overlay (Full Mesh -> Key Contours -> Off) |
m |
Toggle audio alerts (Mute / Unmute) |
q |
Stop worker processes and exit |
- Python 3.11 or 3.12
uv- Webcam (for in-cabin monitoring)
git clone https://github.com/MwenDavo/TAPS.git
cd TAPS
uv syncuv run main.pyCustom video or camera sources:
uv run main.py --road-video road_camera_videos/scenario_01_sudden_brake_day.mp4 --driver-cam 0uv run python -m unittest discover -s tests -v