Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I found that (since some version of OpenCV) when I call the method apply from the BackgroundSubtractorMOG object, it is using a default learningRate parameter set at 0.0, so the BackgroundSubtractor is not "learning" the new frames, it just sticks to the first frame used.

To avoid it, I have to call the method apply with an explicit learningRate parameter, then it works as it worked before.

So after starting the code:

bg1 = cv2.BackgroundSubtractorMOG()
cap = cv2.VideoCapture('video.mp4')
frame = cap.read()[1]

...instead of doing:

fg1 = bg1.apply(frame)

I should do:

fg1 = bg1.apply(frame, learningRate=0.001)