A traffic monitoring system that performs vehicle detection, multi-object tracking, vehicle counting, and speed estimation using YOLOv8, SORT Tracker, OpenCV, and cvzone.
The system processes traffic videos, detects multiple vehicles, assigns unique tracking IDs, counts vehicles crossing a predefined line, estimates vehicle speeds, and provides real-time traffic analytics.
- Real-time vehicle detection using YOLOv8
- Multi-object tracking using SORT Algorithm
- Vehicle counting using line-crossing detection
- Vehicle speed estimation
- Real-time traffic analytics dashboard
- Region of Interest (ROI) detection using masking
- Unique ID assignment for tracked vehicles
- Video-based traffic monitoring
| Technology | Purpose |
|---|---|
| Python | Core implementation |
| YOLOv8 | Object detection |
| SORT | Multi-object tracking |
| OpenCV | Image and video processing |
| cvzone | Visualization and annotations |
| NumPy | Numerical operations |
Multi-Object-Tracking-Traffic-Analytics/
│
├── Traffic_Analytics.py # Main application
├── yolov8l.pt # YOLOv8 model weights
├── Traffic.mp4 # Input traffic video
├── Mask.png # Region of Interest mask
├── sort.py # SORT tracker implementation
└── README.md # Documentation
pip install opencv-python numpy cvzone ultralyticsMake sure the following files are present in the project folder:
yolov8l.ptTraffic.mp4Mask.pngsort.py
Run the application:
python Traffic_Analytics.pyPress:
q
to close the application.
YOLOv8 detects vehicles from video frames and provides:
- Bounding boxes
- Object classes
- Confidence scores
Detected vehicle categories:
- Car
- Truck
- Bus
- Motorbike
SORT tracker assigns a unique ID to each vehicle and maintains tracking across multiple frames.
It helps in:
- Following vehicle movement
- Maintaining object identity
- Preventing duplicate counting
A predefined counting line is placed on the road.
When a tracked vehicle crosses the line:
- The vehicle count is increased
- The unique ID prevents repeated counting
Vehicle speed is estimated using:
- Object movement between frames
- Time difference between frames
- Pixel-to-meter conversion scale
Note: Accurate speed calculation requires proper camera calibration.
The system displays real-time information:
- Total vehicles counted
- Average speed
- Active vehicle tracks
- Vehicle ID
- Vehicle class
- Confidence score
- Estimated speed
cap = cv2.VideoCapture("Traffic.mp4")Replace the video file path or use:
cv2.VideoCapture(0)for camera input.
model = YOLO("yolov8l.pt")Available YOLOv8 models:
yolov8n.pt→ Faster processingyolov8s.ptyolov8m.ptyolov8l.pt→ Better accuracy
Currently configured classes:
["car", "truck", "bus", "motorbike"]limits = [100,400,1200,400]Format:
[x1, y1, x2, y2]
Coordinates can be adjusted according to the camera view.
PIXEL_PER_METER = 15.0This value controls the conversion between pixel movement and estimated real-world speed.
- Improved speed calibration
- Number plate recognition
- Traffic violation detection
- Accident detection
- Vehicle type classification
- Live CCTV integration
- Advanced traffic reporting system
- Traffic flow monitoring
- Road surveillance
- Vehicle counting systems
- Smart transportation systems
- CCTV-based traffic analysis
Rida Irfan Artificial Intelligence Student
- Ultralytics YOLOv8
- SORT (Simple Online and Realtime Tracking)
- OpenCV
- cvzone
This project is developed for educational and research purposes.