Peculiar observations with Opencv BackGroundSubtractorMOG2 module — Opencv-3.0.0, Python-2.7.X, Ubuntu-14.04

asked 2015-08-25 14:24:48 -0600

desri gravatar image

I am using the BackGroundSubtractionMOG2() from Opencv-3.0.0 inside Python-2.7.x. I am observing something peculiar. That is, when I create the BackGroundSubtraction object and apply it to the first frame of a video feed, the mask that I get has 255 (uint8) at all pixels. This implies that the algorithm thinks the entire image is moving. I find that nonsensical, if it is an initialization issue, then by default the mask should have 0 value at all pixels. Does anyone experience this issue.

Any help would be much appreciated.

edit retag flag offensive close merge delete



This is the same behavior I've observed in the past using OpenCV 2.4.x. It is indeed an initialization issue, because it can't create a model of the background with just one frame (an even though from frame 2 on the mask is not all white anymore, it still needs some more frames to give an accurate model of the background). You say it is non-sense, but in my opinion initializations are just that, initializations, and therefore any convention should be ok. If fact, you can see it as "ok, I can't create a model of the background yet so I suppose everything is foreground until I have more info).

LorenaGdL gravatar imageLorenaGdL ( 2015-08-26 03:45:21 -0600 )edit

Hi, Thanks for your insight. While I agree that my take on the issue of initialization was a little harsh, I am not entirely wrong in my opinion. If it is hard for the algorithm to figure out the mask beginning from the first frame, then instead of setting all pixels equal to 255, it should, in fact, set the first mask pixels to be equal to zero. Don't you think that makes more sense?

desri gravatar imagedesri ( 2015-08-26 17:39:52 -0600 )edit

Yes and no :). I see your point, but I think you're missing the important thing: the algorithm has 2 main steps - 1)create/update a model of the background and 2)substract that model from the image, generating a foreground mask. It can't create the model with the first frame, so it is that background model what is set to all zeros, and therefore the following subtraction results in a mask with all pixels set to foreground. So, the algorithm is indeed applying your logic, but in the creation of the background model, which is the first step and the very real initialization.

LorenaGdL gravatar imageLorenaGdL ( 2015-08-27 04:57:35 -0600 )edit