Greetings ! It’s my first post in this forum.
I’ve been following an OpenCV tutorial from a book. Prior to it, I have OpenCV already installed on my machine. I’m working with OpenCV & C++ on terminal Ubuntu and compile my program with CMake. Here’s my Ubuntu OpenCV version :
Ubuntu 18.04.4 LTS
OpenCV version : 4.2.0
I have been getting trouble for days building OpenCV and integrating it with Qt using CMake. You might find my question elsewhere, because I’ve asked this question in OpenCV forum before, even in Stackoverflow, and CodeProject, all with no luck so far. (Can’t link them since I have limitation of how many links I can put here). CMake forum is my last hope, I’d really appreciate some input/advice.
From the book tutorial I followed, the result in the book is different than mine, apparently they’re using QT. And later on the next few chapters, they still use Qt. So, I went on to install Qt using these following codes :
sudo apt-get install qtcreator
sudo apt-get install qt5-default
When I checked my Qt version, this is what I got :
$ qmake --version
QMake version 3.1
Using Qt version 5.9.5 in /usr/lib/x86_64-linux-gnu
So, now I have Qt installed in my machine, but how do I integrate this with my OpenCV so I can use it on my programs other than putting highgui lib ? I encountered this error :
The library is compiled without QT support in function
I’ve been looking around online but still don’t know how to integrate it properly.
WHAT I’VE TRIED
Apparently there was no other way beside completely uninstall OpenCV and then compile & reinstalling it with QT on. This is what I do :
-
Uninstall OpenCV entirely, and reinstalled it again (did it 3x times already) by cloning OpenCV and OpenCV contrib from Github, and during building OpenCV with CMake in terminal, I’ve added WITH_QT = ON . here’s the full set up that I used :
cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_C_EXAMPLES=ON \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D OPENCV_GENERATE_PKGCONFIG=ON \ -D WITH_V4L=ON \ -D WITH_QT=ON \ -D WITH_OPENGL=ON \ -D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \ -D BUILD_EXAMPLES=ON ..
No issue and I got OpenCV installed correctly (tested with several programs). And here’s the version :
$ pkg-config --modversion opencv
4.2.0
I also came across this question : OpenCV integration With Qt, but still no solution there. But why does I still get error on any project with QT on it (I have QT_RADIOBOX and other on createButton
) even after I entirely reinstall, build and make OpenCV with WITH_QT=ON ? The library is compiled without QT support, did CMake failed to locate QT ?
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.2.0-dev) /home/raisa/opencv_build/opencv/modules/highgui/src/window.cpp:597:
error: (-213:The function/feature is not implemented)
The library is compiled without QT support in function 'createButton'
[2] 10467 abort (core dumped) ./exerc13
Here’s createButton function :
//Create buttons
createButton("Blur", blurCallback, NULL, QT_CHECKBOX, 0);
createButton("Grey", greyCallback, NULL, QT_RADIOBOX, 0);
createButton("RGB", bgrCallback, NULL, QT_RADIOBOX, 1);
createButton("Sobel", sobelCallback, NULL, QT_PUSH_BUTTON, 0);
-
I read about explicit path definition for Qt integration instead of just putting " WITH_QT=ON ". So I decided to go with cmake-gui and defined each path for Qt path configuration. Like this :
WITH_QT=ON (checked in cmake-gui) Qt5Concurrent_DIR = /home/raisa/Qt5.9.9/5.9.9/gcc_64/lib/cmake/Qt5Concurrent Qt5Core_DIR = /home/raisa/Qt5.9.9/5.9.9/gcc_64/lib/cmake/Qt5Core Qt5Gui_DIR = /home/raisa/Qt5.9.9/5.9.9/gcc_64/lib/cmake/Qt5Gui Qt5OpenGL_DIR = /home/raisa/Qt5.9.9/5.9.9/gcc_64/lib/cmake/Qt5OpenGL Qt5Test_DIR = /home/raisa/Qt5.9.9/5.9.9/gcc_64/lib/cmake/Qt5Test Qt5Widgets_DIR = /home/raisa/Qt5.9.9/5.9.9/gcc_64/lib/cmake/Qt5Widgets Qt5_DIR = /home/raisa/Qt5.9.9/5.9.9/gcc_64/lib/cmake/Qt5
(Qt installation folowing installation docs from Qt Wiki)
Again, OpenCV was build & installed perfectly with CMake. Tested by running simple programs. But still encounter the same error for Qt. Any advice ? Thank you.