Real-time vehicle detection, axle-based classification, and directional traffic counting from roadside camera feeds.
AITrafficInsights is a computer-vision pipeline for intelligent transportation systems. It ingests traffic camera video, detects and tracks vehicles in real time with YOLO, classifies them (including axle-based truck categories), and counts movements by approach and turning direction (left / through / right / incoming) for each compass leg of an intersection (northbound, southbound, eastbound, westbound).
Counts are aggregated over fixed time intervals and exported to timestamped Excel reports in the standardized turning-movement-count (TMC) layout that traffic engineers and urban planners use for analysis. The system has been run against real-world deployments, including live public traffic-camera feeds in the United States.
- Real-time vehicle detection & tracking — YOLO detection combined with object tracking (Ultralytics ObjectCounter, DeepSORT, SORT, and a custom centroid tracker) to maintain stable IDs across frames.
- Axle-based vehicle classification — distinguishes passenger vehicles from multi-axle trucks (2–6 axle), buses, vans, motorcycles, and cycles via a custom-trained model and
classes.txt. - Directional & turning-movement counting — per-leg counting lines (NB/SB/EB/WB) with left, through, right, and incoming movements, including line-crossing intersection logic.
- Speed estimation — pixel-to-distance calibration with per-direction speed brackets and CSV/Excel logging.
- Automated TMC Excel reports — interval-based aggregation exported to multi-sheet, formatted Excel workbooks (
report_export_files.py) ready for downstream traffic analysis. - Annotated output video — bounding boxes, track IDs, counting lines, and live per-direction count overlays written to an output video.
- Calibration helper —
points.pycaptures pixel coordinates from a frame to define counting lines and regions of interest.
- Language: Python 3.8+
- Computer Vision: OpenCV, Ultralytics YOLO (v8 / v11), cvzone
- Tracking: DeepSORT (PyTorch), SORT, custom CentroidTracker
- Deep Learning: PyTorch (CUDA-accelerated when available)
- Data / Reporting: Pandas, openpyxl, XlsxWriter
- Config: Hydra, YAML
| File | Purpose |
|---|---|
traffic_count.py |
Main directional counter using Ultralytics ObjectCounter (4 movements). |
Directional_count.py |
Full intersection counter (NB/SB/EB/WB) with custom centroid tracker and line-crossing logic. |
nb.py / sb.py / eb.py / wb.py |
Per-leg counting variants for northbound / southbound / eastbound / westbound approaches. |
count2.py |
SORT-based counter with a custom axle-class model. |
predict.py |
YOLOv8 + DeepSORT predictor with speed estimation and per-vehicle CSV logging. |
Speed.py |
Speed estimation with directional speed-bracket reporting. |
report_export_files.py |
Builds the formatted turning-movement-count Excel report from detection CSV. |
points.py |
Interactive helper to capture pixel coordinates for counting lines / ROIs. |
classes.txt |
Vehicle class labels (axle-based truck categories, bus, car, van, etc.). |
deep_sort.yaml |
DeepSORT tracker configuration. |
vehicle_counting.ipynb |
End-to-end notebook (Colab) for batch processing video and exporting reports. |
-
Clone the repository
git clone https://github.com/ube09/LaneVision.git cd LaneVision -
Create and activate a virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install ultralytics opencv-python pandas openpyxl xlsxwriter torch cvzone hydra-core
-
Add your model weights and videos
- Place YOLO weights in the project root (e.g.
yolov8n.pt, or your custom axle-classification model). - Put input videos in a
videos/directory (the directional scripts read from there). - Adjust the counting-line coordinates in each script to match your camera view (use
points.pyto find pixel coordinates).
- Place YOLO weights in the project root (e.g.
-
Run a counter
python Directional_count.py # full NB/SB/EB/WB intersection counts # or a single leg: python nb.py
-
Generate the formatted report (after
predict.pyproduces a detection CSV)python report_export_files.py --file_data_path detected_vehicle_count.csv
-
Output
- Annotated videos are written to the
output/directory. - Vehicle counts with timestamps are saved to
traffic_count_results.xlsx. - The formatted turning-movement report is saved to
vehicle_counting_export.xlsx.
- Annotated videos are written to the
- Counting lines / ROIs — edit
reg_pts(ObjectCounter scripts) orcounting_lines(Directional_count.py) to match your intersection geometry. - Target classes — adjust
target_classes/classes.txtfor the vehicle categories you want to count. - Aggregation interval — change the
interval/update_intervalvalue to control how often counts are written.
Usama Bin Ejaz — AI/ML Engineer & Founder, UBE Labs ("AI that ships.")
- GitHub: github.com/ube09
- Website: usamabinejaz.com
This project is licensed under the MIT License.