What is the history parameter in BackgroundSubtractorMOG2?

asked 2015-09-07 08:44:28 -0600

miav gravatar image

I'm on OpenCV for java. I have read and understood the Zivkovic paper about the algorithm. I can't seem to understand what the history param in the BackgroundSubtractorMOG2 constructor is about.

From here, https://github.com/Itseez/opencv/blob... , line 106, it is said that alpha = 1/ history. That would mean that history is namely the T parameter inside the paper, i.e. (more or less) the number of frames that constitute the training set.

However it doesn't seem so. Changing the value in the constructor, from 10 to 500 or beyond, has no effect on the final result.

Mat result = new Mat();
int history = 10; //or 50, or 500, or whatever
BackgroundSubtractorMOG2 sub = new BackgroundSubtractorMOG2(history, 16, false);
for (....) {
    sub.apply(frame[i], result);
}
//here result is the same no matter what "history" I have set

Where as, I can change the alpha value in the apply() call, and that is really effective:

Mat result = new Mat();
float alpha = 0.1;
BackgroundSubtractorMOG2 sub = new BackgroundSubtractorMOG2(whatever, 16, false);
for (....) {
    sub.apply(frame[i], result, alpha);
}
//if I change alpha here, result changes a lot, which is understandable.

So, either history is not equal to 1/alpha (or there's a bug in the java wrapper which make history useless). But then, what is it?

edit retag flag offensive close merge delete

Comments

1

In c++ I have found this line

learningRate = learningRate >= 0 && nframes > 1 ? learningRate : 1./std::min( 2*nframes, history );

Hence what is default value of learningRate when you call sub.apply(frame[i], result);? can you use sub.apply(frame[i], result,-1); ?

Of course it is C++ and I don't know java source code for MOG2. But may be it could help you.

LBerger gravatar imageLBerger ( 2015-09-07 11:22:04 -0600 )edit

Did you find an answer? I'm having a problem with this in opencv 2.4.11 for python. Changing the history value doesn't seem to work.

Eng4OpenCV gravatar imageEng4OpenCV ( 2016-10-20 13:28:31 -0600 )edit