Embedding an OpenCV window into a Qt GUI

后端 未结 3 1587
悲&欢浪女
悲&欢浪女 2021-02-06 03:46

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 wind

3条回答
  •  南笙
    南笙 (楼主)
    2021-02-06 03:50

    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.

    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.

    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

    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.

提交回复
热议问题