opencv 動画

AVIファイルは読み込みに成功。画面の大きさを変更することも可能。

#include <cv.h>
#include <highgui.h>
#include <cstdio>

char* filename = "bunny.avi";
//char* filename = "humans.mpg";//mpg is not accept...


int main( int argc, char **argv)
{

IplImage* imgA;
CvCapture* cap;


cap = cvCaptureFromFile(filename);
if(cap == NULL)
{
printf("[%s] : Can't load .\n",filename);
exit(0);
}

imgA = cvQueryFrame(cap);
if(imgA == NULL)
{
printf("Can't Get frame.\n");
exit(0);
}


//cvNamedWindow("window",CV_WINDOW_AUTOSIZE);//fixed size
cvNamedWindow("window",0);//variable size

char key;
for( int frame = 1; imgA ; imgA = cvQueryFrame(cap), frame++ )
{
cvShowImage("window",imgA);
key=(char)cvWaitKey(41);
if(key=='\033')
{
exit(0);
}
}


cvWaitKey(0);

cvReleaseCapture(& cap);
cvDestroyWindow("window");

return 0;
}