Skip to content

ube09/LaneVision

Repository files navigation

AITrafficInsights

Real-time vehicle detection, axle-based classification, and directional traffic counting from roadside camera feeds.

Python OpenCV YOLOv8 Pandas License

Overview

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.

Features

  • 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 helperpoints.py captures pixel coordinates from a frame to define counting lines and regions of interest.

Tech Stack

  • 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

Repository Layout

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.

Setup / Run

  1. Clone the repository

    git clone https://github.com/ube09/LaneVision.git
    cd LaneVision
  2. Create and activate a virtual environment

    python -m venv venv
    source venv/bin/activate        # On Windows: venv\Scripts\activate
  3. Install dependencies

    pip install ultralytics opencv-python pandas openpyxl xlsxwriter torch cvzone hydra-core
  4. 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.py to find pixel coordinates).
  5. Run a counter

    python Directional_count.py        # full NB/SB/EB/WB intersection counts
    # or a single leg:
    python nb.py
  6. Generate the formatted report (after predict.py produces a detection CSV)

    python report_export_files.py --file_data_path detected_vehicle_count.csv
  7. 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.

Customization

  • Counting lines / ROIs — edit reg_pts (ObjectCounter scripts) or counting_lines (Directional_count.py) to match your intersection geometry.
  • Target classes — adjust target_classes / classes.txt for the vehicle categories you want to count.
  • Aggregation interval — change the interval / update_interval value to control how often counts are written.

Author

Usama Bin Ejaz — AI/ML Engineer & Founder, UBE Labs ("AI that ships.")

License

This project is licensed under the MIT License.

About

Real-time vehicle detection, tracking, and axle-based classification with turning-movement counts and Excel reports

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors