Skip to content

Instantly share code, notes, and snippets.

@TheB1ackSheep
Last active August 29, 2015 13:58
Show Gist options
  • Save TheB1ackSheep/9958652 to your computer and use it in GitHub Desktop.
Save TheB1ackSheep/9958652 to your computer and use it in GitHub Desktop.
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdio.h>
#include <iostream>
using namespace cv;
using namespace std;
int main(void){
VideoCapture cap(0);
if (!cap.isOpened())
{
cout << "Cannot capture your webcam" << endl;
return -1;
}
namedWindow("Webcam", CV_WINDOW_AUTOSIZE);
while (1)
{
Mat frame;
bool bSuccess = cap.read(frame);
if (!bSuccess){
cout << "Cannot read the frame from your cam" << endl;
break;
}
imshow("Webcam", frame);
if (waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
break;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment