Vehicle Detection and Count Using OpenCV
*Note: Sub-titles are not captured in Xplore and should not be used
line 1: 1st Given Name Surname
line 1: 2nd Given Name Surname line 1: 3rd Given Name Surname
line 2: dept. name of organization
line 2: dept. name of organization line 2: dept. name of organization
(of Affiliation)
(of Affiliation) (of Affiliation)
line 3: name of organization
line 3: name of organization line 3: name of organization
(of Affiliation)
(of Affiliation) (of Affiliation)
line 4: City, Country
line 4: City, Country line 4: City, Country
line 5: email address or ORCID
line 5: email address or ORCID line 5: email address or ORCID
line 1: 4th Given Name Surname
line 1: 5th Given Name Surname line 1: 6th Given Name Surname
line 2: dept. name of organization
line 2: dept. name of organization line 2: dept. name of organization
(of Affiliation)
(of Affiliation) (of Affiliation)
line 3: name of organization
line 3: name of organization line 3: name of organization
(of Affiliation)
(of Affiliation) (of Affiliation)
line 4: City, Country
line 4: City, Country line 4: City, Country
line 5: email address or ORCID
line 5: email address or ORCID line 5: email address or ORCID
XXX-X-XXXX-XXXX-X/XX/$XX.00 ©20XX IEEE
Abstract—In this paper the main focus is on detecting of Figure 1 Positions of the Four Cameras.
vehicle and counting, particularly in traffic control. Vehicle
detecting and also counting are becomes growing important in The image obtained from the cameras is in Fig. 2.
a area of highway regulators. However, because of the various
structure of vehicles, their detections remain challenging which
directly influence in accuracy of a vehicle count. This paper
address a image-based techniques for vehicle recognition and
counting based on OpenCV technologies. The outcome of an
Experiment shows the accuracy of the proposed counting
systems is around 96%.
Keywords—vehicle detection and counting, OpenCV
I. INTRODUCTION
The traditional traffic signal control system is based on the
time and date, and it cannot respond to the road conditions
in time. With the formation of the innovative city concept,
the traditional traffic control system has been unable to cope
with the ever-increasing traffic volume. According to the
report in America, people wasted 20 percent of their travel
Figure 2: Traffic Signal image
time by waiting for the red lights [4]. The road re-planning
Here we will use opencv model to detect number of cars,
project is expensive, and it is pretty dangerous for the traffic
trucks, bus, rikshaws and bike in image.
police standing in the middle of the intersection to relieve
Scope
the traffic. Intelligent traffic control systems become a
decent way to soothe traffic. In this project, we use camera 1. Helps traffic police: A vehicle detection and
images as the system input to deal with the traffic problem counting system could be beneficial for the traffic
to make the traffic signal control system more intelligent police because everything they can monitor from
and sufficient, hoping Taiwan becoming a smart city in the one place only likes how many vehicles have
future. crossed this toll and which vehicle.
We are developing a simulation from scratch using Pygame
to simulate the movement of vehicles across a traffic 2. Maintaining records: It is challenging for some
intersection having traffic lights with a timer. It contains a 4- individuals to record all the vehicles with them
way traffic intersection with traffic signals controlling the because the cars are passing by in real-time. It’s not
flow of traffic in each direction. Each signal has a timer on like that one is watching the video, and they can
top of it which shows the time remaining for the signal to pause it and have a note of it, so to remove this
switch from green to yellow, yellow to red, or red to green. limitation, this application can be very well-versed
Vehicles such as cars, bikes, buses, and trucks are generated, to attain the time-saving quality and be automated.
and their movement is controlled according to the signals
and the vehicles around them. This simulation can be further 3. Traffic surveillance control: As this application
used for data analysis or to visualize AI or ML applications. can be planted anywhere as it only requires a
The real-time traffic flow means how many vehicles pass camera or some wires (for establishing the
through in a period. There are two parts to this section. The connectivity with the central system) hence if the
first part is the vehicle counter, and the second part is to traffic is high at someplace, then from that area, an
decide the time length of calculating a result. We use four officer can monitor it and forward the information
cameras erect on the lamppost, which is near the to next toll officer so that they could be prepared
intersection, to watch out for the opposite side of the traffic beforehand.
conditions shown in Fig. 1
II. PREVIOUS WORK
From the past few years the traffic control has turned into a
serious issue for society. A variety of issues ranging from
traffic blockage, absence of vehicle parking, pollution etc.
have hassled humans. It has achieved major break in the
recent era. However, the detection and classification of
vehicles is a demanding concern. The scope in this area is
huge because of the variety of challenging features that
vehicles possess ranging from edges, colors, shadows,
corners, textures, etc. Due to the progress in hardware and
reduced manufacturing expenses, the amount of surveillance
devices has risen in the past few years, and video cameras
are of high resolutions used in these systems. An important
study of the surveillance system is the detection of different
vehicle types. The main phase in traffic management
software is the classification of vehicles. Prior information
of the model and vehicle type is required, because it allows [11], which comprises of foreground extraction, detection,
for queries as to know “which direction the vehicle has feature extraction and classification. A Gaussian Mixture
passed and at what time?”. Therefore, feature extraction and Model (GMM) is used in detection of vehicles and also
classification of vehicles cover a vast scope of traffic some operations are performed to get the foreground objects
management applications [3, 4]. and classification is done, using k-nearest neighbor
Yu Wang et al. 2019 [5], have developed a system for classifier. In 2015, Dong et al. [12] have recommended a
detection and classification of moving vehicles termed as semi-supervised convolutional neural network technique for
Improved Spatio-Temporal Sample Consensus. Firstly, the vehicles classification based on front view of vehicle. Yet,
moving vehicles are identified using Spatio Temporal the features trained by the CNN are too biased to work in
Sample Consensus algorithm, from the intrusion of raster images. In the same year, Banu et al. [13] have
brightness variation and the vehicles shadow. Furthermore, recommended Histogram of Gradient feature extraction
by means of feature fusion techniques the objects are technique and morphological operations for better detection
classified according to area, face, number plate and vehicle rate
symmetry features.
Chia-Chi Tsai et al. 2018 [6], proposed an optimized
Convolutional Neural Network architecture based on deep III. METHODOLOGY
learning algorithms for vehicle detection and classification
A. Prerequisites
system used for intelligent transportation applications.
PVANET as the base network, is selected and improved by We need to install the following python libraries if it is not
fine-tuning to get better accuracy. It uses eight Concatenated already installed:
ReLU convolution layers, eight inception layers as the base opencv-python
network and hypernet architecture is used to combine cvlib
different levels of features, thereby making it better to matplotlib
achieve the desired bounding boxes for the Region Proposal tensorflow
Net layer. keras
In 2018, Velazquez-Pupo et al. [7] have presented a model
based on vision analysis with a fixed camera for monitoring B. Algorithm Showing Pseudo Code for Vehicle Detection
the traffic, detection of vehicle that includes occlusion Using OpenCV
handling, counting, tracking and classification. Even though
Here is the code to import the required python libraries, read
the best classifier is SVM, still they reported that the OC-
an image from storage, perform object detection on the
SVM with an RBF Kernel has delivered the best results with
image, display the image with a bounding box and label
a high performance and F-measure of 98.190% and
about the detected objects, count the number of cars in the
99.051% for the midsize vehicles.
image and print it.
In the same year 2018, Murugan and Vijaykumar [8], have
import cv2
developed Adaptive Neuro Fuzzy Inference System
import matplotlib.pyplot as plt
classifier for classification of moving vehicles on the roads.
import cvlib as cv
It includes six main phases like pre-processing, feature
from cvlib.object_detection
extraction, detection, structural matching, tracking, and
import draw_bboxim = cv2.imread('cars_4.jpeg')
classification of vehicles. A background subtraction and the
bbox, label, conf = cv.detect_common_objects(im)
Otsu threshold algorithm are used for vehicular detection.
output_image = draw_bbox(im, bbox, label, conf)
The characteristics of the vehicles detected are obtained by
plt.imshow(output_image)
the log Gabor filter and Harrish corner detector, which are
plt.show()
used to classify the vehicles.
print('Number of cars in the image is '+ str(label.count('car')))
Ahmad Arinaldi et al. 2018 [9], presented a traffic video
print('Number of Bikes in the image is '+
analysis system based on computer vision techniques. The
str(label.count('motorcycle')))
core of such system is the detection and classification of
print('Number of Truck in the image is '+
vehicles for which they developed two models, first is a
str(label.count('truck')))
MoG + SVM system and the second is based on Faster
RCNN, a recently popular deep learning architecture for
detection of objects in images. They reported that Faster
RCNN outperforms MoG in detection of vehicles that are
static, overlapping or in night time conditions. Also, Faster
RCNN outperforms SVM for the task of classifying vehicle
types based on appearances.
In 2017, Audebert et al. [10] have conferred a segment
before detect approach using deep learning techniques.
Segmentation and followed by detection and classification
of multiple wheeled vehicle variants is tested for high-
resolution remote sensing pictures. The process detection
and classification of vehicles depending on a virtual
detection zone was suggested by Seenouvong et al. 2016
C. Result obtained 3.6.9 was used for running this code. We have used various
libraries of python like opencv-python, cvlib, matplotlib,
tensorflow, keras. The performance of the system is
evaluated using various real time vehicles images.
V. FURTHER WORK PLAN
The further tentative work plan can further be carried as:
Implementation of Basic Traffic Light System
Using Pygame
Design and implementation of intelligent traffic
light system using Pygame
Performance evaluation and validation of results.
VI. RESEARCH REFERENCES
[1] Intelligent Transportation Systems Joint Program Office. United
States Department of Transportation. Accessed 10 Nov 2016
[2] Aljawarneh, S.A., Vangipuram, R., Puligadda, V.K., Vinjamuri, J.: G-
SPAMINE: an approach to discover temporal association patterns and
trends in internet of things. Future Gener. Comput. Syst. 74, 430–443
(2017) 54 V. Keerthi Kiran et al.
[3] Huang, C.-L., Liao, W.-C.: A vision-based vehicle identification
system. In: Proceedings of the 17th International Conference on
Pattern Recognition, ICPR 2004, vol. 4, pp. 364–367 (2004)
[4] Kanhere, N.K.: Vision-based detection tracking and classification of
(Left) Original image with vehicles (source), (Right) Output vehicles using stable features with automatic camera calibration, p.
image with labelled vehicles 105 (2008)
[5] Wang, Y., Ban, X., Wang, H., Wu, D., Wang, H., Yang, S., Liu, S.,
Lai, J.: Detection and classification of moving vehicle from video
using multiple spatio-temporal features, recent advances in video
coding and security. IEEE Access 7, 80287–80299 (2019)
[6] Tsai, C.C., Tseng, C.K., Tang, H.C., Guo, J.I.: Vehicle detection and
classification based on deep neural network for intelligent
transportation applications. In: APSIPA Annual Summit and
Conference 2018. IEEE (2018)
[7] Velazquez-Pupo, R., Sierra-Romero, A., Torres-Roman, D.,
Shkvarko, Y.V., Santiago-Paz, J., Gómez-Gutiérrez, D., Robles-
Valdez, D., Hermosillo-Reynoso, F., Romero-Delgado, M.: Vehicle
detection with occlusion handling, tracking, and OC-SVM
classification: a high performance vision-based system. Sensors 18,
374 (2018)
[8] Murugan, V., Vijaykumar, V.R.: Automatic moving vehicle detection
and classification based on artificial neural fuzzy inference system.
Wirel. Pers. Commun. 100, 745–766 (2018)
[9] Arinaldi, A., Pradana, J.A., Gurusinga, A.A.: Detection and
classification of vehicles for traffic video analytics. In: INNS
Conference on Big Data and Deep Learning, Procedia Computer
Science, vol. 144, pp. 259–268 (2018)
[10] Audebert, N., Le Saux, B., Lefèvre, S.: Segment-before-detect:
vehicle detection and classification through semantic segmentation of
aerial images. Remote Sens. 9, 368 (2017)
[11] Seenouvong, N., Watchareeruetai, U., Nuthong, C.: Vehicle detection
and classification system based on virtual detection zone. In:
International Joint Conference on Computer Science and Software
Engineering (JCSSE) (2016)
(Left) Original image with vehicles (source), (Right) Output [12] Dong, Z., Wu, Y., Pei, M., Jia, Y.: Vehicle type classification using a
image with labelled vehicles semisupervised convolutional neural network. IEEE Trans. Intell.
Transp. Syst. 16(4), 2247–2256 (2015)
Python version 3.6.9 was used for running this code. [13] Banu, S., Vasuki, P.: Video based vehicle detection using
morphological operation and hog feature extraction. ARPN J. Eng.
Appl. Sci. 10(4), 1866–1871 (2015)
IV. CONCLUSION
During this work we have implemented vehicles detection
and classification system using OpenCV. Python version