#include "core/core.hpp"
#include "highgui/highgui.hpp"
#include "imgproc/imgproc.hpp"
using namespace cv;
int main(void)
{
VideoCapture videoCap;
videoCap.open(0);
if (!videoCap.isOpened())
{
return -1;
}
Mat framePre; //上一帧
Mat frameNow; //当前帧
Mat frameDet; //运动物体
videoCap >> framePre;
cvtColor(framePre, framePre, CV_RGB2GRAY);
while (true)
{
videoCap >> frameNow;
cvtColor(frameNow, frameNow, CV_RGB2GRAY);
absdiff(frameNow, framePre, frameDet);
framePre = frameNow;
imshow("Video", frameNow);
imshow("Detection", frameDet);
if (cvWaitKey(27) == 27)
break;
}
videoCap.release();
return 0;
}
;