AIreport Dharmit
AIreport Dharmit
On
Vehicle Detection
Submitted to
Institute
Code:017
Vishwakarma Government Engineering College, Chandkheda
Prepared by:
Patel Dharmit
210170111127
ELECTRONICS & COMMUNICATION (Semester - VII)
Month & Year:
October-2024
Vishwakarma Government
Engineering College
Vishwakarma Government
Engineering College,
Nr. Visat three roads, Sabarmati-Koba
Highway, Chandkheda, Ahmedabad,
Gujarat, India-382424
CERTIFICATE
I am deeply grateful to my project guide, Prof. Navin Ganesha, for his invaluable
guidance, patience, and support throughout this journey. I consider myself fortunate to
have worked with such considerate and encouraging professors. My heartfelt thanks
also go to our HOD, Dr. Arun Nandurbarkar, for providing me with this excellent
opportunity to work on the project titled “Vehicle Detection.” This project would not
have been possible without their unwavering support.
I would also like to express my sincere gratitude to my parents, friends, and family
members for their continuous encouragement and support during this project.
Additionally, I would like to extend my thanks to the college personnel for granting
me access to the valuable resources required for the successful completion of this
project.
Thank you
Abstract
Vehicle counting and speed detection are critical elements for traffic management, congestion control,
and road safety analysis. This research presents an advanced system for vehicle counting and speed
detection using computer vision and deep learning techniques. Additionally, speed estimation is
achieved by tracking the detected vehicles over time, using frame-by-frame analysis with a calibrated
camera setup. The model is trained on a diverse dataset to ensure reliability under different weather
conditions, lighting variations, and road types. The system provides valuable insights into traffic
patterns, enabling authorities to make informed decisions for traffic control, resource allocation, and
infrastructure planning. Experimental results validate the accuracy and robustness of the system,
showcasing its capability to effectively manage real-world traffic scenarios.
TABLE OF CONTENTS
Sr. Pg.
Content
No. No.
Introduction 1
1
Components 2
2
System Design 2
3
Implementation 3
4
Output 8
5
Conclusion 10
7
References 10
8
Introduction
Vehicle counting and speed detection are essential components of modern traffic management systems,
playing a vital role in monitoring traffic flow, reducing congestion, and enhancing road safety. This
project demonstrates how Python, using the OpenCV library, can be employed to count vehicles and
detect their speeds from real-time video feeds. The vehicle detection and tracking functionality is based
on computer vision techniques, including background subtraction and object detection, to identify and
count vehicles while calculating their speeds.
The ability to detect, count, and track vehicles is a critical aspect of various modern applications, such
as intelligent traffic systems, congestion control, and law enforcement. Vehicle counting and speed
detection have numerous real-world applications, ranging from automated traffic monitoring to smart
city development and road safety improvements.
This project demonstrates how to implement vehicle counting and speed detection using Python and the
OpenCV library, which is a powerful tool for image processing and computer vision. By leveraging
object detection and tracking algorithms, the program can efficiently detect vehicles, count them, and
estimate their speeds based on frame-by-frame analysis. The development of this project was carried
outin Visual Studio Code (VS Code), which provided a robust environment for managing the
code,debugging, and improving productivity throughout the development process.
1|Page
Components
Software: - Python: The programming language used to develop the eye detection logic. -
cv2: OpenCV library for image and video processing.
numpy: Used for numerical operations and handling
matrices. time.sleep: Used to control the speed of video
playback.
System Design
The vehicle counting and speed detection system aims to process video footage,
identify vehicles, count them, and determine their speed. The system is implemented
using Python with the OpenCV library and follows a modular architecture to handle the
different stages of video processing.
2|Page
Implementation
The following Python code uses the OpenCV library to Vehicle counting and speed
detection within a video.
import cv2
import numpy as np
sleep
# Parameters
cars
delay = 60 # FPS of the video (adjust this to match the video's FPS)
scale_factor = 0.05 # Assumed scale factor (meters per pixel, adjust this based on the
detec = []
carros =
3|Page
def pega_centro(x, y, w, h):
box.""" cx = x + int(w / 2)
4|Page
cy = y + int(h /
2) return cx, cy
file_path = r"C:\Users\Dell\OneDrive\Desktop\carvideo.mp4"
cap = cv2.VideoCapture(file_path)
# Background subtractor
subtracao = cv2.bgsegm.createBackgroundSubtractorMOG()
# Main processing
if not ret:
break
tempo = float(1/delay)
img_sub = subtracao.apply(blur)
(x, y, w, h) = cv2.boundingRect(c)
if not validar_contorno:
continue
centro = pega_centro(x, y, w, h)
detec.append(centro)
offset): carros += 1
if len(detec) > 1:
6|Pag
last_cx, last_cy = detec[-2]
car_speeds[carros] = speed_kph
detec.remove((cx, cy))
2, (0, 0, 255), 5)
if cv2.waitKey(1) == 27:
break
cap.release()
cv2.destroyAllWindows()
8|Pag
Output
9|Pag
Challenges and Limitations
10 | P a
Conclusion
The vehicle counting and speed detection system represents a significant advancement in the application
of computer vision technologies for real-time traffic monitoring and analysis. By leveraging Python and
the OpenCV library, this project demonstrates the feasibility of accurately detecting vehicles, counting
them as they pass a predefined line, and estimating their speed based on movement across video frames.
the successful execution of this project not only highlights the practical applications of vehicle
detection and speed estimation but also sets the groundwork for further exploration and
development in the realm of intelligent transportation systems.
References
OpenCV documentation (https://docs.opencv.org)-
Python tutorials and resources (https://www.python.org)-
OpenCV Python tutorials (https://opencv-python-tutroals.readthedocs.io)
11 | P a