Problem
Urban traffic congestion carries a real, measurable cost — wasted time, fuel and emissions — and managing it well depends on reliable data about vehicle flow. Collecting that data manually doesn't scale, so the goal was to turn ordinary traffic footage into usable metrics (counts, vehicle types, flow over time) without requiring specialized infrastructure or cloud dependency.
Approach
Built a Python pipeline where uploaded traffic video is processed frame by frame by YOLO11n and YOLO26n (pretrained on COCO, restricted to car/motorcycle/bus/truck classes), paired with Ultralytics' native BoT-SORT tracker to assign persistent IDs and count unique vehicles across frames. The resulting detections feed a metrics layer — unique vehicle counts, type distribution, flow per time interval and vehicles per minute — surfaced through an interactive Streamlit interface with charts and CSV export. The system auto-detects available hardware (CUDA, Apple MPS or CPU) and runs entirely locally. Along the way, handled a couple of real tracker quirks: YOLO's streaming mode silently dropping the final frames of a video (worked around by backfilling missing frames with the last known count) and the tracker flip-flopping a vehicle's class between frames (fixed by locking each ID's type to its first detection).
Results
Ran 28 experiments across 5 videos (10 seconds to 60 minutes) on three hardware setups — NVIDIA RTX 3070 (CUDA), and an Apple MacBook Pro M4 via MPS and CPU. Apple's MPS backend had the best average processing-time-to-video-duration ratio, edging out the dedicated CUDA GPU, while plain CPU was consistently the slowest. Validating against manual counts on shorter clips, the system landed within 0%–7.7% relative error depending on model and device. Comparing models, YOLO11n was faster on CUDA, while YOLO26n's simplified architecture gave it an edge on CPU and slightly higher counts on longer, denser videos. Main limitations: missed detections on small/distant vehicles, and misclassification of vehicle types outside COCO's categories (e.g. a train read as a bus). Next steps: cloud hosting and support for live camera streams instead of uploaded video only.