This project implements a complete pipeline for real-time vehicle detection, multi-object tracking, counting, and speed estimation. It combines YOLO for object detection, OpenCV for video processing, and Supervision for annotation, tracking, and visualization.
Use cases include:
- Intelligent traffic monitoring.
- Vehicle flow analysis.
- Speed compliance and traffic law enforcement.
Watch the full demonstration on YouTube:
- Real-Time Vehicle Detection using YOLO.
- Accurate Multi-Object Tracking with ByteTrack.
- Vehicle Counting using configurable line zones (In/Out counts).
- Speed Estimation using Perspective Transformation.
- Supports custom YOLO models and various camera perspectives.
We use perspective transformation to convert camera view coordinates into a real-world top-down view. This is essential for accurate speed calculations.
Speed Formula:
speed (km/h) = (distance_in_meters / time_in_seconds) * 3.6
- Python (3.8+)
- YOLO (Ultralytics)
- OpenCV for video processing
- Supervision for tracking, line zones, and annotations
- NumPy for numerical computations
Vehicle-Speed-Estimation-and-Counting-YOLO-Supervision
│
├── data
│ ├── vehicles.mp4
│ ├── vehicles_output.mp4
│ ├── frame.png
│ └── annotated_frame.png
│
├── models
│ ├── yolov8n.pt
│ └── VisDrone_YOLO_x2.pt
│
├── src
│ ├── annotator.py
│ ├── speed_estimator.py
│ ├── view_transformer.py
│ └── __init__.py
│
├── config.py
├── main.py
├── requirements.txt
└── Vehicle_Speed_Estimation_main.ipynb
# Clone the repository
git clone https://github.com/Raafat-Nagy/Vehicle-Speed-Estimation-and-Counting-YOLO-Supervision.git
cd Vehicle-Speed-Estimation-and-Counting-YOLO-Supervision
# Install dependencies
pip install -r requirements.txt# Run the script
python main.pyYou can also check the Jupyter Notebook version:
Vehicle_Speed_Estimation_main.ipynb
- Add lane detection and traffic density analysis.
- Deploy as a web application for real-time traffic monitoring.
- Support multi-camera input with IoT integration.
- Export statistics to dashboards for analytics.

