Problems setting up OpenCV in Qt
I'm using OpenCV since a few days within the scope of an internship. To get some extra exercise I wanted to set it up on my private laptop (Win10 x64). Therefore I installed 5.7 and downloaded OpenCV 2.4.13. From the command line, I executed the command "setx -m OPENCV_DIR C:\opencv\build\x64\vc11". This is how my *.pro file looks like:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = TEST
TEMPLATE = app
INCLUDEPATH += C:/opencv/build/include
LIBS += C:/opencv/build/x64/vc11/bin/opencv_core2413d.dll
LIBS += C:/opencv/build/x64/vc11/bin/opencv_highgui2413d.dll
LIBS += C:/opencv/build/x64/vc11/bin/opencv_imgproc2413d.dll
LIBS += C:/opencv/build/x64/vc11/lib
SOURCES += main.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
I tried to run a really basic example with cv::imread and cv::imshow but if I build the project it tells me:
"file not recognized: File format not recognized opencv_core2413d.dll".
I also tried some other configurations from other forums but the problem stays the same...
I never had to set up libraries or similar before so that my knowledge is really bad. Please tell me if I missed some important information.
Thanks for your help in advance!
You do not link to the dll but to the .lib on windows
LIBS += C:/opencv/build/x64/vc11/bin/opencv_core2413d.dll LIBS += C:/opencv/build/x64/vc11/bin/opencv_highgui2413d.dll LIBS += C:/opencv/build/x64/vc11/bin/opencv_imgproc2413d.dll LIBS += C:/opencv/build/x64/vc11/lib
LIBS += -LC:/opencv/build/x64/vc11/lib -lopencv_core2413d -lopencv_highgui2413d -lopencv_imgproc2413d
or, using your environmental variable:
LIBS += -L$(OPENCV_DIR)/lib -lopencv_core2413d -lopencv_highgui2413d -lopencv_imgproc2413d
Are you using the same compiler that you used to build the openCV library? Which compiler? From the dll file names, it looks like you are using a debug build of openCV; does that match the build type of your test program (debug/release)?
Ok I replaced the LIBS section, now this occurs:
(I hope the screenshot is attached)
For Qt, I use MinGW GCC. It was already included when downloading the Qt package.
How do I build the openCV library? I just followed some instructions from the net. But I think it still fails because of my missing knowledge.
Hi and welcome to devnet,
From the looks of it, you are trying to link a Visual Studio built OpenCV against a MinGW built Qt. There at least two problems here:
- From the path of your OpenCV build, it's a 64bit version and the MinGW Qt package is 32bit
- You are trying to link libraries built with two different compilers. You can't mix and match like that. The compilers are not compatible one with the other and that's not limited to Visual Studio VS MinGW, it's also the case between different version of Visual Studio.
One thing you can do is build OpenCV with the MinGW version provided with Qt.