Click here to Skip to main content
14,736,706 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, 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 a terminal and compile my program with CMake. Here's my Ubuntu OpenCV version :
Ubuntu 18.04.4 LTS
OpenCV version : 4.2.0

In the book whenever they use imshow(), it shows a window with a toolbar and status bar on it, mine is not. And later on the next few chapters, they still use this toolbar for many purposes.

What I have tried:

After searching for a while, I found out that it is using Qt GUI. So, I went on to install Qt using these following codes :
sudo apt-get install qtcreator
sudo apt-get install qt5-default

I also followed installation docs from Qt Wiki. 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. Do I need to entirely uninstall OpenCV and compile it again with QT using CMake ?

UPDATE

Apparently there was no other way beside completely uninstall OpenCV and then compile & reinstalling it with QT. This is what I do :

1. Uninstall OpenCV (already reinstalled 3 times)
sudo apt-get purge '*opencv*'
sudo find / -name "*opencv*" -exec rm -rf {} \;

2. Cloning OpenCV and OpenCV contrib from Github, and during building with CMake in terminal, put 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_TBB=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 running several program). 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 on my createButton function it) even after I entirely reinstall, build and make OpenCV using WITH_QT=ON ? Does 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 :
//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);
Any advice ?

UPDATE [2]

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 Installation for Ubuntu)

Again, OpenCV was installed perfectly. Tested by running simple programs. But still encounter the same error for Qt. Advice ?
Posted
Updated 19-Mar-20 18:54pm
v7
Comments
Richard MacCutchan 8-Mar-20 9:47am
   
Where is the rest of the error message? It should give the function name and the source file and line number.
lock&_lock 8-Mar-20 9:53am
   
Updated !
Richard MacCutchan 8-Mar-20 10:03am
   
I have Googled that message but cannot find a definitive answer. It seems that you are not alone in this. You could try the openCV or QT websites to see if you can get a quicker answer there.
Richard MacCutchan 8-Mar-20 10:11am
   
I took a quick look at some of the source on github. It appears that the openCV source checks for a definition of the tag HAVE_QT and not WITH_QT. If it is not defined then you will get the error that you see.

See if you can find out where that tag is defined (if anywhere) either in the source, or the CMake file.
lock&_lock 8-Mar-20 17:20pm
   
Thanks again. Yes, I've tried OpenCV forum all the time. It's not the most responsive forum actually. And about WITH_QT, it's one of many flag options to build OpenCV with CMake. I'll check more if I need to define HAVE_QT somewhere. Thanks

1 solution

Took me almost 2 weeks tried to integrate QT and OpenGL. I changed my CMake settings back & forth so I'm not exactly sure if this will be the same case for everyone but this this what worked for me. Make sure you have Java installed and configured correctly in your environment.

I have Java installed (checked with running java & javac), but somehow CMake couldn't find it in configuration, so I figured I did clean uninstall Java and reinstall it. I'd like to start with clean env. so I purge everything beforehand (Java, QT, OpenCV, OpenGL) and fonfigure CMake again with QT and OpenGL, and it worked perfectly.

1. Clean uninstall OpenCV. Use uninstall if you configure OpenCV with CMake or simply do it with purge.
sudo apt-get purge '*opencv*'
sudo find / -name "*opencv*" -exec rm -rf {} \;

2. Download the latest OpenCV from official OpenCV website (now it's version 4.2.0).
3. Purge any QT and OpenGL and reinstall them again. Here's a very nice List of all Qt5 developement packages, available on Ubuntu, so you know what you need to install.
4. If you have Java installed, clean uninstall everything first. Here's a very nice post of how to do it, I'll put it here. (There will be many purge in this part, make sure you read and understand what you're removing) :

Remove all the Java related packages (Sun, Oracle, OpenJDK, IcedTea plugins, GIJ):
dpkg-query -W -f='${binary:Package}\n' | grep -E -e '^(ia32-)?(sun|oracle)-java' -e '^openjdk-' -e '^icedtea' -e '^(default|gcj)-j(re|dk)' -e '^gcj-(.*)-j(re|dk)' -e '^java-common' | xargs sudo apt-get -y remove
sudo apt-get -y autoremove

Purge config files (careful. This command removed libsgutils2-2 and virtualbox config files):
dpkg -l | grep ^rc | awk '{print($2)}' | xargs sudo apt-get -y purge

Remove Java config and cache directory:
sudo bash -c 'ls -d /home/*/.java' | xargs sudo rm -rf

Remove manually installed JVMs:
sudo rm -rf /usr/lib/jvm/*

Remove Java entries, if there is still any, from the alternatives:
for g in ControlPanel java java_vm javaws jcontrol jexec keytool mozilla-javaplugin.so orbd pack200 policytool rmid rmiregistry servertool tnameserv unpack200 appletviewer apt extcheck HtmlConverter idlj jar jarsigner javac javadoc javah javap jconsole jdb jhat jinfo jmap jps jrunscript jsadebugd jstack jstat jstatd native2ascii rmic schemagen serialver wsgen wsimport xjc xulrunner-1.9-javaplugin.so; do sudo update-alternatives --remove-all $g; done

Search for possible remaining Java directories:
sudo updatedb
sudo locate -b '\pack200'

If the command above produces any output like /path/to/jre1.6.0_34/bin/pack200 remove the directory that is parent of bin, like this: sudo rm -rf /path/to/jre1.6.0_34.

5. Reinstall Java, I used one from Oracle (now it's version 14). Download the file and install with sudo dpkg -i.
6. Install Apache Ant from Ubuntu Software Center.
7. Create file in etc/profile.d.
sudo nano /etc/profile.d/(yourjdkversion).sh

and put this lines (check your jdk version correctly before put it here)
export JAVA_HOME="/usr/lib/jvm/jdk-14"
export PATH="$PATH:${JAVA_HOME}/bin"

Run this java -version and ant-version, if return correct values then they're configured properly and you're ready. Mine :
java -version                                                                    
java version "14" 2020-03-17
Java(TM) SE Runtime Environment (build 14+36-1461)
Java HotSpot(TM) 64-Bit Server VM (build 14+36-1461, mixed mode, sharing)

ant -version                                                                      
Apache Ant(TM) version 1.10.7 compiled on September 1 2019


8. Install cmake-gui. Open it, put OpenCV source and build directory.
9. Configure
10. Search for option WITH_QT, WITH_OPENGL, and BUILD_JAVA, then tick all of them. NO NEED TO CHANGE ANY PATH, CMake will find it if it's there. Configure again.

Here's my latest setting after the configuration for reference, notice that CMAKE found QT, OpenGL (in GUI) and JAVA (last lines) properly. Full configuration for reference is here (gist) . Java used to be in unavailable section, but CMake found it properly now. If your configuration's missing one of them, try to install what's missing. Mine :

OpenCV modules:
    To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc java ml objdetect photo python2 python3 stitching ts video videoio
    Disabled:                    world
    Disabled by dependency:      -
    Unavailable:                 js ( --> Java used to be here, "unavailable" even though it's installed.)
    Applications:                tests perf_tests examples apps
    Documentation:               NO
    Non-free algorithms:         YES

  GUI: 
    QT:                          YES (ver 5.9.5)
      QT OpenGL support:         YES (Qt5::OpenGL 5.9.5)
    GTK+:                        NO
    OpenGL support:              YES (/usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGLU.so)
    VTK support:                 YES (ver 6.3.0)


  Java:                          
    ant:                         /snap/bin/ant (ver 1.10.7)
    JNI:                         /usr/lib/jvm/jdk-14/include /usr/lib/jvm/jdk-14/include/linux /usr/lib/jvm/jdk-14/include
    Java wrappers:               YES
    Java tests:                  YES

  Install to:                    /usr/local


11. If you make any changes make sure to configure again.
12. Generate.
13. Navigate to your build directory and install OpenCV as usual.
make -j8 (check how many threads you can support, I use -j8)
make install

DONE. Run one or two OpenCV program with QT and OpenGL and see if it works.
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900