Last update: 30/04/2015
See Vehicle Detection, Tracking and Counting in GitHub
Hi everyone,
There are several ways to perform vehicle detection, tracking and counting.
An easy way to do vehicle detection is by using Haar Cascades (please, see Vehicle Detection with Haar Cascades section). Currently, I don't have a tutorial about it, but you can get some extra information in the OpenCV homepage, see Cascade Classifier page.
Another way to do vehicle detection is by using Background Subtraction (BS). You can try to use a background subtraction library like BGSLibrary (developed by me in my master course). See Vehicle Detection with Background Subtraction section for more details. An example source code for C++ beginners using the BGSLibrary can be seen in Demo.cpp file.
If you want to do vehicle tracking, maybe you will need to use a tracking algorithm. The Haar Cascades is not the best choice for vehicle tracking because its large number of false positives. To do this, one suggestion is to use a BS algorithm. But, only a BS algorithm is insufficient to do vehicle tracking, you will need a blob tracker algorithm or a library like cvBlob or OpenCVBlobsLib. I've another youtube video performing vehicle tracking using the BGSLibrary with the cvBlob library (please, see Vehicle Tracking and Counting section).
Here is some tips to do vehicle tracking and counting:
1. First, perform a background subtraction.
2. Send the foreground mask to cvBlob or OpenCVBlobsLib.
3. The cvBlob library provide some methods to get the centroid, the track and the ID of the moving objects. You can also set if you want to draw a bounding box, or the centroid and the angle of the tracked object.
4. Check if the centroid of the moving object has crossed a virtual line (or region) in your video. For more information, please see my source code in the Vehicle Tracking and Counting section.
5. Voilà! enjoy it :)
Some traffic video databases:
Vehicle Detection, Tracking and Counting
Tools: Visual Studio C++ 2010, OpenCV, BGSLibrary, cvBlob and Boost.
Tools: Visual Studio C++ 2010, OpenCV, BGSLibrary, cvBlob and Boost.
Vehicle Detection with Haar Cascades
The source code can be downloaded here:
The haar-cascade cars3.xml was trained using 526 images of cars from the rear (360 x 240 pixels, no scale).
The images were extracted from the Car dataset proposed by Brad Philip and Paul Updike taken of the freeways of southern California.
For more information, please see:
* Train Your Own OpenCV Haar Classifier
* Related paper:
Oliveira, M.; Santos, V. Automatic Detection of Cars in Real Roads using Haar-like Features (PDF)
* Some additional resources:
* Related project: