OpenCV C++: How to slow down background adaptation of BackgroundSubtractorMOG?
background-subtraction, c++, opencv
Solution
BackgroundSubtractorMOG pBSMOG = BackgroundSubtractorMOG(int history=200, int nmixtures=5, double backgroundRatio=0.7, double noiseSigma=0);
Where,
- history – Length of the history.
- nmixtures – Number of Gaussian mixtures.
- backgroundRatio – Background ratio.
- noiseSigma – Noise strength (standard deviation of the brightness or each color channel). 0 means some automatic value.
Increasing the `history` value will slow down the adaptation rate.
There is another function available in OpenCV:
Ptr <BackgroundSubtractorMOG2> createBackgroundSubtractorMOG2(int
history=500, double varThreshold=16, bool detectShadows=true )
This is much faster than the previous one and it can eleminate detecting shadows too.
Problem
I am using BackgroundSubtractorMOG in OpenCV to track objects. When they appear, it works fine but the background fastly adapts so I cannot track static objects. How can I make the background adaptation slower (I dont want it fully static, just slower)? Setting the learning rate using the constructor doesn't change that: ``` BackgroundSubtractorMOG pBSMOG = BackgroundSubtractorMOG(???); ``` How can I solve this? Thanks!