该方法可以用来做运动检测,用法:
Ptr<BackgroundSubtractorMOG2> mog = createBackgroundSubtractorMOG2(100,25,false);
- history:用于训练背景的帧数,默认帧数为500帧,如果不动手设置learingRate,history就被用于计算当前的learningRate, 此时history越大,learningRate越小,背景更新越慢;
- varThreshold:方差阈值,用于判断当前像素是前景还是背景。一般默认为16,如果光照变化明显,如阳光下的水面,建议设为25,值越大灵敏度越低。
- detectShadows:是否检测影子,设为true为检测,false为不检测,检测影子会增加程序时间复杂度,一般设置为false;
eg:mog->apply(src_YCrCb, foreGround, 0.005);
- image 源图
- fmask 前景(二值图像)
- learningRate 学习速率,值为0-1,为0时背景不更新,为1时逐帧更新,默认为-1,即算法自动更新;