Input from Camera

To input a live stream from a camera we have to call cvCreateCameraCapture(). The argument which is passed in this function is a camera ID number as its argument.
 
Of course, this is important only when multiple cameras are available. The default value is –1, which means “just pick one”; naturally, this works quite well when there is only one camera to pick.
 
The cvCreateCameraCapture() function returns the same CvCapture* pointer, which we can hereaft er use exactly as we did with the frames grabbed from a video stream.

Example

#include "cv.h"
#include "highgui.h"

int main(int argc, char** argv) 
{
	cvNamedWindow("cameraDisplay", CV_WINDOW_AUTOSIZE);
	CvCapture * capture;
	capture = cvCreateCameraCapture(0);

	IplImage* frame;
	while (1) 
	{
		frame = cvQueryFrame(capture);
		if (!frame)
			break;
		cvShowImage("cameraDisplay", frame);
		char c = cvWaitKey(10);
		if (c == 27)
			break;
	}
	cvReleaseCapture(&capture);
	cvDestroyWindow("cameraDisplay");
}