Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. OpenCV integration with Qt6

OpenCV integration with Qt6

Scheduled Pinned Locked Moved Solved Qt 6
14 Posts 8 Posters 7.9k Views
  • 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.
  • C Christian Ehrlicher
    9 May 2022, 19:57

    D:\opencv-build != D:\opencv-4.x.build

    C Offline
    C Offline
    Catman
    wrote on 9 May 2022, 20:10 last edited by
    #5

    @Christian-Ehrlicher Act like they are the same, I tried to install OpenCV like 20 times after the original post and this CMake Image is just more recent.
    fafafaafaffaaff.png

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 9 May 2022, 20:26 last edited by Christian Ehrlicher 5 Sept 2022, 20:26
      #6

      You Selected the wrong generator (Visual Studio) and not the Makefile generator and therefore a VS solution file was created. Remove the build dir, make sure no vsvars*.bat is not called so cmake does not pick up MSVC and call cmake with '-G MinGW Makefiles'

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      C 1 Reply Last reply 9 May 2022, 20:36
      0
      • C Christian Ehrlicher
        9 May 2022, 20:26

        You Selected the wrong generator (Visual Studio) and not the Makefile generator and therefore a VS solution file was created. Remove the build dir, make sure no vsvars*.bat is not called so cmake does not pick up MSVC and call cmake with '-G MinGW Makefiles'

        C Offline
        C Offline
        Catman
        wrote on 9 May 2022, 20:36 last edited by Catman 5 Sept 2022, 20:38
        #7

        @Christian-Ehrlicher I'm new to Cmake what do you mean by
        "make sure no vsvars*.bat is not called"

        I think what you mean is that I just have to change my generator to MinGW Makefile, but then:gafasdfasdasdasd.png
        In the console above ^
        'Release' build type is used by default. Use CMAKE_BUILD_TYPE to specify build type (Release or Debug)
        CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
        CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
        Configuring incomplete, errors occurred!

        M 1 Reply Last reply 10 May 2022, 12:56
        0
        • C Online
          C Online
          cristian-adam
          wrote on 9 May 2022, 21:48 last edited by
          #8

          The https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows page is outdated and doesn't apply to Qt6 anymore.

          That page needs to be rewritten to deal with CMake, Qt6 and having a OpenCV CMake example.

          I think the easiest way of dealing with 3rd party dependencies would be to use a source package manager like conan, vcpkg or cpp-pm.

          1 Reply Last reply
          0
          • C Catman
            9 May 2022, 20:36

            @Christian-Ehrlicher I'm new to Cmake what do you mean by
            "make sure no vsvars*.bat is not called"

            I think what you mean is that I just have to change my generator to MinGW Makefile, but then:gafasdfasdasdasd.png
            In the console above ^
            'Release' build type is used by default. Use CMAKE_BUILD_TYPE to specify build type (Release or Debug)
            CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
            CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
            Configuring incomplete, errors occurred!

            M Offline
            M Offline
            mchinand
            wrote on 10 May 2022, 12:56 last edited by
            #9

            In a terminal, add the MinGW's bin directory to your path and then start the cmake_gui from that terminal. e.g., set PATH=D:\Qt\Tools\mingw1120_64\bin;%PATH%. That way, CMake should be able to find the compiler, make, etc.

            1 Reply Last reply
            0
            • C Online
              C Online
              cristian-adam
              wrote on 10 May 2022, 15:42 last edited by cristian-adam 5 Oct 2022, 20:24
              #10

              I just tested Qt 6.2.3, OpenCV 4.5.5 with MinGW 11.2.0, and everything worked as expected 🙂

              I used CMake 3.21.3 (but any recent version should be fine) and Ninja 1.10.2.

              Compiling OpenCV

              I've extracted the OpenCV source package into c:\Projects\opencv\opencv-4.5.5.

              Then I've opened a command prompt window and set the environment:

              set PATH=c:\mingw64\bin;c:\tools\ninja;c:\tools\cmake\bin;%PATH%
              

              Your paths might vary so update accordingly.

              Then configured OpenCV:

              cd c:\Projects\opencv
              cmake -G Ninja -D CMAKE_BUILD_TYPE=Release -S opencv-4.5.5 -B build-opencv -D WITH_QT=ON -D CMAKE_PREFIX_PATH=C:/Qt/6.2.3/mingw_64
              

              Then built OpenCV:

              cmake --build build-opencv
              

              And installed OpenCV

              cmake --install build-opencv --prefix opencv-install
              

              Using OpenCV

              I've created test-qt CMake Qt Widgets example.

              In CMakeLists.txt I have added:

              find_package(OpenCV REQUIRED)
              

              This command finds the OpenCV CMake package and sets some CMake variables which I used for the test-qt executable target:

              target_include_directories(test-qt PRIVATE ${OpenCV_INCLUDE_DIRS})
              target_link_libraries(test-qt PRIVATE ${OpenCV_LIBS})
              

              And in the CMake project settings I have changed the CMAKE_PREFIX_PATH in Initial Configuration to:

              %{Qt:QT_INSTALL_PREFIX};c:\Projects\opencv\opencv-install
              

              Then in mainwindow.cpp I've added the OpenCV headers:

              #include <opencv2/core/core.hpp>
              #include <opencv2/highgui/highgui.hpp>
              

              and in the constructor the OpenCV usage:

                  // read an image
                  cv::Mat image = cv::imread("c:/Windows/Web/Wallpaper/Windows/img0.jpg", 1);
                  // create image window named "Wallpaper"
                  cv::namedWindow("Wallpaper");
                  // show the image on window
                  cv::imshow("Wallpaper", image);
              

              Then compiled and run my application in Qt Creator 7.0.1. 🎉

              C M D 3 Replies Last reply 11 May 2022, 19:46
              6
              • C cristian-adam
                10 May 2022, 15:42

                I just tested Qt 6.2.3, OpenCV 4.5.5 with MinGW 11.2.0, and everything worked as expected 🙂

                I used CMake 3.21.3 (but any recent version should be fine) and Ninja 1.10.2.

                Compiling OpenCV

                I've extracted the OpenCV source package into c:\Projects\opencv\opencv-4.5.5.

                Then I've opened a command prompt window and set the environment:

                set PATH=c:\mingw64\bin;c:\tools\ninja;c:\tools\cmake\bin;%PATH%
                

                Your paths might vary so update accordingly.

                Then configured OpenCV:

                cd c:\Projects\opencv
                cmake -G Ninja -D CMAKE_BUILD_TYPE=Release -S opencv-4.5.5 -B build-opencv -D WITH_QT=ON -D CMAKE_PREFIX_PATH=C:/Qt/6.2.3/mingw_64
                

                Then built OpenCV:

                cmake --build build-opencv
                

                And installed OpenCV

                cmake --install build-opencv --prefix opencv-install
                

                Using OpenCV

                I've created test-qt CMake Qt Widgets example.

                In CMakeLists.txt I have added:

                find_package(OpenCV REQUIRED)
                

                This command finds the OpenCV CMake package and sets some CMake variables which I used for the test-qt executable target:

                target_include_directories(test-qt PRIVATE ${OpenCV_INCLUDE_DIRS})
                target_link_libraries(test-qt PRIVATE ${OpenCV_LIBS})
                

                And in the CMake project settings I have changed the CMAKE_PREFIX_PATH in Initial Configuration to:

                %{Qt:QT_INSTALL_PREFIX};c:\Projects\opencv\opencv-install
                

                Then in mainwindow.cpp I've added the OpenCV headers:

                #include <opencv2/core/core.hpp>
                #include <opencv2/highgui/highgui.hpp>
                

                and in the constructor the OpenCV usage:

                    // read an image
                    cv::Mat image = cv::imread("c:/Windows/Web/Wallpaper/Windows/img0.jpg", 1);
                    // create image window named "Wallpaper"
                    cv::namedWindow("Wallpaper");
                    // show the image on window
                    cv::imshow("Wallpaper", image);
                

                Then compiled and run my application in Qt Creator 7.0.1. 🎉

                C Offline
                C Offline
                Catman
                wrote on 11 May 2022, 19:46 last edited by
                #11

                @cristian-adam
                It really works and it wasn't that hard, your instructions were simple and clear.
                I Highly appreciate your effort, and I hope you wonderful day/night :).

                1 Reply Last reply
                0
                • C cristian-adam
                  10 May 2022, 15:42

                  I just tested Qt 6.2.3, OpenCV 4.5.5 with MinGW 11.2.0, and everything worked as expected 🙂

                  I used CMake 3.21.3 (but any recent version should be fine) and Ninja 1.10.2.

                  Compiling OpenCV

                  I've extracted the OpenCV source package into c:\Projects\opencv\opencv-4.5.5.

                  Then I've opened a command prompt window and set the environment:

                  set PATH=c:\mingw64\bin;c:\tools\ninja;c:\tools\cmake\bin;%PATH%
                  

                  Your paths might vary so update accordingly.

                  Then configured OpenCV:

                  cd c:\Projects\opencv
                  cmake -G Ninja -D CMAKE_BUILD_TYPE=Release -S opencv-4.5.5 -B build-opencv -D WITH_QT=ON -D CMAKE_PREFIX_PATH=C:/Qt/6.2.3/mingw_64
                  

                  Then built OpenCV:

                  cmake --build build-opencv
                  

                  And installed OpenCV

                  cmake --install build-opencv --prefix opencv-install
                  

                  Using OpenCV

                  I've created test-qt CMake Qt Widgets example.

                  In CMakeLists.txt I have added:

                  find_package(OpenCV REQUIRED)
                  

                  This command finds the OpenCV CMake package and sets some CMake variables which I used for the test-qt executable target:

                  target_include_directories(test-qt PRIVATE ${OpenCV_INCLUDE_DIRS})
                  target_link_libraries(test-qt PRIVATE ${OpenCV_LIBS})
                  

                  And in the CMake project settings I have changed the CMAKE_PREFIX_PATH in Initial Configuration to:

                  %{Qt:QT_INSTALL_PREFIX};c:\Projects\opencv\opencv-install
                  

                  Then in mainwindow.cpp I've added the OpenCV headers:

                  #include <opencv2/core/core.hpp>
                  #include <opencv2/highgui/highgui.hpp>
                  

                  and in the constructor the OpenCV usage:

                      // read an image
                      cv::Mat image = cv::imread("c:/Windows/Web/Wallpaper/Windows/img0.jpg", 1);
                      // create image window named "Wallpaper"
                      cv::namedWindow("Wallpaper");
                      // show the image on window
                      cv::imshow("Wallpaper", image);
                  

                  Then compiled and run my application in Qt Creator 7.0.1. 🎉

                  M Offline
                  M Offline
                  Morgan7794
                  wrote on 17 Sept 2023, 09:41 last edited by
                  #12

                  @cristian-adam said in OpenCV integration with Qt6:

                  Using OpenCV
                  I've created test-qt CMake Qt Widgets example.
                  In CMakeLists.txt I have added:
                  find_package(OpenCV REQUIRED)

                  This command finds the OpenCV CMake package and sets some CMake variables which I used for the test-qt executable target:
                  target_include_directories(test-qt PRIVATE ${OpenCV_INCLUDE_DIRS})
                  target_link_libraries(test-qt PRIVATE ${OpenCV_LIBS})

                  And in the CMake project settings I have changed the CMAKE_PREFIX_PATH in Initial Configuration to:
                  %{Qt:QT_INSTALL_PREFIX};c:\Projects\opencv\opencv-install

                  Hey brother, I don't quite understand the specific operation here. Could you please guide me? Thank you

                  BondrusiekB 1 Reply Last reply 11 Oct 2023, 16:23
                  0
                  • M Morgan7794
                    17 Sept 2023, 09:41

                    @cristian-adam said in OpenCV integration with Qt6:

                    Using OpenCV
                    I've created test-qt CMake Qt Widgets example.
                    In CMakeLists.txt I have added:
                    find_package(OpenCV REQUIRED)

                    This command finds the OpenCV CMake package and sets some CMake variables which I used for the test-qt executable target:
                    target_include_directories(test-qt PRIVATE ${OpenCV_INCLUDE_DIRS})
                    target_link_libraries(test-qt PRIVATE ${OpenCV_LIBS})

                    And in the CMake project settings I have changed the CMAKE_PREFIX_PATH in Initial Configuration to:
                    %{Qt:QT_INSTALL_PREFIX};c:\Projects\opencv\opencv-install

                    Hey brother, I don't quite understand the specific operation here. Could you please guide me? Thank you

                    BondrusiekB Offline
                    BondrusiekB Offline
                    Bondrusiek
                    wrote on 11 Oct 2023, 16:23 last edited by
                    #13

                    @Morgan7794 hi please see this example: https://github.com/FelgoSDK/Qt-Felgo-OpenCV maybe it helps you.

                    1 Reply Last reply
                    0
                    • C cristian-adam
                      10 May 2022, 15:42

                      I just tested Qt 6.2.3, OpenCV 4.5.5 with MinGW 11.2.0, and everything worked as expected 🙂

                      I used CMake 3.21.3 (but any recent version should be fine) and Ninja 1.10.2.

                      Compiling OpenCV

                      I've extracted the OpenCV source package into c:\Projects\opencv\opencv-4.5.5.

                      Then I've opened a command prompt window and set the environment:

                      set PATH=c:\mingw64\bin;c:\tools\ninja;c:\tools\cmake\bin;%PATH%
                      

                      Your paths might vary so update accordingly.

                      Then configured OpenCV:

                      cd c:\Projects\opencv
                      cmake -G Ninja -D CMAKE_BUILD_TYPE=Release -S opencv-4.5.5 -B build-opencv -D WITH_QT=ON -D CMAKE_PREFIX_PATH=C:/Qt/6.2.3/mingw_64
                      

                      Then built OpenCV:

                      cmake --build build-opencv
                      

                      And installed OpenCV

                      cmake --install build-opencv --prefix opencv-install
                      

                      Using OpenCV

                      I've created test-qt CMake Qt Widgets example.

                      In CMakeLists.txt I have added:

                      find_package(OpenCV REQUIRED)
                      

                      This command finds the OpenCV CMake package and sets some CMake variables which I used for the test-qt executable target:

                      target_include_directories(test-qt PRIVATE ${OpenCV_INCLUDE_DIRS})
                      target_link_libraries(test-qt PRIVATE ${OpenCV_LIBS})
                      

                      And in the CMake project settings I have changed the CMAKE_PREFIX_PATH in Initial Configuration to:

                      %{Qt:QT_INSTALL_PREFIX};c:\Projects\opencv\opencv-install
                      

                      Then in mainwindow.cpp I've added the OpenCV headers:

                      #include <opencv2/core/core.hpp>
                      #include <opencv2/highgui/highgui.hpp>
                      

                      and in the constructor the OpenCV usage:

                          // read an image
                          cv::Mat image = cv::imread("c:/Windows/Web/Wallpaper/Windows/img0.jpg", 1);
                          // create image window named "Wallpaper"
                          cv::namedWindow("Wallpaper");
                          // show the image on window
                          cv::imshow("Wallpaper", image);
                      

                      Then compiled and run my application in Qt Creator 7.0.1. 🎉

                      D Offline
                      D Offline
                      DeSa
                      wrote on 6 Apr 2024, 23:53 last edited by
                      #14

                      @cristian-adam After spending 6 hours trying to set up OpenCV with Qt6 while following several tutorials (only to find out that it all does not apply to Qt6), your solution worked perfectly fine.

                      I should only add that I struggled with Qt Creator GUI looking for cmake project settings to change CMAKE_PREFIX_PATH. but finally got it (CTRL+5) ,
                      Just bookmarked this thread for good.

                      many thanks for this!

                      1 Reply Last reply
                      1

                      • Login

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