Real-Time Moving Vehicle Detection, Tracking, and Counting System Implemented With Opencv
Real-Time Moving Vehicle Detection, Tracking, and Counting System Implemented With Opencv
Real-Time Moving Vehicle Detection, Tracking, and Counting System Implemented With Opencv
A. Adaptive background generation in gray scale After having original background, we apply Gaussian
filters to smooth the following image frames and convert all
Firstly, our algorithm reads image frames from video, RGB color images to gray ones. The background gray
decomposes the initial 50 image frames into RGB channels, image and the current grayscale image are shown in Fig. 2(a)
weights average of the top 50 frames, and gets an original and Fig. 2(b), respectively.
background picture. This original background could be Following software calculates the difference between the
erroneous if there are moving objects present in the field of grayed image of background and the current image frame, that
view, but it will converge to a robust background after means we can extract the foreground presenting the moving
handling more frames thanks to the operation of “Background objects shown in Fig. 2(c).
update”. At the same time, the system updates in real-time the
background image in the above difference calculation
Read Video frame processing. The latest background image can be defined as a
weighted sum of the current background and the extracted
foreground.
YES
Frame>50 B. Binarization with shadow removal
III. VIRTUAL DETECTOR detector in running system is highlighted with the thin red
rectangular box and shown in Fig. 3(a). While vehicles pass
Here we shall present a technique called “Virtual through the virtual detector, pixel changes in histogram can be
Detector” to count the moving vehicle in each lane. found as shown in Fig. 3(b).
The traditional and popular technology to detect the
vehicle on road is based on principle of electromagnetic IV. BLOB TRACKING
induction. Its sensor is a real inductive loop being buried
under the road. Once a vehicle enters, passes through, and To track a moving object is to detect the movement of the
leaves the lane area embedded inductive loop below, induced object, number the moving object, and obtain its trajectory.
current will change and indicate the presence of vehicle. In our method we adopt the blob tracking technology to track
However, this technology in practical application will and number the vehicles moving in the field of view from the
encounter some challenges such as difficult construction, recorded video camera.
expensive cost, short lifetime, etc. The whole process of blob tracking can be divided into
In this paper, we propose a method in combination of several modules at following: foreground detection module,
vehicle detection and virtual detector to count the number of new blob detection module, blob tracking module, path
vehicles on road in real time. It draws a set of rectangular generation module, and trajectory of post-processing module.
regions of interest (ROIs) in each lane as the virtual detector The processing flow is shown as Fig. 4 and all modules are
in image space, and determines the presence of vehicles by described in detail at below:
monitoring changes in area of virtual detector. The virtual a) Foreground detection module: To determine each
pixel in image space belongs to foreground or
background. This part of processing can be resulted
from Section II;
b) New blob detection module: Using the latest
foreground detected previously to check new blob
corresponding to the vehicle just entering into the
field of view on the road;
c) Blob tracking module: Monitoring the new blobs
detected previously to initialize the tracking to all
(a) Grayed background (b) Grayed current input frame existing blobs;
d) Path generation module: To collect all trajectories of
being tracked blobs and save the corresponding
trajectory at the end of each trace (such as tracking
lost, leaving scene, etc.);
e) Trajectory of post-processing module: Mainly to
smooth the trajectory.
(a) (b)
(g) Binary image after filling Fig. 3 Virtual detector. (a) Be highlighted with red color of
rectangular region in image space. (b) Pixels change in histogram
Fig. 2 Example of algorithm processing. while vehicle traversing
Experimental results, implemented with OpenCV,
Video
indicate that the proposed method is effective to detect, track,
frame Foreground
detection
New blob
detection
Blob
tracking
Trajectory of
post-processing
Blob˄IDˈ and count moving vehicles accurately.
POSˈSize˅
module module module module
REFERENCES
Path
Blob position generation [1] S. Sivaraman and M. Trivedi, “Looking at vehicles on the road: A
correction module survey of vision-based vehicle detection, tracking, and behavior
analysis”, IEEE Transactions on Intelligent Transportation Systems,
vol. 14, no. 4, pp. 1773-1795, 2013.
Fig. 4 Flowchart of blob tracking. [2] Y. Liu, B. Tian, S. Chen, F. Zhu, and K. Wang, “A survey of
vision-based vehicle detection and tracking techniques in ITS”, 2013
IEEE International Conference on Vehicular Electronics and Safety
functions mainly aimed at real-time computer vision. (ICVES), pp. 72-77.
We mount a video camera on footbridge crossing a main [3] M. Lei, D. Lefloch, P. Gouton, and K. Madani, “A Video-Based
street to monitor three lanes simultaneously and avoid Real-Time Vehicle Counting System Using Adaptive Background
erroneous counting caused by vehicle overlapping in image. Method”, 2008 IEEE International Conference on Signal Image
Technology and Internet Based Systems, pp. 523-528.
The results of two different approaches and their respective [4] G.D. Sullivan, K.D. Baker, A.D.Worrall, C.I. Attwood, and P.M.
accuracy rate are listed in Table 1. The accuracy rate Remagnino, “Model-based vehicle detection and classification using
reaches to 97.1% for virtual detector method, and 98.4% for orthographic approximations”, Image and Vision Computing, vol. 15,
blob tracking method. From the table, we observe that this no. 8, pp. 649-654, 1997.
[5] S. Gupte, O. Masoud, R.F.K. Martin, and N.P. Papanikolopoulos,
system is able to detect, track, and count most vehicles “Detection and classification of vehicles”, IEEE Transactions on
successfully. Intelligent Transportation Systems, vol. 3, no. 1, pp. 37-47, 2002.
[6] S.C. Lee and R. Nevatia, “Speed Performance Improvement of Vehicle
VI. CONCLUSION Blob Tracking System”, in Multimodal Technologies for Perception of
Humans, Lecture Notes in Computer Science, vol. 4625, pp: 197-202,
Due to increasing demands in ITS, there is a huge amount 2008.
of potential applications of detecting, tracking, and counting [7] N. Otsu, “A threshold selection method from gray-level histograms”,
IEEE Transactions on Systems, Man, and Cybernetics, vol. 9, no. 1, pp.
the moving vehicles on road in real time. 62-66, 1979.
In this paper we presented unitized techniques to achieve [8] P.S. Liao, T.S. Chen, and P.C. Chung, “A Fast Algorithm for Multilevel
the goal. In vehicle detection, we applied a method to Thresholding”, Journal of Information Science and Engineering, vol.
accurately separate the vehicle foreground from the adaptive 17, no. 5, pp. 713-727, 2001.
[9] B. Sun, S. Li, “Moving Cast Shadow Detection of Vehicle Using
background model through a combination of Otsu’s Combined Color Models”, 2010 Chinese Conference on Pattern
thresholding method and moving cast shadow detection Recognition (CCPR), pp. 1-5.
method. In vehicle tracking and counting, we applied two [10] A. Sanin, C. Sanderson, and B.C. Lovell, “Shadow detection: A survey
methods (virtual detector and blob tracking) to double check and comparative evaluation of recent methods”, Pattern Recognition,
vol. 45, no. 4, pp. 1684-1695, April 2012.
the accuracy and maturity of our proposed method. [11] OpenCV User Site: http://opencv.org/
[12] OpenCV on SourceForge: http://sourceforge.net/projects/opencvlibrary/