Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top