Skip to content

Ankush443/Vehicle-Detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vehicle Detection System Documentation

Overview

This project implements a real-time vehicle detection system using YOLOv3 (You Only Look Once version 3) deep learning model and OpenCV. The system can detect multiple types of vehicles including cars, trucks, buses, and motorcycles from video streams.

Components

1. YOLOv3 Model

YOLOv3 is a state-of-the-art, real-time object detection system that:

  • Uses a single neural network to process the entire image
  • Divides the image into regions and predicts bounding boxes and probabilities
  • Processes images at 30 FPS
  • Has a backbone network of 53 layers (Darknet-53)

Required YOLOv3 files:

  • yolov3.weights: Pre-trained model weights
  • yolov3.cfg: Model configuration file
  • coco.names: Class names from COCO dataset

2. OpenCV Integration

OpenCV (cv2) is used for:

  • Video capture and frame processing
  • Drawing detection boxes and labels
  • Image preprocessing
  • Neural network implementation via cv2.dnn module

Key OpenCV features utilized:

  • cv2.dnn.readNet(): Loads the YOLO network
  • cv2.dnn.blobFromImage(): Preprocesses images for the network
  • cv2.dnn.NMSBoxes(): Performs non-maximum suppression
  • cv2.rectangle() and cv2.putText(): Drawing detection visualizations

Implementation Details

Class Structure: VehicleDetector

  1. Initialization (__init__):
def __init__(self):
    self.net = cv2.dnn.readNet(weights_path, config_path)
    self.conf_threshold = 0.5
    self.nms_threshold = 0.4
  1. File Verification (check_files):
  • Verifies presence of required YOLO files
  • Provides download links if files are missing
  1. Vehicle Detection (detect_vehicles):
  • Processes frames through YOLO network
  • Filters detections for vehicle classes (IDs: 2, 3, 5, 7)
  • Applies confidence thresholding
  • Performs non-maximum suppression
  1. Frame Processing (process_frame):
  • Draws bounding boxes around detected vehicles
  • Displays confidence scores and class labels
  • Shows total vehicle count

Integration Steps

  1. Model Loading:
self.net = cv2.dnn.readNet(weights_path, config_path)
self.classes = [line.strip() for line in f.readlines()]
  1. Image Preprocessing:
blob = cv2.dnn.blobFromImage(frame, 1/255.0, (416, 416), 
                            swapRB=True, crop=False)
  1. Detection Pipeline:
self.net.setInput(blob)
outputs = self.net.forward(self.output_layers)
  1. Post-processing:
  • Filtering detections based on confidence
  • Applying non-maximum suppression
  • Drawing results on frame

Performance Considerations

  1. Detection Parameters:
  • Confidence threshold: 0.5
  • NMS threshold: 0.4
  • Input size: 416x416 pixels
  1. Supported Vehicle Classes:
  • Cars (ID: 2)
  • Motorcycles (ID: 3)
  • Buses (ID: 5)
  • Trucks (ID: 7)

References

  1. YOLOv3 Paper:
  • Joseph Redmon, Ali Farhadi, "YOLOv3: An Incremental Improvement", arXiv:1804.02767, 2018
  1. Required Files:
  1. OpenCV Documentation:

Usage Instructions

  1. Ensure all required files are in the correct directory structure:
project/
├── src/
│   ├── yolov3.weights
│   ├── yolov3.cfg
│   └── coco.names
└── media/
    ├── 0.mp4
    ├── 1.mp4
    └── 2.mp4
    └── 3.mp4
    └── 4.mp4
  1. Run the script:
python vehicle_detector.py
  1. Press 'q' to exit the application

Notes

  • The system automatically resizes the display window based on input video dimensions
  • Real-time detection results are displayed with bounding boxes and labels
  • Total vehicle count is shown in the top-left corner

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages