opencv背景去除建模,如果是基于高斯混合模型,就会停止工作,但是基于k近邻的话,就可以运行,希望大佬指点。
代码如下:
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char**) {
VideoCapture capture;
capture.open("E:/images/1.avi");
if (!capture.isOpened()) {
printf("could not load video date...\n");
return -1;
}
Mat frame;
Mat bsmaskMOG2;
namedWindow("input-video",CV_WINDOW_AUTOSIZE);
namedWindow("MOG2",CV_WINDOW_AUTOSIZE);
Ptr<BackgroundSubtractor>pMOG2 = createBackgroundSubtractorMOG2();
while (capture.read(frame)) {
imshow("input-video",frame);
pMOG2->apply(frame, bsmaskMOG2);
imshow("MOG2",bsmaskMOG2);
char c = waitKey(100);
if (c == 27) {
break;
}
}
capture.release();
waitKey(0);
return 0;
}