How to Link Opencv in Qtcreator and Use Qt Library

How to link opencv in QtCreator and use Qt library

Finally I am starting to be happy. When adjusting this question I had to try all the ways how to define LIBS. Listing them manually helped, at first I wrote them somehow wrong.

This is how it works finally:

LIBS += -LC:\\Programs\\opencv24\\opencv_bin2\\bin \
libopencv_core240d \
libopencv_highgui240d \
libopencv_imgproc240d \
libopencv_features2d240d \
libopencv_calib3d240d \

How can I make OpenCV the default library for my qt projects?

1) You can create a .prf (project feature) file in your mkspecs/features directory:

/usr/share/qt5/mkspecs/features/opencv.prf

INCLUDEPATH += -I/usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_stitching -lopencv_superres ...and another libraries

Now simply add CONFIG += opencv to your .pro file to have it working. Or you can even auto-enable this feature by editing mkspecs/qconfig.pri:

/usr/share/qt5/mkspecs/qconfig.pri

...
CONFIG += ... opencv
...

BTW. qconfig.pri is a part of qt_config, which is loaded by all QMake's machine-dependent specs, so it should always work. However, it's also possible to patch only a specific spec (for example, /usr/share/qt5/mkspecs/linux-g++/qmake.conf, or whatever is appropriate for your configuration). Of course, it's even possible to add all these INCLUDEPATH+=... and LIBS+=... straight into that qmake.conf and get rid of the .prf file completely.

2) Alternatively, if you don't want to pollute Qt installation, you can use manual include:

opencv.pri

INCLUDEPATH += -I/usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_stitching -lopencv_superres ...and another libraries

myprogram.pro

include(path/to/opencv.pri)
...

How to add opencv DLL on Windows to QTCreator project?

Here is a solution (which doesn't match top google search tutorial):

INCLUDEPATH += C:/opencv-3.4.1/build/install/include
LIBS += C:\opencv-3.4.1\build\LIB\Debug\opencv_core341d.lib
LIBS += C:\opencv-3.4.1\build\LIB\Debug\opencv_highgui341d.lib
LIBS += C:\opencv-3.4.1\build\LIB\Debug\opencv_imgcodecs341d.lib
LIBS += C:\opencv-3.4.1\build\LIB\Debug\opencv_imgproc341d.lib
LIBS += C:\opencv-3.4.1\build\LIB\Debug\opencv_features2d341d.lib
LIBS += -L"C:/opencv-3.4.1/build/bin/Debug"

and don't forget to run Build->Run qmake.

Qt creator does not detect opencv

In the .pro file, add the following lines:

INCLUDEPATH += C:\opencv\opencv3.1.0\opencv\build\include
LIBS += -LC:\opencv\opencv3.1.0\opencv\build\x64\vc14\lib \
opencv310.lib \

And also you need to add the .dll file's path C:\opencv\opencv3.1.0\opencv\build\x64\vc14\bin to the system path (this time you need to restart the Qt IDE)



Related Topics



Leave a reply



Submit