Real-time traffic camera validation of MnDOT highway detectors using computer vision
Camera2Detector is a platform that uses YOLO-based computer vision on Minnesota Department of Transportation (MnDOT) highway camera feeds to generate independent traffic metrics (vehicle count, occupancy, speed) and correlates them in real time with MnDOT's ~7,000 loop/radar detectors. It enables transportation agencies to validate detector health, identify malfunctions, and supplement missing data with camera-derived measurements.
Developed by the Choi Lab at the University of Minnesota Twin Cities, Department of Civil, Environmental, and Geo-Engineering (CEGE).
MnDOT operates approximately 2,000 highway cameras and 7,000 traffic detectors across Minnesota. Detectors occasionally malfunction, drift, or go offline β but there is no independent ground truth to detect these failures in real time. Camera2Detector addresses this gap by:
- Running object detection on existing camera feeds to produce an independent traffic measurement
- Spatially matching cameras to nearby detectors using road geometry
- Streaming side-by-side comparisons so operators can spot discrepancies instantly
| Feature | Description |
|---|---|
| Road-Aware Vehicle Detection | Vehicles are assigned to specific road segments (e.g., "I-94 WB", "I-35W NB") using shapefile geometry and tracking-based direction detection |
| Multi-Frame Tracking | 10 frames captured over 30 seconds; centroids matched across frames via the Hungarian algorithm to count unique vehicles and determine travel direction |
| VLM-Based ROI Generation | Vision-language models (GPT-5.3) automatically generate road-specific regions of interest for cameras viewing interchanges or multiple roads |
| Real-Time SSE Streaming | Server-Sent Events push CV + detector data every 30 seconds, matching MnDOT's native reporting interval |
| Historical Comparison | ClickHouse-backed overlay of same-time-yesterday data for trend analysis and anomaly detection |
| Interactive Dashboard | Dark-themed web UI with Leaflet map, Chart.js time series, and color-coded road overlays |
| Per-Road Breakdown | Count, occupancy, and vehicle type (car/motorcycle/bus/truck) breakdown per road visible from each camera |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Browser (Frontend) β
β Leaflet Map β Camera Panel β Chart.js β ROI Editor β
ββββββββ¬βββββββββββββββ¬βββββββββββββββ¬βββββββββββββββ¬ββββββββββ
β β β β
βΌ βΌ βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FastAPI Backend (:30000) β
β β
β /api/cameras β Camera listing & filtering β
β /api/camera/{id}/image β Proxy camera JPEG β
β /api/cv/{id} β Single-shot YOLO analysis β
β /api/sse/{id} β 30s streaming (CV + detectors) β
β /api/camera/{id}/rois β ROI CRUD + VLM generation β
β /api/history/{id} β ClickHouse time series β
β /api/detector/{id} β Mayfly detector data proxy β
ββββββββ¬βββββββββββββββ¬βββββββββββββββ¬βββββββββββββββ¬ββββββββββ
β β β β
βΌ βΌ βΌ βΌ
βββββββββββββ ββββββββββββββ ββββββββββββββ ββββββββββββββββ
β MnDOT β β YOLO β β ClickHouse β β Road β
β APIs β β (v8 nano) β β (sensors) β β Shapefile β
β β β β β β β (383 routes)β
β β’ Images β β β’ Detect β β β’ raw_30s β β β
β β’ Config β β β’ Track β β β’ daily β β β’ Geometry β
β β’ Mayfly β β β’ Assign β β metrics β β β’ Bearings β
βββββββββββββ ββββββββββββββ ββββββββββββββ ββββββββββββββββ
| Layer | Technology |
|---|---|
| Backend | Python 3.12, FastAPI, Uvicorn, Pydantic |
| Object Detection | YOLOv8 nano (Ultralytics) |
| Tracking | Multi-frame centroid matching via SciPy (Hungarian algorithm) |
| Road Geometry | GeoPandas, Shapely, R-tree spatial index |
| Time-Series DB | ClickHouse (27.9B rows of 30-second detector data) |
| VLM ROI Generation | OpenAI API (GPT-5.3 with chain-of-thought prompting) |
| Frontend | Vanilla JS, Leaflet.js, Chart.js, Server-Sent Events |
| Deployment | Docker (Python 3.12-slim + GDAL + OpenCV) |
- Camera images: JPEG snapshots from ~2,000 highway cameras statewide
- Metro config: XML manifest of all cameras and detectors with coordinates
- Mayfly: Real-time 30-second detector readings (volume, occupancy, speed) β 2,880 values per day per detector
- MnDOT Trunk Highways: 383 route segments (79 in metro), EPSG:26915 β EPSG:4326
- Fields: route name, direction (D/I), cardinal (NB/SB/EB/WB)
sensors.raw_30s: 30-second detector readings (volume, occupancy, speed)sensors.detector_meta: 4,109 detector locations with route/direction/lanesensors.daily_metrics: Pre-aggregated daily statistics
- Python 3.12+
- Docker (recommended)
- MnDOT data is publicly accessible (no API key needed for cameras/detectors)
- OpenAI API key (optional, only for VLM-based ROI generation)
- ClickHouse instance (optional, only for historical data overlay)
- Road shapefile:
data/shp/Trunk_Highways_in_Minnesota.shp(download from MnDOT GIS)
# Clone the repository
git clone https://github.com/UMN-Choi-Lab/camera2detector.git
cd camera2detector
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp .env.example .env
# Edit .env with your settings (all optional except port)
# Place the shapefile
mkdir -p data/shp
# Copy Trunk_Highways_in_Minnesota.shp (and .shx, .dbf, .prj) to data/shp/
# Run with hot reload
C2D_RELOAD=1 python run.pyThe dashboard will be available at http://localhost:30000.
# Build
docker build -t camera2detector .
# Run (--network host required for ClickHouse access)
docker run -d \
--name camera2detector \
--network host \
--env-file .env \
-v $(pwd)/data/rois:/app/data/rois \
-v $(pwd)/data/shp:/app/data/shp \
camera2detectorThe YOLO model (yolov8n.pt) is automatically downloaded during the Docker build.
All settings use the C2D_ environment variable prefix (via Pydantic Settings):
| Variable | Default | Description |
|---|---|---|
C2D_PORT |
30000 |
Server port |
C2D_YOLO_MODEL |
yolov8n.pt |
YOLO model file |
C2D_YOLO_CONFIDENCE |
0.3 |
Detection confidence threshold |
C2D_VEHICLE_CLASSES |
[2,3,5,7] |
COCO classes: car, motorcycle, bus, truck |
C2D_TRACKING_FRAMES |
10 |
Frames per 30-second window |
C2D_TRACKING_INTERVAL_S |
3.0 |
Seconds between frames |
C2D_MAX_MATCH_DISTANCE_M |
500 |
Camera-to-detector matching radius (meters) |
C2D_ROAD_SEARCH_RADIUS_M |
300 |
Camera-to-road matching radius (meters) |
C2D_CLICKHOUSE_HOST |
localhost |
ClickHouse server host |
C2D_CLICKHOUSE_PORT |
8123 |
ClickHouse HTTP port |
C2D_OPENAI_API_KEY |
(empty) | OpenAI key for VLM ROI generation |
C2D_OPENAI_MODEL |
gpt-5.3-chat-latest |
VLM model for ROI generation |
camera2detector/
βββ backend/
β βββ app.py # FastAPI app factory & lifespan
β βββ config.py # Pydantic settings (C2D_ prefix)
β βββ models/
β β βββ schemas.py # 15 Pydantic models (CVResult, SSEEvent, ROI, etc.)
β βββ routers/
β β βββ proxy.py # MnDOT API proxy endpoints
β β βββ cv.py # Single-shot YOLO inference
β β βββ sse.py # SSE streaming with tracking pipeline
β β βββ history.py # ClickHouse time-series API
β β βββ roi.py # ROI CRUD + VLM generation
β β βββ clearguide.py # ClearGuide speed data proxy
β βββ services/
β βββ mndot_client.py # Async HTTP client for MnDOT APIs
β βββ metro_config.py # XML parsing + haversine spatial matching
β βββ cv_pipeline.py # YOLO detection + multi-frame tracking
β βββ road_geometry.py # Shapefile loading + spatial queries
β βββ clickhouse_client.py # ClickHouse queries
β βββ vlm_roi.py # VLM ROI suggestor-reviewer loop
β βββ clearguide_client.py # ClearGuide OAuth2 + speed queries
βββ frontend/
β βββ index.html # Main dashboard layout
β βββ roi_tool.html # Standalone ROI annotation tool
β βββ css/style.css # Dark theme (576 lines)
β βββ js/
β βββ app.js # Orchestrator: camera click β load β stream
β βββ map.js # Leaflet map with camera clusters + road lines
β βββ camera_panel.js # Image overlay with road-colored bounding boxes
β βββ charts.js # Chart.js time series (count, occupancy, speed)
β βββ sse_client.js # EventSource connection manager
β βββ roi_editor.js # Interactive polygon drawing on canvas
β βββ utils.js # Formatting and normalization helpers
βββ data/
β βββ shp/ # Road shapefile (not included β see setup)
β βββ rois/ # Cached ROI JSON files per camera
βββ Dockerfile
βββ requirements.txt
βββ run.py # Uvicorn entry point
βββ .env.example # Environment variable template
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/cameras?road={name} |
List cameras, optionally filtered by road name |
GET |
/api/camera/{id}/image |
Proxy camera JPEG from MnDOT |
GET |
/api/camera/{id}/detectors |
Detectors within 500m of camera |
GET |
/api/camera/{id}/roads |
Nearby road segments from shapefile |
GET |
/api/detector/{id}/{type} |
Mayfly data (counts, occupancy, speed) |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/cv/{camera_id} |
Single-frame YOLO detection β CVResult |
GET |
/api/sse/{camera_id} |
SSE stream: CV + detector data every 30s |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/camera/{id}/rois |
Load cached ROIs |
POST |
/api/camera/{id}/rois/generate |
Auto-generate via VLM |
PUT |
/api/camera/{id}/rois |
Save manually edited ROIs |
DELETE |
/api/camera/{id}/rois/{roi_id} |
Delete a single ROI |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/history/detectors |
All detector metadata |
GET |
/api/history/{detector_id}?type=v30&start=...&end=... |
Time-series data (raw or downsampled) |
GET |
/api/history/{detector_id}/daily |
Daily aggregated metrics |
The CV pipeline captures 10 frames over 30 seconds (one every 3s) from a camera and:
- Detects vehicles in each frame using YOLOv8 nano (classes: car, motorcycle, bus, truck)
- Tracks vehicles across frames by matching bounding box centroids using the Hungarian algorithm (SciPy's
linear_sum_assignment) - Counts unique vehicles that appear across multiple frames (reducing double-counting from stationary vehicles)
- Computes occupancy as the average ratio of bounding box area to effective road area across all frames
Each detected vehicle is assigned to a specific road segment. Two methods are used:
- ROI-based (preferred): If the camera has defined Regions of Interest, vehicles are assigned via point-in-polygon tests on their centroid positions
- Bearing-based (fallback): The pixel velocity vector of tracked vehicles is converted to a compass direction and matched against the bearing of nearby road segments from the shapefile
For cameras viewing interchanges or multiple roads, a suggestor-reviewer loop automatically generates ROI polygons:
- Suggestor: A vision-language model (GPT-5.3) receives the camera image + nearby road list and generates polygon coordinates using chain-of-thought reasoning
- Reviewer: Evaluates polygons on 5 criteria (on pavement, angle matches road, covers lanes, proper placement, reasonable size) with a score out of 20
- Iteration: If the score < 14/20, feedback is sent back to the suggestor for refinement (up to 3 iterations)
Camera-derived metrics are displayed alongside MnDOT detector readings for real-time comparison:
- Spatial matching: Detectors within 500m of the camera are matched using haversine distance from the metro config XML
- Temporal alignment: Both sources report at 30-second intervals, enabling direct comparison
- Historical overlay: ClickHouse provides same-time-yesterday data as dashed lines for trend analysis
| Parameter | Value | Rationale |
|---|---|---|
| Model | YOLOv8 nano | Fast inference for real-time streaming |
| Confidence | 0.3 | Balanced recall vs. precision for highway scenes |
| Vehicle classes | car (2), motorcycle (3), bus (5), truck (7) | COCO classes relevant to highway traffic |
| Tracking window | 10 frames Γ 3s = 30s | Matches MnDOT detector reporting interval |
| Occupancy formula | Ξ£ box_area / (image_area Γ 0.6) |
0.6 factor approximates visible road surface |
| Matching threshold | 50px centroid distance | Balances re-identification vs. new vehicle detection |
- Minnesota Department of Transportation (MnDOT) for publicly available camera feeds, detector data, and road geometry
- Ultralytics for the YOLOv8 object detection framework
This project is developed for research purposes at the University of Minnesota. See LICENSE for details.
If you use Camera2Detector in your research, please cite:
@software{camera2detector2026,
author = {Choi, Seongjin},
title = {Camera2Detector: Real-Time Traffic Camera Validation of Highway Detectors},
year = {2026},
institution = {University of Minnesota},
url = {https://github.com/UMN-Choi-Lab/camera2detector}
}Seongjin Choi, Ph.D. Assistant Professor, Department of Civil, Environmental, and Geo-Engineering University of Minnesota Twin Cities choi-seongjin.umn.edu