Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use cv::BackgroundSubtractorMOG in OpenCV?

I'm using OpenCV2.2 to implement moving objects detection with the method of Background Subtraction. And I use the Gaussian Mixture Model(GMM) method to model the background reference image.

I directly get the foreground pixels(or foreground mask) by using the class cv::BackgroundSubtractorMOG provided in OpenCV2.2. It's convenient but the foreground mask returned by cv::BackgroundSubtractorMOG is not as good as I expected. In addition, it seems that cv::BackgroundSubtractorMOG performs poorer than the method of GMM wrote in C language provided in OpenCV1.0.

The following is my code in OpenCV2.2:

cv::BackgroundSubtractorMOG mog;
mog(frame, fgMask, 0.01);

So, did I use the method in a wrong way?

By the way, does cv::BackgroundSubtractorMOG perform shadow removal on the foreground pixels?

Thank you very much.

like image 285
visualassit Avatar asked May 05 '12 03:05

visualassit


People also ask

How do I subtract two images in OpenCV?

You can subtract two images by OpenCV function, cv. subtract(). res = img1 - img2. Both images should be of same depth and type.

How is background subtraction done?

The background subtraction method (BSM) is one of the most popular approaches to detecting objects. This algorithm works by comparing moving parts of a video to a background image and foreground image.

What is background subtraction in OpenCV?

OpenCV >= 3.0. Background subtraction (BS) is a common and widely used technique for generating a foreground mask (namely, a binary image containing the pixels belonging to moving objects in the scene) by using static cameras.


2 Answers

When you create mog, you are not defining any parameters, so it is created with default parameters. Here you have a description of each parameter, maybe is just that. Try with 3, 4 5 Gaussians.

This function does not perforn shadow-removal but you have this other function that does. Good luck!

like image 123
Jav_Rock Avatar answered Oct 08 '22 06:10

Jav_Rock


There are recent algorithms which remove backgrounds (detect foreground) far better than the standard GMM implementation in OpenCV.

For example, there is a block-based classifier cascade approach described in this journal article, along with its C++ based source code.

like image 35
mtall Avatar answered Oct 08 '22 07:10

mtall