Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top