Embedding an OpenCV window into a Qt GUI

后端 未结 3 1463
悲&欢浪女
悲&欢浪女 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.

    0 讨论(0)
  • 2021-02-06 04:03

    simply check out the opencv highgui implementation. as i recall it uses qt.

    0 讨论(0)
  • 2021-02-06 04:07

    My first guess is to want to say this: I'm sure that if you dig into the code for namedWindow, you will find that they use some sort of standard, albeit not oft-referenced, object for painting said window (that's in the openCV code). If you were ambitious enough, you could extend this class yourself, to interface directly to a frame or custom widget in Qt. There might even be a way to take the entire window and embed it, using a similar method of a Qt frame, or an extension of the (general) widget class. This is a very interesting question and relates rather directly to work I've been doing of late, so I'll continue to think about and research it and see if I can't come up with something else more helpful.

    [EDIT] What specific new controls are you so interested in? It might be more efficient on the part of the programmer to extend a Qt control to emulate that, as opposed to my first suggestion.[/EDIT]

    0 讨论(0)
提交回复
热议问题