Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Python cv2.BackgroundSubtractorMOG2 history parameter doesn't work

I'm using opencv 2.4.11 with python 2.7.12.

The BackgroundSubtractorMOG2 works (i.e. background subtraction results are ok), but I wanted to tune the parameters.

However, changing the history parameter is not showing any changes the in the background subtraction results.

Here is the code snippet:

history = 30  #I've also tried 2,5,20,200
varThreshold = 16
bShadowDetection = False
bgSub = cv2.BackgroundSubtractorMOG2(history, varThreshold, bShadowDetection)

learningRate = 0.1
for currentFrame in allFrames:  #assume allFrames is a list containing the images
    fgMask = bgSub.apply(currentFrame, None, learningRate)

I've also tried setting the history using the setInt method:

history = 30  #I've also tried 2,5,20,200
varThreshold = 16
bShadowDetection = False
bgSub = cv2.BackgroundSubtractorMOG2(history, varThreshold, bShadowDetection)

bgSub.setInt('history',30)

learningRate = 0.1
for currentFrame in allFrames:  #assume allFrames is a list containing the images
    fgMask = bgSub.apply(currentFrame, None, learningRate)

Has anyone else had this problem or know what's going on?