OpenCV Python cv2.BackgroundSubtractor parameters -
Overview
It does not affect the results of the algorithm change parametes of BackgroundSubtractorMOG is.
I'm Python: 2.7.6 | Anaconda 2.1.0 (64-bit)
OpenCV: '2.4.10'
OS: Windows 7 x 64
The default criteria for algorithm are as follows:
Reproductive Problem
First, create two parameters with different parameters;
bg1 = cv2.BackgroundSubtractorMOG () bg2 = cv2.BackgroundSubtractorMOG (history = 3, nmixtures = 5, backgroundRatio = 0.0001)
2 "VideoCaptrue ago "The objects:
cap = cv2.VideoCapture ( 'video.mp4') cap2 = cv2.VideoCapture ( 'different_video.mp4')
Test a frame from the first capturing object: frame = cap.read () [1] # get both background foreground masks subtractors: fg1 = bg1.apply (frame) Fg2 = bg2.apply (frame) # both results and Show the difference between the two: cv2.imshow ('window name', np hstack (fg1, fg2, fg1-fg2))) cv2.waitKey (30) < / Code>
After running that block of code for a few frames, the window first shows the results from the background subtractor, r and the difference between the two and the two are included.
Because both masks are the same, the result of their difference (third pane) is a full black frame:
Then, suddenly change the source of the video (second video capture object): get a frame from the second capturing object: frame = Cap2.read () [1] # Get foreground mask from both background subtractors: fg1 = bg1.apply (frame) fg2 = bg2.apply (frame) # Both the result Program and show the difference between them: cv2.imshow ( 'Window name', NP Acstak ((fg1, fg2, fg1 - fg2))) cv2.waitKey (30)
and After running that block of code of some frames:
Two foreground masks look the same, and this is the reason that the third panel is a complete black frame.
But the last block of code for more than 3 frames after the RU, the results of the second panel should be blackened again ( history = 3
due to bg2
in the manufacture of the object). But both background subtractors keep getting the same results (as shown by the third full black pane).
option
I have also tried to modify my standards:
< P>
"(for example):
& gt; bg 2.getInt ('history') 3
< / Pre>
What I have found is that (when there are some versions of OpenCV) when I call the method
BackgroundSubtractorMOG
object, it's a Setting the defaultlearningRate
parameter to0.0
, therefore BackgroundSubtractor is not "learning" New Frame, it just used Sticks to the first frame.To avoid this, I have to call the method
apply
with a clear education rate parameter, then it works as before.after starting T code:
bg1 = cv2. background Sbttractor Emoji (hats) = CV 2. Veediokapcr ( 'video.mp4') frame = Cap.read () [1]
... instead of:
fg1 = bg1.apply (frame)
I should:
fg1 = bg1.apply (frame, learning rate = 0.001)
Comments
Post a Comment