Ask Your Question

Revision history [back]

In order for the the history parameter to be used, the apply method needed to be called with the learningRate parameter set to -1 (actually anything less than or equal to zero should work). To see this, look in the source code file bgfb_gaussmix2.cpp in the BackgroundSubtractorMOG2::operator method definition. There you will find the following line:

learningRate = learningRate >= 0 && nframes > 1 ? learningRate : 1./min( 2*nframes, history );

Replacing the apply call in my original post with the following worked for me:

gMask = bgSub.apply(currentFrame, None, -1)

In order for the the history parameter to be used, the apply method needed to be called with the learningRate parameter set to -1 (actually anything less than or equal to zero should work). To see this, look in the source code file bgfb_gaussmix2.cpp in the BackgroundSubtractorMOG2::operator method definition. (Note, this operator method gets wrapped to the apply method for python). There you will find the following line:

learningRate = learningRate >= 0 && nframes > 1 ? learningRate : 1./min( 2*nframes, history );

If you explicitly set the learningRate to a value between 0 and 1 on each call to apply, then when nframes is greater than 1 the method will use the learningRate you specified and history will not be used.

Replacing the apply call in my original post with the following worked for me:

gMask = bgSub.apply(currentFrame, None, -1)