A Computer Vision Based Vehicle Detection and Counting System
A Computer Vision Based Vehicle Detection and Counting System
Counting System
Noboru Ohnishi
Graduate School of Information Science
Nagoya University
Furo-cho, Chikusa-ku, Nagoya-shi 464-8601 Japan
[email protected]
Abstract—A vehicle detection and counting system plays an For example, a video sequence of road can be processed and
important role in an intelligent transportation system, especially analyzed to detect and count vehicles. Further information,
for traffic management. This paper proposes a video-based such as the speed of a vehicle or traffic density, can also be
method for vehicle detection and counting system based on calculated by using computer vision. This would directly
computer vision technology. The proposed method uses benefits to two groups of people: road users and traffic
background subtraction technique to find foreground objects in a administrations. If road users know the real-time traffic
video sequence. In order to detect moving vehicles more information, they can then use the information to choose the
accurately, several computer vision techniques, including best way for traveling and can avoid traffic congestion. On the
thresholding, hole filling and adaptive morphology operations,
other hand, traffic administrations can utilize the traffic
are then applied. Finally, vehicle counting is done by using a
virtual detection zone. Experimental results show that the
information in their traffic control systems, resulting to a better
accuracy of the proposed vehicle counting system is around 96%. traffic management.
There are several methods for vehicle detection and
Keywords- vehicle detection; vehicle counting; virtual detection counting proposed so far. Li et al. [1] proposed a real-time
zone; computer vision vehicle detection, tracking, and counting system. Their
proposed system, firstly, used an adaptive background
I. INTRODUCTION subtraction technique to detect moving objects in a video.
Traffic problem is an important issue happening in many Secondly, it performed a binarization process to obtained
cities in the world. There are many important causes of the foreground area, followed by morphological operations to
traffic problem. The number of people moving into an urban remove noise and shadow. Thirdly, to avoid an over-
area has grown substantially, leading to a dramatic increase in segmentation problem, the foreground image obtained from the
the number of vehicles. However, roadway capacity has grown previous step was integrated with the edge image of the same
relatively slow and become insufficient. This causes an frame, before applying a hole filling process. Then, vehicles
imbalance between the numbers of vehicles and roads, were detected and counted by using a detector virtually located
resulting in road traffic congestion, especially in large cities. on the road. Finally, a blob tracking was done to match
An inadequacy of public transportation systems also causes the vehicles in the current frame and those in the previous frame.
same problem. Another cause is an inefficient traffic Bhaskar and Yong [2] proposed a vehicle detection and
administration due to a lack of real-time traffic information. tracking method using Gaussian mixture model (GMM)
The traffic problem mentioned earlier seems to be more severe together with a blob detection technique. In particular, GMM
in the future if it is not solved appropriately. was trained to model the background, and was then used to
extract foreground pixels based on the Mahalanobis distance.
Nowadays, computer vision—an analysis and interpretation Morphological operations were then applied to remove noises
of images and videos captured by a digital camera—has gained and to combine blob fragments together. Next, a blob analysis
more popularity and been used in many fields including was done to identify vehicle blobs. Finally, counting and
industry, robotics, medicine, etc. Computer vision has also tracking were done. Kryjak et al. [3] presented a hardware-
been applied for solving traffic and transportation problems. software system for vehicle detection and counting at road
,(((
224
intersections, in which two popular techniques, i.e.,
background subtraction and optical flow, could not be used to
detect vehicles stopping by a red signal. Instead, three
similarity measurements of the area around a detector in two
consecutive frames were used to detect the presence of
vehicles. Patch analysis was then performed to determine the
number of vehicles in the detector area. Liu et al. [4] proposed
a real-time vehicle counting methods based upon virtual
detection line and spatio-temporal contour techniques. (a) (b)
Specifically, GMM was used to detect moving foreground
pixels on the detection line in each frame. By combining this
information of several consecutive frames, a contour of a
vehicle in the spatio-temporal domain could be constructed.
This contour was then analyzed to determine the number of
vehicles. Some other algorithms for shadow detection and
shadow removal were proposed in [5,6].
This paper proposes a method of vehicle detection and
counting system based on a computer vision technology. (c)
Firstly, a background subtraction technique is used to find an
image of foreground objects. Secondly, a region of interest in Fig. 2 Foreground extraction: (a) background frame
the image is then processed by several techniques, including (b) current frame (c) difference image
adaptive morphological operations, to remove noises and
enhance foreground objects. Next, the centroid of each
foreground object is calculated and used to represent the
position of a vehicle. Finally, vehicles in a predefined virtual Zone 5
detection zone are recorded and counted. Zone 4
Region of
interest Zone 3
Zone 2
Background image Video frame
Zone 1
(a) (b)
Gray-scale conversion Gray-scale conversion
Background subtraction
Virtual detection
zone
Establishing region of interest
Thresholding (c)
225
background image of the road, which contains no vehicle, and to be 50. The result after thresholding operation, which is a
the current frame in the video are converted from color (RGB) binary image, is shown in Fig. 4(b).
to gray-scale image (Fig. 2(a) and Fig. 2(b)). Then, for each
pixel (x, y), the gray intensity of the background image is It is noted that at this step, the binary image contains both
subtracted by that of the current frame. The absolute result is spurious and missing foreground pixels. Therefore, a number
stored into the same position in another image, which is called of techniques are used to remove noises and enhance
a difference image (Fig. 2(c)). foreground objects. Firstly, hole filling operation is applied to
remove black pixels enclosed by white regions. The image
after hole filling process is shown in Fig.4 (c). Then,
morphology operations are used to remove noises and some
fail regions in the image. In particular, small foreground
objects are converted into background by morphological
erosion operation with a rectangle structuring element of size
3×3. The result after erosion operation is shown in Fig. 4(d).
Next, an adaptive morphological dilation is applied to
recover some missing foreground pixels and to connect
(b)
foreground fragments together. Here, a rectangle structuring
(a)
element is also used but its size is adaptively chosen based on
the zone defined in Section II-B. The size of structuring
element is set to be 13×13, 11×11, 9×9, 7×7 and 5×5
rectangles, for zones 1 to 5, respectively. It is observed that
foreground objects become smoother, clearer and more
appropriate for detection and counting process. Fig. 4(e) is the
result after adaptive morphological dilation. The contours of
each foreground object is then extracted (Fig. 4(f)). This
information will be used in the next step for vehicle counting.
(c) (d)
(a) (b)
(e) (f)
Fig. 4 Vehicle detection: (a) differnce image in ROI (b) binary image
(c) hole filling image (d) eroded image (e) dilated image
(f) vehicle contour
226
virtual detection, its status will be set to 1 (counted), indicating accurately, we established conditions to manage vehicle’s blob
that it has been counted and will not be counted in the through the controlling the region of interest, divided to each
subsequent frames. The examples of vehicle counting are zone for to detect and count vehicle. Then, several computer
shown in Fig. 5. vision techniques, including thresholding, hole filling,
morphology operation, were applied to remove noise and to
III. EXPERIMENTAL RESULTS AND DISCUSSION enhance foreground objects. Next, we extracted the contour of
detected foreground objects and calculated their centroids.
To collect a database of road videos, a digital camera was Finally, the vehicles were detected and counted when their
set-up on a flyover. Seven input videos of road, around three to centroid passed into the virtual detection zone. Experimental
seven minutes, were recorded during 10 am to 2 pm. The results showed that the accuracy of the proposed vehicle
spatial resolution of the recorded videos was 1280×720 pixels, counting method was 96%.
with temporal resolution of 30 frames per second.
It should be noted that there are limitations of the proposed
The proposed method was implemented in C++ language method to be concerned with. Firstly, the vehicles appeared in
using OpenCV library [7]. An experiment was done to measure the video are assumed to be clear and not occluded inside the
the accuracy of vehicle detection. In particular, when an input virtual detection zone and secondly, the width of the virtual
video was fed into the proposed method, the number of detection zone should be large enough for counting the
vehicles detected by the proposed method would be shown and vehicles. Furthermore, there are additional vehicles’ features to
be compared with those obtained by a manual counting be taking into account for vehicle detection in various setups.
(ground truth). The experiment was done on a laptop powered These issues will be the major concerns in the future work.
by an Intel(R) Core i5 (1.7-2.4 GHz) CPU and 4 GB RAM.
Experimental results are shown in Table I. The accuracy of ACKNOWLEDGMENT
the proposed vehicle counting method varied from 95-99%, This work was supported by King Mongkut’s Institute of
depending on the input videos. It suggests that the proposed
Technology Ladkrabang Research Fund (KREF015808).
method could perform quite well on every tested video. In
total, 646 vehicles out of 667 in all seven input videos could be
detected, resulting in an accuracy of 96.85%. REFERENCES
227