int main()
{
cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );
CvCapture* capture = cvCaptureFromAVI( "a.avi" );
IplImage* frame;
if(!capture)
{
printf("fail");
}
else
{
while(1)
{
frame = cvQueryFrame( capture );
cvShowImage( "Examp开发者_C百科le2", frame );
char c = cvWaitKey(40);
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "Example2" );
}
return 0;
}
the frame rate of the video i tried with open cv is 29 frames/s and frame width is 720 and height is 480 the format of the video is DX50 with avi wrapper
the blank window is showed named example2 which goes away...
the problem is cvcapturefromavi does return the pointer thats why fail is not printed
operating system window 7
I tried on my computer (with a webcam instead of a file using cvCaptureFromCAM(-1)) and your code worked perfectly, this is what you should try.
- The file "a.avi" is not in the path of your executable, maybe you should first use an absolute path to try something like "C:/MyVideos/a.avi"
- I would try using the cvCaptureFromFile() function instead of the cvCaptureFromAVI(), because I searched in the API documentation (OpenCV C 2.1) and couldn't find any cvCaptureFromAVI() function (maybe it exists but is deprecated or not documented).
PS : there is a little mistake in your code, why do you use cvDestroyWindow in the else {} scope, it should be in the main{} scope as you create the window in the main scope.
PPS : please indent your code better for readability
Julien,
I have the same problem. It is said the problem occurs because of the lack of necessary video codecs. It is reccommended to use "Mencoder" to encode the avi files to serve to use of OpenCV but it didnt solve my problem and I am still not able to play avi files with OpenCV 2.3.1.
I solved my problem by adding to my path opencv_ffmpeg.dll which was missing. Hope it works for yours and peoples who face this problem.
If you build opencv to static library, you will find there is still a dll file "opencv_ffmpegxxxxx.dll" in the bin directory. This dll is required even if you link your code with opencv statically. So make sure the system can find this dll file.
精彩评论