This Python project uses YOLO11 for real-time vehicle detection from a YouTube video stream. It tracks vehicles like cars and displays the total number of vehicles passed along with the elapsed time on the video stream.
- Real-time vehicle detection using YOLO11.
- Detects cars from YouTube live streams and videos.
- Tracks detected vehicles using SORT (Simple Online and Realtime Tracking).
- Displays bounding boxes and vehicle counts on the video stream.
- Shows elapsed time and vehicle counts on the video.
-
Clone the repository:
git clone https://github.com/pablocaeg/opencv-traffic-detector.git cd opencv-traffic-detector
-
Install dependencies:
pip install filterpy scikit-image numpy opencv-python torch ultralytics yt-dlp
-
Install SORT:
SORT isn't available via
pip
, so you need to install it manually:git clone https://github.com/abewley/sort.git cd sort pip install -r requirements.txt python setup.py install
-
Run the script:
python3 detection.py
-
Replace the YouTube URL:
- In
detection.py
, replace theyoutube_url
variable with the YouTube video or livestream URL you want to process:
youtube_url = 'https://www.youtube.com/watch?v=YOUR_VIDEO_ID'
- In
- Total Cars Passed: Counts and displays the total number of cars detected during the video stream.
- Elapsed Time: Shows how long the script has been running in HH:MM:SS format.
When the script is running, you'll see a video stream with bounding boxes around the detected cars and real-time stats overlaying the video.
Example of stats:
Cars Passed: 14
Time Elapsed: 00:12:43