VEHICLE COUNTING, CLASSIFICATION &
DETECTION USING OPENCV & PYTHON
A Project Report Submitted in Partial Fulfillment of the Requirements for the
Award of Degree of Bachelor of Technology in Computer Science and
Engineering
Department of Computer Science and Engineering
Chandigarh Group of Colleges, COE
ABSTRACT
This project focuses on real-time Vehicle Detection, Classification, and Counting using
OpenCV and the YOLOv3 deep learning model. The goal is to automate traffic monitoring
systems to analyze vehicle flow and categories such as cars, buses, trucks, and motorbikes.
The YOLO algorithm identifies multiple objects in real-time by applying convolutional
neural networks and bounding box regression. The proposed system captures frames from
live or recorded video streams, detects vehicles, tracks their motion, and counts them as
they cross defined lines. The system uses Python, OpenCV, and YOLOv3 pre-trained weights
to achieve high accuracy and efficiency. The data is stored in CSV format for further analysis.
The results show that the model can classify and count vehicles in diverse traffic
environments, making it suitable for smart traffic management applications.
CHAPTER 1: INTRODUCTION
In the modern world, monitoring and managing traffic flow is an essential part of urban
infrastructure. Traditional methods of vehicle counting rely heavily on manual labor, which
is time-consuming, error-prone, and inefficient. With the advancements in computer vision
and artificial intelligence, automated systems can now detect, classify, and count vehicles
using real-time video feeds. The use of deep learning algorithms such as YOLO (You Only
Look Once) enhances the accuracy and speed of detection. This project demonstrates the
use of OpenCV and Python to implement a vehicle detection and classification system using
YOLOv3, a state-of-the-art object detection model.
Figure 1.1: YOLO Architecture Overview
The objective of this project is to build an efficient and scalable solution for vehicle
detection and classification in traffic videos. The project aims to automate traffic data
collection to support smart city initiatives, congestion control, and intelligent
transportation systems.
CHAPTER 2: LITERATURE REVIEW
Vehicle detection and tracking have been active research areas in computer vision for
decades. Early methods used background subtraction and frame differencing techniques,
which failed under varying lighting and weather conditions. With the evolution of deep
learning, models like R-CNN, Fast R-CNN, and YOLO have revolutionized object detection.
YOLOv3, in particular, provides real-time detection by dividing the input image into grids
and predicting bounding boxes and class probabilities. Previous works demonstrated
success in vehicle detection using YOLO and OpenCV integration, enabling efficient
detection of multiple vehicle classes from live video streams.
CHAPTER 3: SOFTWARE REQUIREMENT SPECIFICATION (SRS)
The system requires Python (version 3.8 or higher) and OpenCV (version 4.4 or higher).
YOLOv3 pre-trained model weights and configuration files are essential for detection. The
software environment includes:
- Operating System: Windows / Linux
- Programming Language: Python
- Libraries: OpenCV, NumPy, CSV, Math
- Hardware: GPU (NVIDIA recommended) or CPU for inference
- Input: Video stream or image file
- Output: Counted and classified vehicles stored in CSV
CHAPTER 4: SYSTEM DESIGN
The system design includes the following components:
1. Video Frame Acquisition
2. Object Detection using YOLOv3
3. Object Tracking using Euclidean Distance Tracker
4. Vehicle Counting and Classification
5. Data Storage
Figure 4.1: System Architecture Diagram
Figure 4.2: Data Flow Diagram (DFD)
Figure 4.3: UML Use Case Diagram
CHAPTER 5: IMPLEMENTATION
The project integrates YOLOv3 for vehicle detection through OpenCV’s DNN module. Each
frame from a video is processed to extract objects, and bounding boxes are drawn around
detected vehicles. A Euclidean distance tracker ensures that vehicles are not double-
counted. When vehicles cross predefined lines in the video, the counter updates the number
of vehicles moving in upward or downward directions. The system supports both real-time
video and static image processing. Results are stored in CSV files for further analysis.
CHAPTER 6: TESTING AND RESULTS
The model was tested on sample traffic videos with multiple lanes and different vehicle
types. The results show high accuracy in detection and counting. The system successfully
classified cars, motorbikes, buses, and trucks. The performance depends on video quality
and lighting conditions. The output frames displayed bounding boxes, class labels, and
counts in real time. Data was also logged into CSV files for record keeping and further
analysis.
Figure 6.1: Output of Vehicle Detection and Counting
CHAPTER 7: CONCLUSION AND FUTURE SCOPE
This project successfully implements an automated system for vehicle detection,
classification, and counting using OpenCV and YOLOv3. The system can efficiently analyze
real-time video streams, classify vehicles, and count them accurately. Such systems can
greatly benefit smart cities by automating traffic management and providing data-driven
insights for urban planning. Future work can include integrating YOLOv8 or advanced
transformer-based models, enabling multi-camera integration, real-time analytics
dashboards, and cloud-based data storage.
REFERENCES
[1] Redmon, J., & Farhadi, A. (2018). YOLOv3: An Incremental Improvement. arXiv preprint
arXiv:1804.02767.
[2] Bradski, G. (2000). The OpenCV Library. Dr. Dobb’s Journal of Software Tools.
[3] TechVidvan. (2021). Vehicle Counting, Classification, and Detection using OpenCV &
Python. Retrieved from https://techvidvan.com/tutorials/vehicle-detection-opencv/