OpenCV need to do before reading a video file:
1. Download the video Codec
Recommended XviD, download link: http://pan.baidu.com/s/1jGjE2ii Password: xrni
2. Use the format factory to convert the video file to a standard format, such as *.avi
/*----------------------------------------OPENCV Video Read code---------------------------------------------*/
CString Filepath; CFileDialog dlg (TRUE); if(DLG. DoModal () = =IDOK) {Filepath=dlg. GetPathName (); } Char*path; Path=Filepath.getbuffer (Filepath.getlength ()); Cvcapture*cap; Iplimage*frame; Const CharESC = -; Cvnamedwindow ("Camera", cv_window_autosize); if(Cap =cvcreatefilecapture (path)) { while(frame = cvqueryframe (CAP))! =0&&Cvwaitkey ( -) !=ESC) {Frame=cvqueryframe (CAP); Cvshowimage ("Camera", frame); } cvreleasecapture (&cap); /*cvreleaseimage (&frame); * Note that this cannot be released, the release will be wrong*/Cvdestroywindow ("Camera"); }
Ps:
"Explore OpenCV" OpenCV Read video files