Skip to content

Instantly share code, notes, and snippets.

@embed
Created August 4, 2009 12:54
Show Gist options
  • Save embed/161193 to your computer and use it in GitHub Desktop.
Save embed/161193 to your computer and use it in GitHub Desktop.
/**
* Display video from webcam
*
* Author Nash
* License GPL
* Website http://nashruddin.com
*/
#include <stdio.h>
#include <stdlib.h>
#include "cv.h"
#include "highgui.h"
int main( int argc, char **argv )
{
CvCapture *capture = 0;
IplImage *frame = 0;
int key = 0;
int i=0;
/* initialize camera */
capture = cvCaptureFromCAM( -1 );
/* always check */
if ( !capture ) {
fprintf( stderr, "Cannot open initialize webcam!\n" );
return 1;
}
printf("%d\n",i++);
/* create a window for the video */
cvNamedWindow( "result", CV_WINDOW_AUTOSIZE );
while( key != 'q' ) {
printf("%d\n",i++);
/* get a frame */
frame = cvQueryFrame( capture );
/* always check */
if( !frame ) break;
/* display current frame */
cvShowImage( "result", frame );
/* exit if user press 'q' */
key = cvWaitKey( 1 );
usleep();
}
/* free memory */
cvDestroyWindow( "result" );
cvReleaseCapture( &capture );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment