To Capture Video using a Webcam
//Standard Header
#include "stdafx.h"
//OpenCV header
#include "cv.h"
#include "highgui.h"
//Start of main function
int main( int argc, char** argv )
{
//Enable camera input
CvCapture* capture = cvCreateCameraCapture(0);
//Terminate Program if camera feed is not available
assert( capture != NULL );
//Create Window named Output
cvNamedWindow( "Output", CV_WINDOW_AUTOSIZE );
//Frames pointer
IplImage* image;
//continuous loop to obtain frames from the cam and display at output window
while(1)
{
//Bring each frame to image variable
image = cvQueryFrame( capture );
//If no input then terminate
if( !image )
break;
cvShowImage( "Output", image );
//Delay to wait before returning to the loop to get next frame
char c = cvWaitKey(33);
//If escape ket pressed then terminate
if( c == 27 )
break;
}
//During program end release camera so it could be used by another application
cvReleaseCapture( &capture );
//Close the Output Window created earlier
cvDestroyWindow( "Output" );
}
Thursday, January 1, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment