Skip to content

Instantly share code, notes, and snippets.

@nikhil9
Created November 15, 2012 19:24
Show Gist options
  • Save nikhil9/4080630 to your computer and use it in GitHub Desktop.
Save nikhil9/4080630 to your computer and use it in GitHub Desktop.
Camera Access using Opencv
#include <iostream>
#include <cv.h>
#include <highgui.h>
using namespace std;
char key;
int main()
{
cvNamedWindow("Camera_Output", 1); //Create window
CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY); //Capture using any camera connected to your system
while(1){ //Create infinte loop for live streaming
IplImage* frame = cvQueryFrame(capture); //Create image frames from capture
cvShowImage("Camera_Output", frame); //Show image frames on created window
key = cvWaitKey(10); //Capture Keyboard stroke
if (char(key) == 27){
break; //If you hit ESC key loop will break.
}
}
cvReleaseCapture(&capture); //Release capture.
cvDestroyWindow("Camera_Output"); //Destroy Window
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment