OpenCV读取视频文件之前需要做是事情:
1.下载视频编码解码器
推荐XviD,下载链接:http://pan.baidu.com/s/1jGjE2ii 密码:xrni
2.用格式工厂将视频文件转成标准格式,如*.avi
/*----------------------------------------OpenCV视频读取代码---------------------------------------------*/
CString Filepath; CFileDialog dlg(TRUE); if(dlg.DoModal()==IDOK) { Filepath=dlg.GetPathName(); } char *path; path=Filepath.GetBuffer(Filepath.GetLength()); CvCapture *cap; IplImage *frame; const char ESC = 27; cvNamedWindow("Camera",CV_WINDOW_AUTOSIZE); if (cap = cvCreateFileCapture(path)) { while ((frame = cvQueryFrame(cap)) != 0 && cvWaitKey(20) != ESC) { frame = cvQueryFrame(cap); cvShowImage("Camera", frame); } cvReleaseCapture(&cap); /* cvReleaseImage(&frame); * 注意,这里不能释放,释放会出错 */ cvDestroyWindow("Camera"); }