main.cpp
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>
using namespace cv;
using namespace std;
int main()
{
VideoCapture capture;
capture.open("3.avi");
if(!capture.isOpened())
{
cout << "could not find the video file ..." << endl;
return -1;
}
Mat frame;
Mat bsmaskMOG2;
Mat bsmaskKNN;
namedWindow("input video", CV_WINDOW_AUTOSIZE);
namedWindow("MOG2", CV_WINDOW_AUTOSIZE);
namedWindow("KNN", CV_WINDOW_AUTOSIZE);
Mat kernel = getStructuringElement(MORPH_RECT, Size(3, 3), Point(-1, -1));//形态学开操作
//init BS
Ptr<BackgroundSubtractor> pMOG2 = createBackgroundSubtractorMOG2();
Ptr<Backgr