I have the following code.

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);
}

How can I clear the background model and update it again from beginning? Like it has not been updated before. What should be the code to replace the TODO part in the code above?

有帮助吗?

解决方案

Call void initialize(Size frameSize, int frameType); method.

//clear background model
backgroundModel.initialize(image.size(), image.type());

According to source code thie methos will clear internal model.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top