Professional Documents
Culture Documents
p. u tin ta khai bo 1 bin capture thuc Struct CvCapture, sau gn cho n ly d liu t webcam. ?
1 2 3
1 2 3
Nu nhn 1 phm bt k, th thot khi vng lp, release capture, release image, v kt thc ?
1 2
if(cvWaitKey( 1 )) break;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <stdio.h> #include "cv.h" #include "highgui.h" int main( int argc, char **argv ) { CvCapture *capture = 0; IplImage *frame = 0; int key = 0; // initialize camera capture = cvCaptureFromCAM( 0 ); // always check if ( !capture ) { fprintf( stderr, "Cannot open initialize webcam!\n" ); return 1; } // create a window for the video cvNamedWindow( "result", CV_WINDOW_AUTOSIZE ); while( 1 ) {
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
// 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 ); if(key !=-1) break; } // free memory cvDestroyWindow( "result" ); cvReleaseCapture( &capture ); return 0;