Last active
November 20, 2016 07:20
-
-
Save sagi-z/c3186d1437c7fadd62c5bc8fc8b405fb 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
#include <opencv2/opencv.hpp> | |
#include <iostream> | |
using namespace cv; | |
using namespace cv::bgsubcnt; | |
using namespace std; | |
int main( int argc, char** argv ) | |
{ | |
VideoCapture cap; | |
cap.open(0); | |
if( !cap.isOpened() ) | |
{ | |
cout << "Could not initialize capturing...\n"; | |
return 0; | |
} | |
namedWindow("FG", 1); | |
Ptr<BackgroundSubtractor> pBgSub = createBackgroundSubtractorMOG2(); | |
for(;;) | |
{ | |
Mat frame; | |
cap >> frame; | |
if( frame.empty() ) | |
{ | |
break; | |
} | |
Mat gray; | |
cvtColor(frame, gray, COLOR_BGR2GRAY); | |
Mat fgMask; | |
pBgSub->apply(gray, fgMask); | |
Mat fg; | |
frame.copyTo(fg, fgMask); | |
imshow("FG", fg); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment