Skip to content

Instantly share code, notes, and snippets.

@santosh
Created August 5, 2018 10:38
Show Gist options
  • Save santosh/7c52c59d61635d7fc667a1f23da101e6 to your computer and use it in GitHub Desktop.
Save santosh/7c52c59d61635d7fc667a1f23da101e6 to your computer and use it in GitHub Desktop.
Webcam feed in OpenCV. #ComputerVision
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(void) {
// capture a video, for webcam, pass 0 instead of file path..
VideoCapture cap(0);
if (!cap.isOpened()) {
cout << "Error opening video stream or file" << endl;
return -1;
}
while (1) {
Mat frame;
cap >> frame;
if (frame.empty()) {
break;
}
imshow("Frame", frame);
char c=(char)waitKey(25);
if (c==27) {
break;
}
}
cap.release();
destroyAllWindows();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment