August 3, 2025

RoadTrace: Video-Based Driving Behavior Assessment

A local pipeline for analyzing dashcam footage and generating scored driving-safety reports.

  • computer vision
  • object tracking
  • kalman filter
  • homography
  • video
  • python
  • road safety

Read the analysis notebook

Autonomous driving has brought renewed attention to the question of how safely vehicles operate on public roads. A related question receives less attention: how safely do people drive when their behavior is measured from observed data rather than self-report?

Insurance telematics programs address this problem using signals such as phone accelerometers and vehicle sensors, with the resulting measurements typically reported to an insurer. A dashcam provides a richer visual signal. It captures the vehicles ahead, their relative positions, changes in distance, and the duration of those interactions. DriveAudit uses that information to analyze driving behavior locally. Given a dashcam recording, the system produces an annotated video and a quantitative safety report without requiring a cloud-based analysis service.

The target users are people who need to evaluate driving behavior without an insurance-oriented telematics program: parents monitoring a new driver, small fleet operators providing driver coaching, or individuals reviewing their own driving history. The primary output is a per-drive report containing a safety score, a table of timestamped driving events, and an annotated version of the original footage with tracked vehicles, estimated ranges, and event indicators. A bird’s-eye-view representation is also provided to show the estimated position of each tracked vehicle relative to the ego vehicle and road geometry.

System Design

The pipeline consists of five replaceable stages: detection, tracking, geometry, event detection, and safety scoring. Detection uses a YOLOv8 model exported to ONNX and executed on the CPU, with a simple interface that allows the model to be replaced independently. Tracking uses a SORT-style architecture with constant-velocity Kalman filters, IoU-based association, and Hungarian assignment to maintain stable vehicle identities and smooth ground-plane range estimates. Geometry converts image measurements into physical distance and lateral offset using a flat-road pinhole model, while ego speed comes from a GPS-derived signal or a bird’s-eye-view motion estimator. Together, these stages provide the metric signals required for downstream behavioral analysis.

Event detection applies persistent, configurable thresholds to physical quantities to identify tailgating, hard braking, cut-ins, and rolling stops. Same-type events separated by brief interruptions are merged, and each event retains its peak triggering measurement. Safety scoring then assigns penalty weights to detected events, normalizes them by driving time, and maps the result to a 0–100 heuristic index using exponential decay. The score provides a compact summary of observed events; the timestamped event table remains the underlying evidence.

Evaluation

Correctness is divided into properties that can be verified deterministically and components that must be evaluated empirically. The geometric transformation is verified deterministically: a round-trip test from image coordinates to the ground plane and back recovers the calibration to numerical precision. The remaining pipeline is evaluated against a synthetic drive with known ground truth, consisting of a two-minute scene generated from scripted trajectories: a lead vehicle closing to a tailgating gap, a vehicle cutting in from the left lane, a slower vehicle passed in the right lane, a roadside stop sign, and a hard-braking event. The scene is rendered for visual inspection, while the detector is replaced by a scripted detection stream derived from the same ground truth. This substitution is deliberate, isolating the tracker, geometric estimation, and event rules from detector performance so that the components under direct evaluation can be measured independently.

On the synthetic drive, estimated lead-vehicle distance has a mean absolute error of 0.94 m and RMSE of 1.70 m out to 60 m, with error increasing at longer ranges as expected under the flat-road model. The tracker produces zero identity switches across the three vehicles under global frame-by-frame matching. The event detector recovers all four designed events with 1.0 precision and 1.0 recall when evaluated against the same rules applied to the ground-truth signals; the right-lane vehicle is correctly excluded and the sustained cruise produces no false events. The resulting safety score is 45.6/100, consistent with the behavior encoded in the scenario. These results do not establish detector performance on real-world footage, which will depend on the selected model, confidence threshold, camera configuration, and environmental conditions. The per-drive report therefore records the detector configuration and confidence threshold alongside the detected events. This evaluation separates deterministic verification of the geometric model from empirical measurement of the estimation and event-detection stack, providing a clear basis for subsequent validation on real driving data.

Scope and Limitations

Monocular distance estimation from a ground-plane model assumes a flat road and fixed camera pose, so braking-induced pitch changes, hills, and speed bumps can introduce error, which also increases with distance; the sub-metre accuracy reported above is therefore a best-case result on level synthetic ground. Ego-speed accuracy depends on its source: a GPS-derived signal is used directly when available, while the bird’s-eye-view estimator provides a smoothed approximation that can degrade on textureless roads and in stop-and-go traffic. The lane corridor is currently a fixed-width region around the camera axis rather than detected lane geometry, so gentle curves can temporarily misclassify the lead vehicle. The safety score is a coaching-oriented heuristic rather than a calibrated risk model; its weights and decay function are engineering defaults, not parameters calibrated against collision or claims data, and the score provides a relative measure rather than a probability of risk. More broadly, the system measures driving behavior observable from a forward-facing camera, with detection performance on real-world footage remaining the principal component outside the scope of the synthetic evaluation.

Availability and Reproducibility

RoadTrace runs entirely on the local machine by design. Dashcam footage can contain location history, faces, license plates, and other identifying information, so a system intended to keep driving data under the driver’s control should not require that footage to be uploaded to a hosted service. A hosted deployment would also make the system responsible for collecting and processing personal data belonging to other drivers and pedestrians. The resulting privacy boundary is therefore part of the system design, not simply a deployment choice, and there is no hosted demo. The pipeline installs from a requirements file and runs from a single command against an MP4 and calibration file. The accompanying notebook regenerates the synthetic drive and reproduces the reported results in approximately fifteen seconds on a CPU, without requiring a GPU or model weights.

Toward Calibrated Thresholds

The next step is to address the component deliberately excluded from the synthetic evaluation: run the production detector on a labelled driving dataset such as BDD100K and report its precision and recall, since detection performance constrains the complete pipeline. The same data can support empirical calibration of the event thresholds by estimating the distribution of time headway across road types and speed ranges, then selecting flagging thresholds from observed percentiles rather than fixed round values. This would replace the current engineering defaults with thresholds grounded in real driving data, following the same empirical-service-level principle used by ClosureLabels but applied here to following distance.

Receipts

  • Deliverable Per-drive safety report, timestamped event table, annotated video, and bird's-eye-view visualization.
  • Pipeline Local end-to-end processing with ONNX detection, Kalman tracking, ground-plane ranging, event detection, and safety scoring.
  • Validation Synthetic ground-truth evaluation produced 0.94 m MAE, 1.70 m RMSE to 60 m, zero identity switches, and 1.0 event precision and recall.
  • Runtime Runs locally from an MP4 and calibration file, with the synthetic evaluation reproducible on CPU.
  • Limits Real-world detector performance remains unmeasured, and the score is a coaching heuristic rather than a calibrated risk model.

← All projects