π¦ Smart Traffic Analysis System
An end-to-end Computer Vision pipeline for real-time traffic monitoring that combines detection, tracking, and analytics into a single system.
π Features π Vehicle Detection using YOLOv8 π Multi-Object Tracking with ByteTrack π Real-World Speed Estimation using homography mapping π Wrong-Way Detection based on trajectory direction π¨ Red-Light Violation Detection using stop-line crossing π₯ Annotated Video Output with IDs, speed, and alerts β‘ Performance Monitoring (FPS) π§ System Overview
This system processes a video input and performs:
Object detection (vehicles)
Object tracking with persistent IDs
Pixel β real-world coordinate transformation
Speed estimation in km/h
Behavior analysis (direction + violations)
π οΈ Tech Stack
Python
OpenCV
Ultralytics YOLOv8
ByteTrack
NumPy
π Project Structure
traffic-analysis/
βββ main.py
βββ input.mp4
βββ yolov8n.pt
βββ bytetrack.yaml
βββ README.md
βοΈ Installation
pip install ultralytics opencv-python numpy
For accurate speed estimation, you must calibrate:
src_pts = np.float32([...]) # pixel points dst_pts = np.float32([...]) # real-world meters
π Tips:
Measure lane width or road distance in meters
Match 4 points from image β real-world rectangle
π¨ Violation Detection Logic
π΄ Red Light Violation
Vehicle crosses stop line while signal = RED
π Wrong Way Detection
Vehicle direction β expected traffic flow
https://github.com/user-attachments/assets/72a24807-cb94-40e7-98f8-50802a111e78 π€ Author
Awais Shah AI / ML | Computer Vision
β If you like this project
Give it a β on GitHub and feel free to contribute!