从文件或摄像机读

View Code
 1 int main( int argc, char** argv ) {
 2     cvNamedWindow( "Example2_9", CV_WINDOW_AUTOSIZE );
 3     CvCapture* capture;
 4     if (argc==1) {
 5         capture = cvCreateCameraCapture( 0 );
 6     } else {
 7         capture = cvCreateFileCapture( argv[1] );
 8     }
 9     assert( capture != NULL );
10 
11     IplImage* frame;
12     while(1) {
13         frame = cvQueryFrame( capture );
14         if( !frame ) break;
15         cvShowImage( "Example2_9", frame );
16         char c = cvWaitKey(10);
17         if( c == 27 ) break;
18     }
19     cvReleaseCapture( &capture );
20     cvDestroyWindow( "Example2_9" );
21 }

 

posted on 2013-04-28 11:37  wf110  阅读(154)  评论(0编辑  收藏  举报