将OpenCV窗口嵌入Qt GUI [英] Embedding an OpenCV window into a Qt GUI

查看:1248
本文介绍了将OpenCV窗口嵌入Qt GUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OpenCV最近升级了其显示窗口(在Qt中使用) . 它看起来非常好,但是我发现它不可能嵌入到现有的Qt GUI窗口中.唯一的可能性似乎是创建cvNamedWindowcv::namedWindow,但是它会创建一个自由浮动的独立窗口.

OpenCV recently upgraded its display window, when it is used in Qt. It looks very good, however I did not find any possibility for it to be embedded into an existing Qt GUI window. The only possibility seems to be the creation of a cvNamedWindow or cv::namedWindow, but it creates a free-floating independent window.

是否有可能在现有GUI的内部内部创建该OpenCV窗口?在OpenCV论坛上,我只能找到一个未回答的问题,与我的问题有些相似.

Is there any possibility to create that OpenCV window inside an existing GUI? All I could find on the OpenCV forums is an unanswered question, somewhat similar to my own.

有一个简单易懂的

There is a straight-forward possibility to show an OpenCV image in Qt, but it has two major problems:

  1. 它涉及逐像素复制图像,而且速度很慢.它具有每个像素的函数调用! (在我的测试应用程序中,如果我从图像中创建视频并将其显示在cvNamedWindow中,则即使同时播放多个视频,它也可以非常流畅地运行,但是如果我通过IplImage-> QImage-> QPixmap-> QLabel路线,即使是一个视频也有严重的延迟)​​
  2. 我不能将其与cvNamedWindow的那些不错的新控件一起使用.
  1. it involves copying the image pixel by pixel, and it's quite slow. It has function calls for every pixel! (in my test application, if I create a video out of the images, and display it in a cvNamedWindow, it runs very smoothly even for multiple videos the same time, but if I go through the IplImage --> QImage --> QPixmap --> QLabel route, it has severe lag even for one single video)
  2. I can't use those nice new controls of the cvNamedWindow with it.

推荐答案

首先,图像转换的效率没有您想象的那么低.优化编译可以内联至少在我的代码中每个像素的函数调用"(您所引用问题的答案之一).

First of all, the image conversion is not as inefficient as you think. The 'function calls' per pixel at least in my code (one of the answers to the question you referenced) are inlined by optimized compilation.

第二,highgui/imshow中的代码执行相同的操作.无论哪种方式,您都必须从矩阵获取ARGB图像.转换QImage-> QPixmap本质上就是将数据从主内存移动到GPU内存.这也是为什么您无法直接访问QPixmap数据而必须通过QImage的原因.

Second, the code in highgui/imshow does the same. You have to get from the matrix to an ARGB image either way. The conversion QImage -> QPixmap is essentially nothing else than moving the data from main memory to GPU memory. That's also the reason why you cannot access the QPixmap data directly and have to go through QImage.

第三,如果您使用QGLWidget绘制图像,它的速度要快几倍,并且我假设您在OpenCV构建中启用了QT_OPENGL.我使用QPainter在QGLWidget中绘制QPixmap,并且速度没有问题.这是示例代码:

Third, it is several times faster if you use a QGLWidget to draw the image, and I assume you have QT_OPENGL enabled in your OpenCV build. I use QPainter to draw the QPixmap within a QGLWidget, and speed is no issue. Here is example code:

http://sourceforge.net/p/gerbil/svn/19/tree/gerbil-gui/scaledview.h

http://sourceforge.net/p/gerbil/svn/19/tree/gerbil-gui/scaledview.cpp

现在是您的原始问题:您当前的选择是从OpenCV中获取代码,将其包含在其他命名空间中的项目中,并对其进行更改以适合您的需求.除此之外,您现在别无选择. OpenCV的highgui使用其自己的事件循环,与X服务器的连接等,因此您无法拦截.

Now to your original question: Your current option is to take the code from OpenCV, include into your project under a different namespace, and alter it to fit your needs. Apart from that you have no alternative right now. OpenCV's highgui uses its own event loop, connection to the X server etc. and it is nothing you can intercept.

这篇关于将OpenCV窗口嵌入Qt GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆