使用opencv显示视频 [英] Displaying a video using opencv
问题描述
根据使用opencv显示视频",我有一个小问题.该代码是使用Visual Studio 2008的c ++编写的.
i have a little problem according "displaying a video with opencv". The code is written in c++ with visual studio 2008.
下面是代码:
int main( int argc, char** argv )
{
cvNamedWindow( "xample2", CV_WINDOW_AUTOSIZE );
CvCapture* capture = cvCreateFileCapture( "Micro-dance_2_.avi" );
IplImage* frame;
while(1) {
frame = cvQueryFrame( capture );
if( !frame ) break;
cvShowImage( "xample2", frame );
char c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "xample2" );
}
在调试时,程序将启动,并且我可以看到命令窗口和灰色窗口(我认为应该在此处显示视频)持续了几毫秒.然后两个窗口都关闭.
when debugging, the programm launches and i can see the command window and a grey window (wher the video should be displayed i suppose) for a few milliseconds. Then both windows close.
Visual调试窗口中的输出显示以下内容:
the output from debug window in visual shows the following:
.. . (很多已加载和已卸载的dll) . .
.. . (a lot of loaded and unloaded dlls) . . .
程序"[3684] 2aufg4).exe:本机"已退出,代码为0(0x0).
The program '[3684] 2aufg4).exe: Native' has exited with code 0 (0x0).
我不知道我在做什么错...
i dont know what i am doing wrong...
非常感谢您的帮助!
一直谢谢你们
推荐答案
您需要检查cvCreateFileCapture()
的返回值,并确保它成功加载了文件:
You need to check the return of cvCreateFileCapture()
and make sure it loaded the file successfully:
#include <cv.h>
#include <highgui.h>
int main(int argc, char** argv)
{
cvNamedWindow("xample2", CV_WINDOW_AUTOSIZE);
CvCapture* capture = cvCreateFileCapture( "Micro-dance_2_.avi" );
if (!capture)
{
std::cout << "!!! cvCreateFileCapture didn't found the file !!!\n";
return -1;
}
IplImage* frame;
while (1)
{
frame = cvQueryFrame(capture);
if(!frame)
break;
cvShowImage("xample2", frame);
char c = cvWaitKey(33);
if (c == 27)
break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("xample2");
}
这篇关于使用opencv显示视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!