1 | initial version |
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat prev;
VideoCapture cap(0); // 1st cam
while( cap.isOpened() )
{
Mat frame,gray,diff;
if ( ! cap.read(frame) )
break;
imshow("lalala",frame);
cvtColor( frame, gray, CV_BGR2GRAY );
if ( ! prev.empty() )
{
absDiff( gray, prev, diff );
imshow("diff",diff);
}
prev = gray; // swap
int k = waitKey(10);
if ( k==27 )
break;
}
return 0;
}
2 | No.2 Revision |
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat prev;
VideoCapture cap(0); // 1st cam
while( cap.isOpened() )
{
Mat frame,gray,diff;
if ( ! cap.read(frame) )
break;
imshow("lalala",frame);
cvtColor( frame, gray, CV_BGR2GRAY );
if ( ! prev.empty() )
{
absDiff( absdiff( gray, prev, diff );
imshow("diff",diff);
}
prev = gray; // swap
int k = waitKey(10);
if ( k==27 )
break;
}
return 0;
}