Share technology, record life!
Paste the code directly:
void GMM(){
// Open the video file
VideoCapture capture("E:/LeftBag.mpg");
if (!capture.isOpened()){
cout << "Video open fail!" << endl;
return;
}
//Current video frame
Mat frame;
//Binary image of
foreground Mat foreground;
namedWindow("Extracted Foreground" );
//Objects of the mixed Gaussian model class, all use the default parameters
BackgroundSubtractorMOG2 mog;
bool stop(false);
//Travel through all frames in the video
while (!stop){
//Read the next frame
if (!capture. read(frame))
break;
// update background and return foreground
mog(frame, foreground, 0.01);
// learning rate
threshold(foreground, foreground, 128, 255, THRESH_BINARY_INV);
// show foreground
imshow("Extracted Foreground", foreground);
if (waitKey(10) >= 0)
stop = true;
}
}