Project Description:
This project implements an intelligent traffic monitoring system that automatically detects and counts vehicles moving IN and OUT using a single video stream. By leveraging YOLOv8 for vehicle detection and custom object tracking with centroid smoothing and frame association (Hungarian Algorithm), the system can reliably count directional movement in real-time. A virtual centerline is defined, and any vehicle crossing it is counted only once based on direction.
Core Objectives:
-
➕ Track vehicles across frames using simple data association (Hungarian algorithm).
-
🔁 Count how many vehicles go “IN” and “OUT” based on line crossing.
-
✅ Prevent duplicate counts for the same vehicle using ID tracking.
-
🧠 Provide visually annotated output for human readability and audit.
Key Features:
-
✅ YOLOv8-based Detection: High-speed and lightweight object detection using
yolov8n.pt. -
🔁 ID-based Object Tracking: Tracks vehicles frame-to-frame using position-based data association.
-
🔄 Bidirectional Counter: Counts vehicles moving top-to-bottom (
IN) and bottom-to-top (OUT). -
🧠 Centroid Smoothing: Smooths jittery movement for stable detection using moving average.
-
🧾 Display Labels and Counts: Draws class label, ID, and bounding boxes on the video.
-
💾 Output Video Saving: Saves processed footage with bounding boxes and counters.
-
📏 Virtual Line Crossing Logic: Defines direction using a virtual line in the middle of the frame.
-
🧼 Disappeared Track Management: Automatically removes stale IDs after a delay.
Technologies Used:
-
Python 3.x – core scripting language.
-
YOLOv8 (Ultralytics) – for object detection.
-
OpenCV – for video processing, drawing, and real-time visualization.
-
NumPy – array manipulation and distance computation.
-
SciPy (
linear_sum_assignment) – for solving the Hungarian algorithm for ID matching. -
cv2.VideoWriter – for saving annotated videos to disk.
Use Cases:
-
🚦 Traffic Monitoring Systems – analyze road congestion or traffic flow at intersections or toll booths.
-
🏙️ Smart City Projects – enable real-time surveillance in urban infrastructure.
-
🧾 Audit and Reporting – generate video proof and numerical logs for traffic analysis.
-
📊 Transport Planning – evaluate IN/OUT flow on highways, flyovers, or parking lots.
Possible Enhancements:
-
🧠 Integrate deep learning-based tracking like DeepSORT for re-identification.
- 🎥 Detect multiple types of vehicles (cars, trucks, buses, bikes) in real-time.
-
🌐 Export real-time IN/OUT counts to cloud dashboards (e.g., Firebase, MQTT, InfluxDB).
-
📊 Include heatmaps or time-based analytics for vehicle density.
-
🔔 Add alerts for vehicle congestion or reversed flow.
-
🚧 Expand to lane-wise vehicle classification (left/right turns, lane hopping).
-
📱 Deploy to edge devices (Jetson Nano, Raspberry Pi) for cost-efficient deployment.
Conclusion:
This real-time vehicle flow monitoring solution demonstrates the power of combining YOLOv8 with custom tracking logic for bidirectional counting. It is accurate, customizable, and lightweight—ideal for smart surveillance and traffic analytics systems. It also serves as a great foundation for more advanced transport AI applications.


Reviews
There are no reviews yet.