Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV C++: How to slow down background adaptation of BackgroundSubtractorMOG?

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!

like image 498
user2212461 Avatar asked Feb 14 '23 18:02

user2212461


1 Answers

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.

like image 106
Anoop K. Prabhu Avatar answered May 12 '23 18:05

Anoop K. Prabhu