Last active
April 22, 2019 15:04
-
-
Save MareArts/9d189d6a9996bffb62dcc3ecac1c21b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://study.marearts.com/2019/04/opencv-simple-background-subtraction.html | |
//https://youtu.be/s32FB0OxnuI | |
#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); | |
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
http://study.marearts.com/2019/04/opencv-simple-background-subtraction.html
https://youtu.be/s32FB0OxnuI