Ask Your Question

Revision history [back]

If you have many small part of "motion", you could use either another background subtraction, like these one, but probably you still have noise. You may have to use Morphological Mathematics to remove this speckles, see [erode](http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=erode#void erode(InputArray src, OutputArray dst, InputArray kernel, Point anchor, int iterations, int borderType, const Scalar& borderValue), [dilate](http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=dilate#void dilate(InputArray src, OutputArray dst, InputArray kernel, Point anchor, int iterations, int borderType, const Scalar& borderValue), and [morphologyEx](http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=morphologyex#void morphologyEx(InputArray src, OutputArray dst, int op, InputArray kernel, Point anchor, int iterations, int borderType, const Scalar& borderValue) with OPEN and CLOSE.

Keep in mind, the background subtraction is to see what pixels are moving, if you want to track an object, you have to perform a tracking of this object, with blob or anything else.

click to hide/show revision 2
Adding part on vehicles detection

If you have many small part of "motion", you could use either another background subtraction, like these one, but probably you still have noise. You may have to use Morphological Mathematics to remove this speckles, see [erode](http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=erode#void erode(InputArray src, OutputArray dst, InputArray kernel, Point anchor, int iterations, int borderType, const Scalar& borderValue), [dilate](http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=dilate#void dilate(InputArray src, OutputArray dst, InputArray kernel, Point anchor, int iterations, int borderType, const Scalar& borderValue), and [morphologyEx](http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=morphologyex#void morphologyEx(InputArray src, OutputArray dst, int op, InputArray kernel, Point anchor, int iterations, int borderType, const Scalar& borderValue) with OPEN and CLOSE.

Keep in mind, the background subtraction is to see what pixels are moving, if you want to track an object, you have to perform a tracking of this object, with blob or anything else.

[Update] For vehicles detection, there is many workflows. Some of them are even not using background subtraction. You could Google it if your are interested. But in your case, I think you should look at this paper: Robust Vehicle Detection for Tracking in Highway Surveillance Videos using Unsupervised Learning, Tamersoy and Aggarwal, in Advanced Video and Signal Based Surveillance, 2009. It used background subtraction, and histogram of oriented gradient with an SVM for binary classification. All these algorithms are in OpenCV, therefore, you could start testing directly.