Skip to content

deepak0x/SmartTrafficMonitoring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smart Traffic Monitoring

YOLOv8-based traffic monitoring that detects two-wheelers and associates riders using IoU matching.


Description

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.


Features

  • 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 to detections/.
  • GPU acceleration — automatically uses CUDA if available, otherwise falls back to CPU.
  • Auxiliary face detectorface.py runs OpenCV's SSD/ResNet-10 face detector on a single image.

Tech Stack

  • Python 3.8+
  • Ultralytics YOLOv8 (object detection)
  • PyTorch (model backend, CUDA)
  • OpenCV (image I/O, drawing, DNN face detector)
  • NumPy, Matplotlib

Project Structure

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)

Installation

git clone https://github.com/deepak0x/SmartTrafficMonitoring.git
cd SmartTrafficMonitoring
pip install ultralytics opencv-python torch numpy matplotlib

The first ultralytics import will download required dependencies. yolov8n.pt is included in the repo, so no separate model download is needed.


Usage

Two-wheeler + rider detection

  1. Drop your traffic images into the images/ folder.

  2. Run:

    python main.py
  3. Annotated results appear in detections/ as result_<original_name>.

    • Two-wheelers are drawn in green with the label and confidence score.
    • Associated riders are drawn in blue and labelled Rider.

Face detection demo

Place an image named 1.jpg next to face.py, then run:

python face.py

A Matplotlib window opens showing detected faces with confidence percentages.


How It Works

  1. YOLOv8 runs inference on each input image and returns bounding boxes + class labels.
  2. Boxes labelled motorcycle or bicycle are collected as two-wheelers; boxes labelled person are collected separately.
  3. 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.
  4. The annotated frame is written to detections/.

Possible Extensions

  • 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.

License

MIT (add a LICENSE file if you want this enforced).


Author

Deepak Bhagat@deepak0x

About

YOLOv8-based traffic monitoring that detects two-wheelers and associates riders via IoU matching

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages