// Example 2-2. A simple OpenCV program for playing a video file from disk
#include "highgui.h"
int main(int argc, char **argv)
{
cvNamedWindow("Example2",CV_WINDOW_AUTOSIZE);
// it will also allocate a memory for the image
CvCapture *capture = cvCreateFileCapture(argv[1]);
IplImage *frame;
while(1)
{
frame = cvQueryFrame( capture );
if( !frame )
break;
cvShowImage( "Example2", frame );
// 30 frames per second = 30 frames / 1000 ms = 1 frame / 33 ms
// if no stdin then it will return -1
char c = cvWaitKey(33);
if(c==27)
break;
// pause while pressing p or P
while((c=='p')||(c=='P'))
{
c = cvWaitKey(0);
if(c==27)
{
cvReleaseCapture( &capture );
cvDestroyWindow( "Example" );
return 0;
}
// continue the video while pressing c, C or enter
if((c=='c')||(c=='C')||(c==13))
break;
else
c='p';
}
}
// it will also called "cvReleaseImage()" for the "frame" pointer
cvReleaseCapture( &capture );
cvDestroyWindow( "Example2" );
return 0;
}
沒有留言:
張貼留言