OpenCV cvNamedWindow 未出现在 Fedora 下

发布于 2024-08-14 23:03:59 字数 437 浏览 8 评论 0原文

正如标题所示,我只是想打开一个命名窗口。我使用 OpenCV 已经一年多了,以前从未遇到过这个问题。由于某种原因,窗口永远不会打开。我尝试运行一些旧脚本,一切正常。

作为一个非常精简的示例,请参见下面,

#include "cv.h"
#include "highgui.h"

int main(int argc, char** argv) {

    cvNamedWindow( "video", 0 );
    IplImage *im = cvCreateImage( cvSize(200,200), 8, 3 );
    while(1) {
        cvShowImage( "video", im );
    }

    return 0;
}

我看不出为什么这不起作用,但由于某种原因,窗口永远不会出现。 还有其他人经历过吗?它让我头疼!

As the title suggests I'm simply trying to get a named window to come up. I've been working with OpenCV for over a year now, and never had this problem before. For some reason, the window never opens. I've tried running some of my old scripts and everything works fine.

As a very cut down example, see below

#include "cv.h"
#include "highgui.h"

int main(int argc, char** argv) {

    cvNamedWindow( "video", 0 );
    IplImage *im = cvCreateImage( cvSize(200,200), 8, 3 );
    while(1) {
        cvShowImage( "video", im );
    }

    return 0;
}

I can see no reason why that wouldn't work, but for some reason the window never appears.
Has anyone else experienced this? It's doing my head in!

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

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

发布评论

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

评论(1

痴意少年 2024-08-21 23:03:59

只需在循环中调用 cvWaitKey(int milliseconds) 即可。该函数通知GUI系统运行图形待处理事件。
你的代码应该是这样的:

int main(int argc, char** argv) {
   cvNamedWindow( "video", 0 );
   IplImage *im = cvCreateImage( cvSize(200,200), 8, 3 );
   while(1) {
       cvShowImage( "video", im );
       cvWaitKey(100); //wait for 100 ms for user to hit some key in the window
   }

   return 0;
}

Simply call cvWaitKey(int milliseconds) within the loop. This function notifies the GUI system to run graphics pending events.
Your code should be something like:

int main(int argc, char** argv) {
   cvNamedWindow( "video", 0 );
   IplImage *im = cvCreateImage( cvSize(200,200), 8, 3 );
   while(1) {
       cvShowImage( "video", im );
       cvWaitKey(100); //wait for 100 ms for user to hit some key in the window
   }

   return 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文