使用opencv进行视频的前景检测,也可作为运动检测
代码:
#include "stdafx.h"
#include "opencv2/core.hpp"
#include <opencv2/core/utility.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/video/background_segm.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <stdio.h>
using namespace std;
using namespace cv;
//this is a sample for foreground detection functions
int main(int argc, const char** argv)
{
bool smoothMask = true;
string method = "knn";
VideoCapture cap;
bool update_bg_model = true;
//读取视频
cap.open("D:\\1.avi");
if (!cap.isOpened())
{
printf("can not open camera or video file\n");
return -1;
}
namedWindow("image", WINDOW_NORMAL);
namedWindow("foreground mask", WINDOW_NORMAL);
namedWindow("foreground image", WINDOW_NORMAL);
namedWindow("mean ba