This project loads still images from traffic webcam URLs, combines them into a mosaic, runs YOLO object detection, and counts vehicles that appear red based on HSV color filtering inside each detected bounding box.
The app opens a live OpenCV window and updates every few seconds.
red_car_live.py- Main scripturls.txt- Webcam image URLs (one per line)yolov8n.pt- YOLO model weights
- Python 3.9+
- pip
- Internet access (for webcam URLs)
Python packages:
- ultralytics
- opencv-python
- numpy
- requests
Install packages:
pip install ultralytics opencv-python numpy requests
From this folder, run:
python red_car_live.py
Then press ESC in the OpenCV window to quit.
urls.txt should contain one image URL per line. Empty lines and lines starting with # are ignored.
Example:
https://example.com/cam1.jpg
https://example.com/cam2.jpg
# https://example.com/disabled.jpgDefault run:
python red_car_live.py
Faster refresh and larger model:
python red_car_live.py --refresh 2 --model yolov8s.pt
Count multiple vehicle classes:
python red_car_live.py --vehicles car,truck,bus,motorcycle
Custom tile size and fixed columns:
python red_car_live.py --tile-size 640x360 --cols 3
Tune red sensitivity:
python red_car_live.py --min-red-ratio 0.12
--urls-file(default:urls.txt)
Text file with one URL per line.--model(default:yolov8n.pt)
YOLO weights file (for exampleyolov8n.pt,yolov8s.pt).--refresh(default:5.0)
Seconds between refresh cycles.--tile-size(default:960x540)
Mosaic tile size asWIDTHxHEIGHT.--cols(default:0)
Number of mosaic columns (0= auto).--conf(default:0.35)
YOLO confidence threshold.--iou(default:0.45)
YOLO IoU threshold.--min-red-ratio(default:0.08)
Minimum red-pixel ratio in a detected vehicle box to classify it as red.--vehicles(default:car)
Comma-separated YOLO class names to treat as vehicles.--per-cycle-unique
Enable simple near-duplicate suppression per cycle.
- The script counts detections per refresh cycle and keeps a running total.
- Red classification is HSV-based and may need tuning depending on lighting/weather.
- If a webcam URL fails or returns non-image content, it is skipped for that cycle.
- If
pythonis not found, use your full Python path or launcher (py). - If model loading fails, confirm
yolov8n.ptexists in this folder or pass--modelwith a valid path. - If nothing appears, verify URLs in
urls.txtreturn valid images in a browser.
.png)