YOLOv8-based traffic monitoring that detects two-wheelers and associates riders using IoU matching.
This project processes traffic images to detect motorcycles and bicycles, identify the people riding them, and produce annotated output images. It uses YOLOv8 for object detection and an IoU (Intersection over Union) check to associate each rider with their vehicle. A separate script demonstrates DNN-based face detection on a sample image.
Intended as a starting point for downstream traffic-safety tasks such as helmet detection, rider counting, or violation flagging.
- Two-wheeler detection — motorcycles and bicycles via YOLOv8 (
yolov8n.pt). - Rider association — bounding-box IoU > 0.3 between a person and a two-wheeler tags that person as a Rider.
- Batch image processing — every image in
images/is processed and the annotated result is saved todetections/. - GPU acceleration — automatically uses CUDA if available, otherwise falls back to CPU.
- Auxiliary face detector —
face.pyruns OpenCV's SSD/ResNet-10 face detector on a single image.
- Python 3.8+
- Ultralytics YOLOv8 (object detection)
- PyTorch (model backend, CUDA)
- OpenCV (image I/O, drawing, DNN face detector)
- NumPy, Matplotlib
SmartTrafficMonitoring/
├── main.py # YOLOv8 two-wheeler + rider detection pipeline
├── face.py # Standalone DNN face-detection demo
├── yolov8n.pt # Pre-trained YOLOv8 nano weights
├── images/ # Input images to process
└── detections/ # Annotated output images (auto-created)
git clone https://github.com/deepak0x/SmartTrafficMonitoring.git
cd SmartTrafficMonitoring
pip install ultralytics opencv-python torch numpy matplotlibThe first ultralytics import will download required dependencies. yolov8n.pt is included in the repo, so no separate model download is needed.
-
Drop your traffic images into the
images/folder. -
Run:
python main.py
-
Annotated results appear in
detections/asresult_<original_name>.- Two-wheelers are drawn in green with the label and confidence score.
- Associated riders are drawn in blue and labelled Rider.
Place an image named 1.jpg next to face.py, then run:
python face.pyA Matplotlib window opens showing detected faces with confidence percentages.
- YOLOv8 runs inference on each input image and returns bounding boxes + class labels.
- Boxes labelled
motorcycleorbicycleare collected as two-wheelers; boxes labelledpersonare collected separately. - For every two-wheeler, the IoU is computed against every person box. If IoU > 0.3, that person is tagged as the Rider of that vehicle.
- The annotated frame is written to
detections/.
- Helmet detection on the Rider crops.
- Number-plate OCR for flagged violations.
- Video input instead of a static
images/directory. - Real-time stream processing via RTSP / webcam.
MIT (add a LICENSE file if you want this enforced).
Deepak Bhagat — @deepak0x