我有以下代码。
cv::VideoCapture capture;
cv::Mat image;
cv::Mat foregroundMask
cv::BackgroundSubtractorMOG2 backgroundModel;
// update background model
for(int i = 0; i < 10; ++i)
{
capture >> image;
backgroundModel(image, foregroundMask);
}
//clear background model
// TODO
// update background model
for(int i = 0; i < 10; ++i)
{
capture >> image;
backgroundModel(image, foregroundMask);
}
如何清除背景模型并重新从头开始更新?就像以前没有更新过一样。应该用什么代码来替换上面代码中的 TODO 部分?
最佳答案
调用voidinitialize(SizeframeSize, intframeType);
方法。
//clear background model
backgroundModel.initialize(image.size(), image.type());
根据source code该方法将清除内部模型。
关于opencv - 清除背景SubtractorMOG2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19809499/