BackgroundSubtractorMOG still saves the object after it leaves the frame

I tried using BackgroundSubtractorMOG to remove the background, but there are some objects that have already left the frame, but the result of BackgroundSubtractorMOG.apply () still shows that the object is still on the scene.

Here is my code

inputVideo = cv2.VideoCapture('input.avi') fgbg = cv2.BackgroundSubtractorMOG() while inputVideo.isOpened(): retVal, frame = inputVideo.read() fgmask = fgbg.apply(frame) cv2.imshow('Foreground', fgmask) cv2.imshow('Original', frame) if cv2.waitKey(1) & 0xFF == 27: break 

I also tried BackgroundSubtractorMOG with custom parameters (history = 200, nmixtures = 5, ratio = 0.8), but the result is the same. Did I do something wrong or any decision? Please, help.

+5
source share
1 answer

The problem is fgbg.apply . For some reason, the learningRate parameter is set to 0 . Do this:

 history = 10 # or whatever you want it to be fgmask = fgbg.apply(frame, learningRate=1.0/history) 

The loan should go to Sebastian Ramirez, who launched a ticket in opencv and found a solution

+8
source

Source: https://habr.com/ru/post/1201970/


All Articles