使用工具:vs2010+opencv2.4.3
读视频、将视频前后帧图像像素值相减、将差值图像转化为灰度图并二值化(阈值为25)、之后进行中值滤波、将帧号写入滤波后的图像并把每帧保存、播放处理后的视频帧以及原始视频帧、在当前文件夹下生成处理后的视频文件。
#include "stdafx.h"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <iostream>
#include<strstream>
#include<string.h>
#include<fstream>
#define threshold_diff 25 //设置简单帧差法阈值
using namespace cv;
using namespace std;
int main(int argc,unsigned char* argv[])
{
Mat img_dst,gray[2000],gray_diff,frame[2000],frame1,rst;
bool pause=false;
//在这里修改相应的输入视频名
//CvCapture *capture=cvCaptureFromAVI("D:/chenxu/test.avi");
VideoCapture capture("D:/chenxu/test.avi");
//检查视频是否正常打开,如果正常打开isOpened()返回ture;
if(!capture.isOpened())
cout<<"fail to open!"<<endl;
//获取整个视频的帧数
long totalFrameNum