10

I am using Qt & OpenCV on a new project am about to compile OpenCV to work with MinGW.

A thought has arose that I can compile the OpenCV libs with Qt support but I don't really understand why I would want to do that. If I don't compile the libs with Qt support I can still route cv::mat to a QImage using a method like this.

So what am I missing? What value is provided in compiling Qt with OpenCV?

I have searched online and pages like this, this & this (from searching "why compile OpenCV with Qt") only show me how to compile with Qt and not why.

Community
  • 1
  • 1
GPPK
  • 6,546
  • 4
  • 32
  • 57

2 Answers2

6

LE: misunderstood the question

WITH_QT option is used by highgui module to create windows using qt, so the QImage to cv::Mat conversion and vice-versa will work no matter how WITH_QT option is set.

First some clarifications: you are not compiling OpenCV with Qt, Qt is not a compiler so you can't compile anything with it. Qt is a C++ library (it's called a framework because it imposes some design some rules to your application source code, but basically it's a C++ library, just like OpenCV).

Now, in C++ world* to use some libraries together you need to build those libraries with the same compiler (and in some cases even the same compiler settings), so must decide which C++ compiler you want to use and get both Qt and OpenCV built with the same compiler not necessarily build by you, binaries can be obtained from their websites.

If you want to use MinGW you will need to build OpenCV with MinGW compiler, because OpenCV (at least, version 2410) comes build only with Visual C++ version 10, 11, 12 - that means Visual Studio 2010, 2012 and 2013.

So if you decide to use some Visual Studio version, depending on version you choose, you might be able to use Qt with OpenCV without having to build neither yourself, but if you want MinGW compiler you need to build OpenCV with MinGW.

*you can get away with it if your libraries only export a C interface, but that is not the case with neither Qt nor latest OpenCV versions. //if you want more details about this use your favorite internet search engine to search for: c++ binary compatibility and or c++ abi

Zlatomir
  • 6,964
  • 3
  • 26
  • 32
  • I understand all your points, and whilst valid I don't think you answered the question. They are two separate libraries, which can be used together without ticking the qt box in the cmake window when compiling the OpenCV library for MinGW. (I've already compiled Qt with MinGW). So what is it actually doing when I tick that box and say I want to compile OpenCV for MinGW with Qt (WITH_QT tickbox) – GPPK Dec 14 '15 at 20:59
  • 2
    My bad, i didn't understand the question. – Zlatomir Dec 14 '15 at 21:05
  • WITH_QT option is used by highgui module to create windows using qt, so the QImage to cv::Mat conversion and vice-versa will work no matter how WITH_QT option is set. – Zlatomir Dec 14 '15 at 21:06
  • And why, or in what way, are windows created with Qt better/preferable to ones not created with Qt? – Mark Setchell Dec 14 '15 at 21:08
  • 2
    I don't know exactly, maybe in an kde environment you don't want gtk (i'm not sure if that is used by default) or other framework to create highgui windows. But this doesn't matter in your case since you are creating your UI with Qt and not gonna use highgui module – Zlatomir Dec 14 '15 at 21:13
  • Ahhh now we are getting to the crux of it, your last comment makes a lot more sense. Thinking from a non-windows point of view it's good to standardize your UI work and use Qt... Interesting. – GPPK Dec 14 '15 at 21:21
  • 2
    @MarkSetchell It's to enable you to control what widget toolkit to use behind the scenes (GTK, Qt, Cocoa, MFC, etc.). It's also to not depend too much on a single library from a highgui developer pespective when implementing the highgui API. – moooeeeep Dec 14 '15 at 21:23
  • 2
    I had a look here... http://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html#imshow and Qt allows you to set `CV_GUI_EXPANDED` which enables some extra features in `imshow()`. – Mark Setchell Dec 14 '15 at 22:05
5

You'd like to compile OpenCV with Qt for at least two reasons:

  • it gives you the zoom (mouse wheel) in imshow
  • it gives you the pixel RGB value when hovering over this pixel

Without WITH_QT, you just have a bare window, with none of these features (and you'll miss extra buttons too, like Save the picture), which make the image processing debugging more tedious.

PJ127
  • 986
  • 13
  • 23