Skip to content

Awais-Asghar/Vehicle-Detection-and-Counting-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vehicle Detection and Counting System

Project Status Platform Language Framework IDE License

Image

Introduction

The Vehicle Detection and Counting System is a real-time traffic monitoring solution built using Python, OpenCV, and YOLOv4. It is capable of identifying, tracking, and counting vehicles from a video feed or image sequence. It also features a voice interface using pyttsx3 for audible alerts. This project addresses the growing need for intelligent traffic systems, helping to automate vehicle monitoring, enhance traffic flow analysis, and improve smart city infrastructure.


Problem Statement

Manual vehicle counting is time-consuming, error-prone, and not scalable for high-traffic areas. Our system aims to solve this by providing a fully automated, accurate, and scalable solution using computer vision and deep learning.


Overview

This Python script is designed for real-time vehicle detection and counting using YOLOv4, OpenCV, pyttsx3, and a custom object detection module. The system identifies vehicles in a video stream, assigns unique IDs for tracking, and provides a voice-guided interface.

Motivation

  • Eliminate manual traffic counting.
  • Provide real-time vehicle monitoring and alerts.
  • Enable smart city infrastructure and intelligent traffic systems.
  • Collect accurate traffic data for analytics and prediction.

Scope

  • Real-time vehicle detection in videos.
  • Counting vehicles with unique IDs using tracking.
  • Voice interaction for detected vehicle counts.
  • Can be integrated with traffic lights, CCTV, or smart surveillance systems.

Why Python?

Python is the preferred language for computer vision applications due to:

  • Easy syntax and rapid prototyping
  • Seamless integration with OpenCV
  • Support for deep learning frameworks like YOLO, TensorFlow, etc.
  • Libraries like pyttsx3 make voice interaction easy

Alogorthim:

Image Image

Libraries Used

Library Purpose
cv2 (OpenCV) Video capture, image processing, bounding boxes
math Distance calculations between object centers
numpy Frame matrix manipulation and array processing
pyttsx3 Text-to-speech output for vehicle counts
art Generates ASCII art title screen for CLI
textblob Optional NLP tasks like text analysis
Image Image Image Image Image Image Image

Flow Chart

Image Image

Installation

You have to download the latest version of python.

Prerequisites

Make sure you have Python installed. You can download it from python.org.

Install Required Libraries

Once python is installed then open the command window and run these commands.

pip install opencv-python
pip install numpy
pip install art
pip install pyttsx3
pip install textblob
pip install colorama

Download YOLOv4 Weights

Download the YOLOv4 weights files and give the address of that files in object_detection.py.

Place the weights and cfg files in the object_detection directory .

Usage

Image Image
  1. Open the script in a code editor.

  2. Customize the image/video file path according to your path:

    video = cv2.VideoCapture("C:\\Users\\DELL\\OneDrive\\Desktop\\Project\\Highway.mp4")
  3. Modify the YOLOv4 weights path:

    od = ObjectDetection(weights_path="path/to/yolov4.weights")
  4. Run the script:

    python vehicle_detection.py

Working

Image Processing:

Firstly you to download the libraries by using the above commands and then you have to save all the images and video files where your main.py file is located. When you will run the code then you have to answer some questions. When program ask for image processing then you have to put the name of that file only e.g 1 It depens on your image name and extension of image should be .png. For video processing repeat the same process and extension of video file should be .mp4

1

2

It can detect cars in smog also.

10

It can detect and count cars at night also.

26354

Video Processing:

3

Conclusion

The Vehicle Detection and Counting System provides a reliable, real-time solution for identifying and tracking vehicles using Python, OpenCV, and YOLOv4. It automates traffic monitoring with accurate detection and voice-based interaction, making it suitable for smart city and surveillance applications. This project lays the groundwork for future enhancements in intelligent transportation systems.

Image

About

This is my first repository and it is based on object detection and object tracking of vehicles. It will first detect and count the vehicles.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages