Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. How to use OpenCV inside QtCreator?
Forum Updated to NodeBB v4.3 + New Features

How to use OpenCV inside QtCreator?

Scheduled Pinned Locked Moved Solved Installation and Deployment
11 Posts 3 Posters 7.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Beriol
    wrote on last edited by Beriol
    #1

    Hi guys.

    I've been trying to make the OpenCV library to work with QtCreator the last couple of days, but I can't make it work.

    I've looked at a bunch of guides around the web, and tried each of them several times, but still nothing. Some guides use older versions of OpenCV, so I tried and use those versions, but it didn't work.

    All guides pretty much follow the steps reported here: https://zahidhasan.wordpress.com/2014/08/19/qt-5-3-1-64-bit-mingw-windows/

    The steps are basically to use CMake to build the OpenCV library (adding the option WITH_QT while doing it), install it, and then link the library to the QtProject.

    Although the part with CMake works a little different for me, meaning that it gives me some errors saying that it can't find some folders related to Qt (even though it points exactly where the directories are... which is odd), it still works and I manage to build the library and get the dll files.

    But when I try creating a simple project in QtCreator, nothing seems to work.

    As of right now, I'm using QtCreator 3.0.1 based on Qt 5.2.1 and OpenCV 2.4.9.

    Basically the code is simply this:

    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    int main() {
            cv::namedWindow("My Image");
            return 1;
    }
    

    So nothing really, it just uses a random OpenCV function.

    The .pro file is like this:

    QT       += core
    QT       -= gui
    TARGET = OpenCV
    CONFIG   += console
    CONFIG   -= app_bundle
    TEMPLATE = app
    SOURCES += main.cpp
    
    INCLUDEPATH += D:\Development\opencv-mingw\install\include
    
    
    LIBS += D:\Development\opencv-mingw\install\x64\mingw\bin\libopencv_core249.dll \
        D:\Development\opencv-mingw\install\x64\mingw\bin\libopencv_highgui249.dll \
        D:\Development\opencv-mingw\install\x64\mingw\bin\libopencv_imgproc249.dll \
        D:\Development\opencv-mingw\install\x64\mingw\bin\libopencv_features2d249.dll \
        D:\Development\opencv-mingw\install\x64\mingw\bin\libopencv_calib3d249.dll
    

    The paths are alright, the code compiles. But it crashes at startup without giving any errors. If I try using the debugger, it does the same but it also gives me an error:
    "An exception was triggered:
    Exception at 0x77018f05, code: 0xc000007b; flags=0x0.
    During startup program exited with code 0xc000007b."

    So probably the problem is that it can't find the dlls. But I checked and re-checked, they ARE there, and I added the paths to the system PATH variable, as you can see in this screenshot: http://imgur.com/aYrVkei

    So, I'm out of ideas. Can you guys help me linking the libraries? Or maybe there is another problem?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Aren't you providing the path to a 64bit version of OpenCV while using a 32bit Qt ?

      On a side note, you shouldn't link to .dll files but to .lib files.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      B 1 Reply Last reply
      0
      • B Offline
        B Offline
        beginMyCoding
        wrote on last edited by
        #3

        Hei even i tried to follow the instructions from the same link which you attached. In the Cmake i am getting errors after i select c and c++ compilers and enter finish

        Error in configuration process, project files may be invalid
        

        Do you know what to do?

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Aren't you providing the path to a 64bit version of OpenCV while using a 32bit Qt ?

          On a side note, you shouldn't link to .dll files but to .lib files.

          B Offline
          B Offline
          Beriol
          wrote on last edited by
          #4

          @SGaist

          Damn, you're right. How did I not see that?

          I built the libraries again using the right mingw compiler and now it seems to be working! Thanks a lot! :D

          About the .lib files, there are none in the library. Or at least none I could find, only dll.

          @beginMyCoding

          From what I've seen it's kind of normal for Cmake to throw some errors here and there. If you try hitting the configure botton again what happens?

          B 1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            You're welcome !

            Late night debugging can have that kind of effect ;)

            Since you have it working now, please mark the thread as solved using the "Topic Tool" button so that other forum users may know a solution has been found :)

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • B Beriol

              @SGaist

              Damn, you're right. How did I not see that?

              I built the libraries again using the right mingw compiler and now it seems to be working! Thanks a lot! :D

              About the .lib files, there are none in the library. Or at least none I could find, only dll.

              @beginMyCoding

              From what I've seen it's kind of normal for Cmake to throw some errors here and there. If you try hitting the configure botton again what happens?

              B Offline
              B Offline
              beginMyCoding
              wrote on last edited by
              #6

              @Beriol its the same error again and again
              can you write in brief what all you have done, it will be much useful for me and others who are trying it for first time.

              B 1 Reply Last reply
              0
              • B beginMyCoding

                @Beriol its the same error again and again
                can you write in brief what all you have done, it will be much useful for me and others who are trying it for first time.

                B Offline
                B Offline
                Beriol
                wrote on last edited by
                #7

                @beginMyCoding

                I followed exactly the guide I posted in the first post. For me the hard part was actually linking the libraries, not building them.

                Are you sure you selected the right compilers? The path should be something like:
                C:\YourPathToQT\Qt\Tools\mingw48_32\bin\gcc.exe <-- for C
                C:\YourPathToQT\Qt\Tools\mingw48_32\bin\g++.exe <-- for C++

                In my case inside the "Tools" folder there is also a folder called MinGW which also contain the bin with the compilers, but do NOT use that (which was my mistake).

                Besides this, did you add the path to CMake to your system PATH variable and restarted the computer?

                B 1 Reply Last reply
                0
                • B Beriol

                  @beginMyCoding

                  I followed exactly the guide I posted in the first post. For me the hard part was actually linking the libraries, not building them.

                  Are you sure you selected the right compilers? The path should be something like:
                  C:\YourPathToQT\Qt\Tools\mingw48_32\bin\gcc.exe <-- for C
                  C:\YourPathToQT\Qt\Tools\mingw48_32\bin\g++.exe <-- for C++

                  In my case inside the "Tools" folder there is also a folder called MinGW which also contain the bin with the compilers, but do NOT use that (which was my mistake).

                  Besides this, did you add the path to CMake to your system PATH variable and restarted the computer?

                  B Offline
                  B Offline
                  beginMyCoding
                  wrote on last edited by
                  #8

                  @Beriol
                  I downloaded and extracted openCV. Later installed Qt. Added the directories
                  C:\Qt\5.5\mingw492_32\bin
                  C:\opencv\build\x86\vc12\bin
                  to the path in Environment variables.

                  Later downloaded CMake and installed it and added its path
                  C:\CMake\bin
                  Created an empty folder opencv-mingw in C-Drive

                  Rebooted Laptop

                  In CMake i selected
                  the sourcecode Directory as C:\Qt\Tools\mingw492_32\bin
                  (also tried with C:\Qt\5.5\mingw492_32\bin)
                  Buid the binary in C:/opencv-mingw and hit configure button

                  Selected MinGW Makefiles from dropdown menu. Then it asked to specify native compilers
                  Specified C:/Qt/Tools/mingw491_32/bin/gcc.exe for C
                  specified C:/Qt/Tools/mingw491_32/bin/g++.exe for C++
                  and hit finish

                  IT GAVE ME ERROR
                  Error in configuration process, Project files may be invalid

                  B 1 Reply Last reply
                  0
                  • B beginMyCoding

                    @Beriol
                    I downloaded and extracted openCV. Later installed Qt. Added the directories
                    C:\Qt\5.5\mingw492_32\bin
                    C:\opencv\build\x86\vc12\bin
                    to the path in Environment variables.

                    Later downloaded CMake and installed it and added its path
                    C:\CMake\bin
                    Created an empty folder opencv-mingw in C-Drive

                    Rebooted Laptop

                    In CMake i selected
                    the sourcecode Directory as C:\Qt\Tools\mingw492_32\bin
                    (also tried with C:\Qt\5.5\mingw492_32\bin)
                    Buid the binary in C:/opencv-mingw and hit configure button

                    Selected MinGW Makefiles from dropdown menu. Then it asked to specify native compilers
                    Specified C:/Qt/Tools/mingw491_32/bin/gcc.exe for C
                    specified C:/Qt/Tools/mingw491_32/bin/g++.exe for C++
                    and hit finish

                    IT GAVE ME ERROR
                    Error in configuration process, Project files may be invalid

                    B Offline
                    B Offline
                    Beriol
                    wrote on last edited by
                    #9

                    @beginMyCoding

                    The "sourcecode directory" inside CMake should point to the folder that contains the source code for OpenCV, not the folder that contains compiler executables like the one you're using!

                    So, you should put the path to the folder where you extracted the OpenCV stuff. Something like "C:/opencv/sources". That's why you're getting the error at start, there are no source files to configure :)

                    B 1 Reply Last reply
                    1
                    • B Beriol

                      @beginMyCoding

                      The "sourcecode directory" inside CMake should point to the folder that contains the source code for OpenCV, not the folder that contains compiler executables like the one you're using!

                      So, you should put the path to the folder where you extracted the OpenCV stuff. Something like "C:/opencv/sources". That's why you're getting the error at start, there are no source files to configure :)

                      B Offline
                      B Offline
                      beginMyCoding
                      wrote on last edited by
                      #10

                      @Beriol Oh yes, thanks for the that
                      It was my silly mistake... It is working and I have generated the compilers in Cmake.

                      But in Command prompt after entering mingw32–make ,
                      I was left with errors at 31%, I referred the comments in the link and unchecked WITH_IPP and regenerated in Cmake.

                      But this time I was a getting errors at 37% in Command prompt.

                      makefile: 148: recipe for target 'all' failed
                      mingw32-make: ***[all] Error 2
                      

                      Do you know anything about this?

                      B 1 Reply Last reply
                      0
                      • B beginMyCoding

                        @Beriol Oh yes, thanks for the that
                        It was my silly mistake... It is working and I have generated the compilers in Cmake.

                        But in Command prompt after entering mingw32–make ,
                        I was left with errors at 31%, I referred the comments in the link and unchecked WITH_IPP and regenerated in Cmake.

                        But this time I was a getting errors at 37% in Command prompt.

                        makefile: 148: recipe for target 'all' failed
                        mingw32-make: ***[all] Error 2
                        

                        Do you know anything about this?

                        B Offline
                        B Offline
                        Beriol
                        wrote on last edited by
                        #11

                        @beginMyCoding

                        It happened to me too, but I don't remember what exactly fixxed that problem.

                        Try this: in CMake tick the option "Advanced" (it's on the right after the search bar), and search for CMAKE__MAKE_PROGRAM; make sure that it points to the mingw32-make.exe inside you Qt folder "C:\Qt\Tools\mingw492_32\bin\mingw32-make.exe". I remember that in my case it wasn't set right and I used to get errors because of that.

                        Besides this I'm not sure what else you could do... Did you check "WITH_QT"?
                        Also, try unchecking "WITH_CUDA". I remember reading somewhere that it might give problems, but I actually don't remember if it gave me any while building.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved