Problems setting up OpenCV in Qt



  • Hi,

    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
    mainwindow.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

    replace

    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
    

    with

    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:

    0_1474657029718_upload-22d8238a-3582-4da6-bbce-8cc9a1657961

    (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.


  • Lifetime Qt Champion

    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:

    1. From the path of your OpenCV build, it's a 64bit version and the MinGW Qt package is 32bit
    2. 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.