How to use cv::BackgroundSubtractorMOG in OpenCV?

倾然丶 夕夏残阳落幕 提交于 2019-12-03 05:46:18

When you create mog, you are not defining any parameters, so it is created with default parameters. Here you have a description of each parameter, maybe is just that. Try with 3, 4 5 Gaussians.

This function does not perforn shadow-removal but you have this other function that does. Good luck!

There are recent algorithms which remove backgrounds (detect foreground) far better than the standard GMM implementation in OpenCV.

For example, there is a block-based classifier cascade approach described in this journal article, along with its C++ based source code.

austin

F.X.'s answer on this thread gives sample parameters of

backgroundSubtractor = new BackgroundSubtractorMOG(3, 4, 0.8);

I will recommend using the following settings to get started. Then you can start tuning your parameters:

cv::BackgroundSubtractorMOG2 mog;
mog(rawFrame,foregroundFrame,-1);
mog.set("nmixtures", 3);
mog.set("detectShadows",1);   

In this example I set the MOG2 subtractor with 3 Gaussian mixtures. I also enabled shadow detection.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!