Skip to content

mosi1910/vehicle-detection-tracking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

🚗 Vehicle Detection, Tracking and Counting using YOLO + ByteTrack

📌 Project Overview

This project focuses on vehicle detection, multi-object tracking, and vehicle counting in traffic videos using multiple YOLO versions combined with ByteTrack.

The objective was to evaluate detection performance across different YOLO versions, apply preprocessing techniques to improve robustness (especially in low-light and night scenes), and analyze performance before and after custom dataset training.


🧠 Detection Models

The following YOLO versions were evaluated:

  • YOLOv8
  • YOLOv9
  • YOLOv10
  • YOLOv11

Model variants analyzed:

  • n (nano)
  • s (small)
  • m (medium)
  • l (large)
  • x (extra large)

Higher-capacity models (l, x) achieved better accuracy but with slower inference speed.

Tracking was performed using ByteTrack, which improves ID consistency by leveraging both high-confidence and low-confidence detections.


🚦 Vehicle Counting Strategies

Two counting methods were implemented:

1️⃣ ID-Based Counting (Tracking-Based)

Each detected vehicle was assigned a unique ID using ByteTrack.
Vehicles were counted based on unique tracked IDs across frames.

2️⃣ Virtual Line Crossing

A predefined virtual line was placed in the frame.
Vehicles were counted when crossing this line.

Both methods were evaluated before and after retraining.


🛠 Preprocessing Techniques

To improve detection performance, especially in challenging lighting conditions, several preprocessing techniques were applied.

1️⃣ CLAHE (Contrast Enhancement)

Contrast Limited Adaptive Histogram Equalization was used with:

  • clipLimit = 2.0
  • tileGridSize = (8, 8)

This improved local contrast in low-contrast frames.


2️⃣ Shadow Removal

Steps:

  • Convert image to HSV color space
  • Normalize the V channel using: cv2.normalize(v, None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX)

This reduced dark shadow regions and improved detection stability.


3️⃣ Gamma Correction (Night Videos)

Gamma value used: gamma = 2.2

Applied using a lookup table transformation to enhance brightness in dark scenes.


4️⃣ Noise Reduction

Applied filters:

  • Gaussian Blur
  • Bilateral Filter

These reduced noise while preserving object boundaries.


📊 Dataset Preparation & Training

Custom dataset creation was performed using Roboflow.

Dataset Preparation:

  • 1 frame extracted per second from each video
  • Manual annotation
  • Dataset split:
    • 80% Train
    • 10% Validation
    • 10% Test

Training Details:

  • Base model: YOLOv8n
  • Epochs: 100
  • Training environment: Google Colab

📈 Training Results

Video 1 Dataset

Precision = 0.87
Recall = 0.62
F1 = 0.72
mAP50 = 0.66

Video 2 Dataset

Precision = 0.88
Recall = 0.50
F1 = 0.64
mAP50 = 0.57

Video 3 Dataset

Precision = 1.00
Recall = 0.97
F1 = 0.99
mAP50 = 0.99

Video 4 Dataset

Precision = 0.93
Recall = 0.61
F1 = 0.74
mAP50 = 0.96

Video 5 Dataset

Precision = 0.95
Recall = 0.64
F1 = 0.77
mAP50 = 0.97


📦 Merged Dataset Training

After merging all five datasets:

Precision = 0.96
Recall = 0.64
F1 = 0.77
mAP50 = 0.75

Merged training improved generalization across different traffic conditions.


🔬 Final Processing Pipeline

Final processing steps applied before detection:

  1. Convert image to grayscale
  2. Apply CLAHE
  3. Convert back to RGB
  4. Apply sharpening filter
  5. Apply Gaussian Blur
  6. Run detection using the retrained merged model

This final pipeline improved robustness, particularly in challenging lighting scenarios.


⚠️ Code Availability

The original training and experimentation code was developed in Google Colab. Due to loss of access to the original notebook, only the project report and results are available in this repository.


About

Vehicle detection, tracking, and counting project using YOLO + ByteTrack

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors