“历史”的含义是什么?里面BackgroundSubtractorMOG2? [英] What is the meaning of "history" inside BackgroundSubtractorMOG2?

查看:699
本文介绍了“历史”的含义是什么?里面BackgroundSubtractorMOG2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OpenCV的java(但这不相关,我猜)。我使用的是 BackgroundSubtractorMOG2 类.htmlrel =nofollow>此处。我已阅读并了解了关于算法的Zivkovic文章,您可以在这里找到。 p>

BackgroundSubtractorMOG2 在其构造函数中接受 history 的参数。它是什么,它如何影响结果?



类源代码,第106行,据说 alpha = 1 / history 。这意味着历史就是纸张中的T参数,即(或多或少)构成训练集的帧数。



但是它不会似乎是。将构造函数中的值从10更改为500或更大,对最终结果具有无效。这是我所说的:

  Mat result = new Mat 
int history = 10; //或50,或500,或任何
BackgroundSubtractorMOG2 sub = new BackgroundSubtractorMOG2(history,16,false);
for(....){
sub.apply(frame [i],result);
}
imshow(result); //让我们看看最后一帧

,500,1000 - 结果总是相同的。然而,如果我通过 apply()更改 alpha 值(学习率),我可以看到它的真实影响:

  Mat result = new Mat(); 
float alpha = 0.1; //学习速率,1 / T(1 /历史?)
BackgroundSubtractorMOG2 sub = new BackgroundSubtractorMOG2(whatever,16,false);
for(...){
sub.apply(frame [i],result,alpha);
}
imshow(result);

如果我在这里更改alpha,结果变化很多,这是可以理解的。所以,两个猜想:


  1. 历史 $ c> 1 / alpha 作为源代码状态。但是:那是什么?它如何影响算法?


  2. 历史真的 1 / alpha ,但是在java包装器中有一个错误,使得在构造函数中设置的历史值无用。


您能帮我吗?



(标记c ++也是关于OpenCV类的问题,整个OpenCV的java框架只是c ++的一个包装)

解决方案

清除 alpha = 1 / history (除了一些暂时的时刻)。在void BackgroundSubtractorMOG2Impl :: apply 方法中:

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

您可以测试 BackgroundSubtractorMOG2 对象使用您在构造函数中使用 getHistory()方法传递的历史值。


I'm on OpenCV for java (but that's not relevant I guess). I'm using the BackgroundSubtractorMOG2 class which is (poorly) referenced here. I have read and understood the Zivkovic paper about the algorithm which you can find here.

BackgroundSubtractorMOG2 takes in its constructor a parameter called history. What is it, and how does it influence the result? Could you point me to its reference inside the paper, for example?

From the class source code, 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. This is what I'm calling:

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);
}
imshow(result); //let's see last frame

It doesn't matter what history I set, be it 5, 10, 500, 1000 - the result is always the same. Whereas, if I change the alpha value (the learning rate) through apply(), I can see its real influence:

Mat result = new Mat();
float alpha = 0.1; //learning rate, 1/T (1/history?)
BackgroundSubtractorMOG2 sub = new BackgroundSubtractorMOG2(whatever, 16, false);
for (...) {
    sub.apply(frame[i], result, alpha);
}
imshow(result);

If I change alpha here, result changes a lot, which is understandable. So, two conjectures:

  1. history is not really 1/alpha as the source code states. But then: what is it? how does it affect the algorithm?

  2. history is really 1/alpha, but there's a bug in the java wrapper that makes the history value you set in the constructor useless.

Could you help me?

(Tagging c++ also as this is mainly a question about an OpenCV class and the whole OpenCV java framework is just a wrapper around c++).

解决方案

It seems clear that alpha = 1 / history (except for some transitory instants). In void BackgroundSubtractorMOG2Impl::apply method:

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

You can test if the BackgroundSubtractorMOG2 object is using the history value that you pass in the constructor using the getHistory() method.

这篇关于“历史”的含义是什么?里面BackgroundSubtractorMOG2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆