Created
August 4, 2009 12:54
-
-
Save embed/161193 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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