Extends Level 7's tracking with per-vehicle speed estimation and a structured, exportable data pipeline.
# Pixel displacement between tracked positions / calibrated pixels-per-meter / elapsed time
pixel_dist = ((x_new - x_old)**2 + (y_new - y_old)**2) ** 0.5
meters_per_sec = (pixel_dist / PIXELS_PER_METER) / seconds
mph = meters_per_sec * 2.23694Explicitly stated as an approximation — true speed requires real camera calibration (e.g., a surveyed lane-width reference), which is stated both in the on-screen video overlay and in terminal output. That honesty is a deliberate part of the narrative: an uncalibrated number presented as precise would undermine credibility the moment someone asks how it was calibrated.
Visual feature: bounding boxes turn red above a configurable mph threshold, green at or below it — recalculated fresh every frame per vehicle, so it toggles live and accurately reflects current speed.
| ID | Class | Avg MPH | Max MPH | Min MPH | Frames | Over threshold |
|---|---|---|---|---|---|---|
| 1 | car | 14.1 | 23.2 | 3.1 | 74 | YES |
| 16 | car | 15.3 | 24.3 | 2.3 | 74 | YES |
| 20 | bus | 4.8 | 28.7 | 0.0 | 147 | YES |
| 26 | car | 18.2 | 24.2 | 12.1 | 49 | YES |
| 45 | car | 17.2 | 32.3 | 6.5 | 79 | YES |
| 48 | truck | 12.5 | 22.3 | 3.2 | 66 | YES |
| 67 | car | 3.6 | 8.7 | 0.0 | 128 | no |
| 71 | car | 31.3 | 33.1 | 29.6 | 7 | YES |
| ID | Class | Avg MPH | Max MPH | Min MPH | Frames | Over threshold |
|---|---|---|---|---|---|---|
| 8 | car | 61.0 | 121.0 | 19.5 | 77 | YES |
| 11 | car | 99.7 | 206.9 | 1.8 | 42 | YES |
| 120 | car | 121.8 | 163.0 | 81.4 | 13 | YES |
| 139 | car | 157.5 | 193.6 | 108.6 | 10 | YES |
| 154 | car | 133.3 | 155.1 | 78.7 | 19 | YES |
| 157 | car | 126.0 | 275.5 | 62.3 | 7 | YES |
| 176 | car | 118.8 | 243.2 | 50.3 | 48 | YES |
No camera calibration in either case. That gap is the clearest possible demonstration of why an uncalibrated pixel-to-mph conversion is an approximation, not a measurement — clip 4 flags 158 of its 167 tracked vehicles (95%) as "over threshold," versus 0 of 10 in clip 3, the slowest/most static of the four.
Terminal output
--------------------------------------------------------------------------------
Total vehicles tracked: 46
Vehicles exceeding 10mph threshold: 40
Saved annotated video as output_speed1.mp4
Saved speed data table as speed_data1.csvTerminal output
--------------------------------------------------------------------------------
Total vehicles tracked: 21
Vehicles exceeding 10mph threshold: 20
Saved annotated video as output_speed2.mp4
Saved speed data table as speed_data2.csvTerminal output
--------------------------------------------------------------------------------
Total vehicles tracked: 10
Vehicles exceeding 10mph threshold: 0
Saved annotated video as output_speed3.mp4
Saved speed data table as speed_data3.csvTerminal output
--------------------------------------------------------------------------------
Total vehicles tracked: 167
Vehicles exceeding 10mph threshold: 158
Saved annotated video as output_speed4.mp4
Saved speed data table as speed_data4.csvThe video isn't just producing a visual — it's extracting structured, exportable data per object, exactly the kind of output a real manufacturing or logistics deployment would need to feed into a dashboard or reporting system.