使用opencv显示视频

发布于 2024-12-08 00:36:25 字数 791 浏览 0 评论 0原文

根据“使用 opencv 显示视频”,我遇到了一个小问题。该代码是用 Visual Studio 2008 用 C++ 编写的。

代码如下:

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" );
}

调试时,程序启动,我可以看到命令窗口和一个灰色窗口(我想应该在其中显示视频)几毫秒。然后两个窗口都关闭。

视觉调试窗口的输出显示以下内容:

.. 。 (大量加载和卸载的dll) 。 。 。

程序“[3684] 2aufg4).exe: Native”已退出,代码为 0 (0x0)。

我不知道我做错了什么...

我非常感谢你的帮助!

一如既往地谢谢你们

i have a little problem according "displaying a video with opencv". The code is written in c++ with visual studio 2008.

here is the code:

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.

the output from debug window in visual shows the following:

..
. (a lot of loaded and unloaded dlls)
.
.
.

The program '[3684] 2aufg4).exe: Native' has exited with code 0 (0x0).

i dont know what i am doing wrong...

i would appreciate your help a lot!

as allways thank you guys

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北凤男飞 2024-12-15 00:36:25

您需要检查cvCreateFileCapture()的返回并确保它成功加载文件:

#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");
}

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");
}
緦唸λ蓇 2024-12-15 00:36:25

试试这个

int main( int argc, char** argv ) 
{
    cvNamedWindow( "xample2", CV_WINDOW_AUTOSIZE );
    CvCapture* capture = cvCreateFileCapture( "Micro-dance_2_.avi" );
    IplImage* frame;
    if(!cvQueryFrame( capture )){
        std::cout << "Could not open file\n";
        return -1; 
    }
    while(1) {
        frame = cvQueryFrame( capture );
        if( !frame ) break;
        cvShowImage( "xample2", frame );
        char c = cvWaitKey(33);
        if( c == 27 ) break;
    }
    cvReleaseCapture( &capture );
    cvDestroyWindow( "xample2" );
}

Try this

int main( int argc, char** argv ) 
{
    cvNamedWindow( "xample2", CV_WINDOW_AUTOSIZE );
    CvCapture* capture = cvCreateFileCapture( "Micro-dance_2_.avi" );
    IplImage* frame;
    if(!cvQueryFrame( capture )){
        std::cout << "Could not open file\n";
        return -1; 
    }
    while(1) {
        frame = cvQueryFrame( capture );
        if( !frame ) break;
        cvShowImage( "xample2", frame );
        char c = cvWaitKey(33);
        if( c == 27 ) break;
    }
    cvReleaseCapture( &capture );
    cvDestroyWindow( "xample2" );
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文