Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Building OpenCV for Qt
Forum Updated to NodeBB v4.3 + New Features

Building OpenCV for Qt

Scheduled Pinned Locked Moved Solved 3rd Party Software
20 Posts 4 Posters 8.3k Views 2 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.
  • M Offline
    M Offline
    MartijnKor
    wrote on 25 Apr 2017, 20:47 last edited by
    #1

    Hello everyone,

    for the past couple of hours I've tried to get OpenCV to work with Qt, but without any luck. I've followed the instructions on this page on the Qt-website to the letter and all goes well until one of the final steps. When I have run CMake the file directory of opencv-build still looks the excact same. It did get significantly bigger though (from 9.27MB to 1.75GB). The problem is that the file structure is in no way what it needs to be and the files needed to link and include in the project file are nowhere to be found. here is a link to a screenshot of the file directory shared with Dropbox. I feel like I am so close, but I really need your help with this one. Thanks in advance!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MartijnKor
      wrote on 1 May 2017, 11:34 last edited by MartijnKor 5 Jan 2017, 13:57
      #19

      So after a lot of searching the internet and getting very frustrated I found a solution that seems to work for me so far. I have no idea why this solves the problem and I think it is kind of strange but here is:

      On Youtube I found a video where someone explained the exact same steps as described in the original tutorial published by Qt. The problem was the linking. CMake gave me some .dll.a files which I thoughtwas strange.
      In this video that person got the excact same files as me (.dll.a). The problem was on how to link these files in the .pro-file.

      So here is the solution.
      Instead of using this:

      LIBS += -LD:\opencv-build\install\x86\mingw\lib \
          -lopencv_core320.dll \
          -lopencv_highgui320.dll \
          -lopencv_imgcodecs320.dll \
          -lopencv_imgproc320.dll \
          -lopencv_features2d320.dll \
          -lopencv_calib3d320.dll
      

      Use this:

      LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_calib3d320.dll.a"
      LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_core320.dll.a"
      LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_features2d320.dll.a"
      LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_flann320.dll.a"
      LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_highgui320.dll.a"
      LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_imgcodecs320.dll.a"
      LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_imgproc320.dll.a"
      LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_ml320.dll.a"
      LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_objdetect320.dll.a"
      LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_photo320.dll.a"
      LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_shape320.dll.a"
      LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_stitching320.dll.a"
      LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_superres320.dll.a"
      LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_video320.dll.a"
      LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_videoio320.dll.a"
      LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_videostab320.dll.a"
      

      EDIT: This path "C:\opencv-build\install\x86\mingw\lib" also needs to be inserted in Path in System variables I have noticed in order to work.
      Using those (longer unfortunately) lines of code, it did work for me. If anyone knows a simpler way of making this work I and presumably other people would appreciate it. Everyone thanks a lot for their help!

      -Martijn

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 25 Apr 2017, 22:21 last edited by
        #2

        Hi and welcome to devnet,

        Did you call make install ?

        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
        2
        • M Offline
          M Offline
          MartijnKor
          wrote on 25 Apr 2017, 22:30 last edited by
          #3

          Thanks! No i didn't. I called mingw32-make -j 4. I just tried to call make install, but make is not recognized as an internal or external command. My guess is that it needs to be added to path, but I have no idea how.

          M 1 Reply Last reply 25 Apr 2017, 22:39
          0
          • M MartijnKor
            25 Apr 2017, 22:30

            Thanks! No i didn't. I called mingw32-make -j 4. I just tried to call make install, but make is not recognized as an internal or external command. My guess is that it needs to be added to path, but I have no idea how.

            M Offline
            M Offline
            MartijnKor
            wrote on 25 Apr 2017, 22:39 last edited by
            #4

            @MartijnKor Ow wow sorry I feel really stupid now. Just forgot to run the last line of code I realise now. I will try this and give an update. Thanks!

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MartijnKor
              wrote on 25 Apr 2017, 22:57 last edited by
              #5

              Okay so that worked. Unfortunately I now face another problem. Link to screenshot shared in Dropbox I get a linker error. This is what my libs file directory looks like: another link. Could it have something to do with the .a-extension? I hope anyone has an answer! Thanks!

              J 1 Reply Last reply 26 Apr 2017, 06:55
              0
              • M MartijnKor
                25 Apr 2017, 22:57

                Okay so that worked. Unfortunately I now face another problem. Link to screenshot shared in Dropbox I get a linker error. This is what my libs file directory looks like: another link. Could it have something to do with the .a-extension? I hope anyone has an answer! Thanks!

                J Offline
                J Offline
                J.Hilk
                Moderators
                wrote on 26 Apr 2017, 06:55 last edited by J.Hilk
                #6

                @MartijnKor You said, you build openCV with mingw32, so you're trying to build your project with the same compiler right?

                Also, it says int the docu that extensions and prefixes are not necessary .
                However, if I remember correctly, it never worked for me, if I added the extensions -.dll in your case - to the path.


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 26 Apr 2017, 07:25 last edited by
                  #7

                  To add to @J-Hilk you don't link to .dll. On Windows the dynamic libraries are not linking target like on Linux. Depending on your compiler you'll have .lib or .a files for that.

                  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
                  1
                  • M Offline
                    M Offline
                    MartijnKor
                    wrote on 26 Apr 2017, 10:39 last edited by
                    #8

                    Okay thanks! The problem is that my opencv-build directory does not contain any .lib-files.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 26 Apr 2017, 11:46 last edited by
                      #9

                      You have .a files haven't you ?

                      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
                      • M Offline
                        M Offline
                        MartijnKor
                        wrote on 26 Apr 2017, 12:21 last edited by
                        #10

                        Well kind of. I have .dll.a files. And I have no idea how to make this work in Qt. The way it is shown in the example does not work for me, no matter what minor changes I try.

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 26 Apr 2017, 19:45 last edited by
                          #11

                          What example ?

                          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
                          • M Offline
                            M Offline
                            MartijnKor
                            wrote on 26 Apr 2017, 21:13 last edited by
                            #12

                            The example/instructions on the Qt website on how to get opencv to work with Qt for Windows. On the bottom of the page they give an example code to test whether everything has been installed the properly. The instructions are on this page

                            1 Reply Last reply
                            0
                            • Y Offline
                              Y Offline
                              Yacinoben
                              wrote on 27 Apr 2017, 00:26 last edited by
                              #13

                              Hi
                              -Open file "opencv\sources\cmake\OpenCVCompilerOptions.cmake", and comment this line :
                              #add_extra_compiler_option(-Werror=non-virtual-dtor)
                              -After click in configure, no check : WITH_IPP
                              -And use mingw32-make , mingw32-make install

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                MartijnKor
                                wrote on 27 Apr 2017, 07:46 last edited by
                                #14

                                Thanks for your help. I deleted my opencv-build directory, commented that line in CMake-file. Did CMake again, with IPP unchecked, ran make and make install again, but no luck. Still the same problem.

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 27 Apr 2017, 22:19 last edited by
                                  #15

                                  Maybe a silly question but, are you also using the Qt MinGW version to build that project ?

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

                                  M 1 Reply Last reply 28 Apr 2017, 17:57
                                  0
                                  • S SGaist
                                    27 Apr 2017, 22:19

                                    Maybe a silly question but, are you also using the Qt MinGW version to build that project ?

                                    M Offline
                                    M Offline
                                    MartijnKor
                                    wrote on 28 Apr 2017, 17:57 last edited by
                                    #16

                                    @SGaist Yes I am. I installed the mingw included in the Qt online installer and included it in Path. I also select those as the compilers in CMake. Thanks guys for all your help to untill this point. I really appreciate it!

                                    1 Reply Last reply
                                    0
                                    • S Offline
                                      S Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on 28 Apr 2017, 20:33 last edited by
                                      #17

                                      Do you have a static or dynamic build of OpenCV ?

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

                                      M 1 Reply Last reply 1 May 2017, 11:11
                                      0
                                      • S SGaist
                                        28 Apr 2017, 20:33

                                        Do you have a static or dynamic build of OpenCV ?

                                        M Offline
                                        M Offline
                                        MartijnKor
                                        wrote on 1 May 2017, 11:11 last edited by
                                        #18

                                        @SGaist That's a good question. According to this YouTube video(I am sorry, but this was quite new for me so I used this as a source of information) at 7:46 it looks like a mix of a static Linux(.a) library and a dynamic Windows(.dll) library, since the files I got after making it have a .dll.a extension.

                                        Anyway, I think I have found the solution for my problem. I will post it right away after this reaction :) Thanks SGaist for all your help!

                                        1 Reply Last reply
                                        0
                                        • M Offline
                                          M Offline
                                          MartijnKor
                                          wrote on 1 May 2017, 11:34 last edited by MartijnKor 5 Jan 2017, 13:57
                                          #19

                                          So after a lot of searching the internet and getting very frustrated I found a solution that seems to work for me so far. I have no idea why this solves the problem and I think it is kind of strange but here is:

                                          On Youtube I found a video where someone explained the exact same steps as described in the original tutorial published by Qt. The problem was the linking. CMake gave me some .dll.a files which I thoughtwas strange.
                                          In this video that person got the excact same files as me (.dll.a). The problem was on how to link these files in the .pro-file.

                                          So here is the solution.
                                          Instead of using this:

                                          LIBS += -LD:\opencv-build\install\x86\mingw\lib \
                                              -lopencv_core320.dll \
                                              -lopencv_highgui320.dll \
                                              -lopencv_imgcodecs320.dll \
                                              -lopencv_imgproc320.dll \
                                              -lopencv_features2d320.dll \
                                              -lopencv_calib3d320.dll
                                          

                                          Use this:

                                          LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_calib3d320.dll.a"
                                          LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_core320.dll.a"
                                          LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_features2d320.dll.a"
                                          LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_flann320.dll.a"
                                          LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_highgui320.dll.a"
                                          LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_imgcodecs320.dll.a"
                                          LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_imgproc320.dll.a"
                                          LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_ml320.dll.a"
                                          LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_objdetect320.dll.a"
                                          LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_photo320.dll.a"
                                          LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_shape320.dll.a"
                                          LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_stitching320.dll.a"
                                          LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_superres320.dll.a"
                                          LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_video320.dll.a"
                                          LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_videoio320.dll.a"
                                          LIBS += "C:\opencv-build\install\x86\mingw\lib\libopencv_videostab320.dll.a"
                                          

                                          EDIT: This path "C:\opencv-build\install\x86\mingw\lib" also needs to be inserted in Path in System variables I have noticed in order to work.
                                          Using those (longer unfortunately) lines of code, it did work for me. If anyone knows a simpler way of making this work I and presumably other people would appreciate it. Everyone thanks a lot for their help!

                                          -Martijn

                                          1 Reply Last reply
                                          0
                                          • S Offline
                                            S Offline
                                            SGaist
                                            Lifetime Qt Champion
                                            wrote on 1 May 2017, 13:52 last edited by
                                            #20

                                            Then why not:

                                            LIBS += -LD:/opencv-build/lib \
                                                -lopencv_core320 \
                                                -lopencv_highgui320 \
                                            # etc...
                                            

                                            ?

                                            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

                                            1/20

                                            25 Apr 2017, 20:47

                                            • Login

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