Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top