Skip to content

Instantly share code, notes, and snippets.

@MareArts
Created April 22, 2019 15:25
Show Gist options
  • Save MareArts/f6df7013965e1857243b2c2ca342c54a to your computer and use it in GitHub Desktop.
Save MareArts/f6df7013965e1857243b2c2ca342c54a to your computer and use it in GitHub Desktop.
#include <opencv2/opencv.hpp>
#ifdef _DEBUG
#pragma comment(lib, "opencv_world401d.lib")
#else
#pragma comment(lib, "opencv_world401.lib")
#endif
using namespace cv;
using namespace std;
using namespace std;
using namespace cv;
int main(int, char)
{
Mat frame;
Mat old_frame;
//Mat absdiff_frame;
VideoCapture stream1(0);
if (!stream1.isOpened()) { //check if video device has been initialised
cout << "cannot open camera 1";
}
Mat PR_img;
Mat sub_frame;
Mat BG_img;
int frame_flow = 50;
int count_frame = 0;
while (1)
{
if (!(stream1.read(frame))) //get one frame form video
break;
//frame flow
if (BG_img.empty()) {
if (count_frame < frame_flow)
{
count_frame++;
printf("calibration %d\n", count_frame);
continue;
}
else {
BG_img = frame.clone();
cvtColor(BG_img, BG_img, COLOR_BGR2GRAY);
}
}
PR_img = frame.clone();
cvtColor(PR_img, PR_img, COLOR_BGR2GRAY);
//subtract(old_frame, frame, sub_frame);
absdiff(BG_img, PR_img, sub_frame);
threshold(sub_frame, sub_frame, 50, 255, THRESH_BINARY);
//
imshow("frame", frame);
imshow("sub_frame", sub_frame);
imshow("BG_frame", BG_img);
if (waitKey(5) >= 0)
break;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment