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. OpenCV libraries with Qt
Forum Updated to NodeBB v4.3 + New Features

OpenCV libraries with Qt

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
12 Posts 3 Posters 5.9k 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.
  • deleted511D Offline
    deleted511D Offline
    deleted511
    wrote on last edited by
    #3

    I did that originally but yet still no change. My QT is recognizing the functions of openCV so I believe my path is correct but the libraries are not transferring for some reason and giving me unresolved internal issues (which basically means I messed up with my libraries.)

    1 Reply Last reply
    0
    • L Offline
      L Offline
      LuGRU
      wrote on last edited by
      #4

      As I did wrote, Your path is incorrect and -l ... was left for You to fill in.

      Indeed linker will fail due to unresolved symbols (as i.e. "opencv2/core/core.hpp" etc. are not compiled into application and linker expect to find them in libs).

      To do so in project file add this:

      win32 {
          INCLUDEPATH += C:/Users/[username]/Desktop/opencv/build/include
          LIBS += -LC:/Users/[username]/Desktop/opencv/build/x64/vc12/lib/
      
          CONFIG(debug, debug|release) {
              LIBS += -lopencv_core2413d -lopencv_highgui2413d -lopencv_imgproc2413d
          }else{
              LIBS += -lopencv_core2413 -lopencv_highgui2413 -lopencv_imgproc2413
          }
      }
      

      As You can see there are two section, debug and release, and due to issue with cv::imread debug libs can't be used in release and vice versa.

      Main can be like:

      //#include <opencv2/opencv.hpp>
      #include <opencv2/core/core.hpp>
      #include <opencv2/highgui/highgui.hpp>
      //#include <opencv2/imgproc/imgproc.hpp>
      
      using namespace cv;
      
      #include <QDebug>
      
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
      
          const QString imgpath = qApp->applicationDirPath() + "/canada.png";
          Mat inputimage = imread( imgpath.toStdString());
      
          if (!inputimage.data) {
              qDebug() << "Error: image data is empty.";
          } else {
              imshow("display image", inputimage);
          }
      }
      

      In .exe location place PNG file, and copy appropriate libs there so app will find them.

      1 Reply Last reply
      0
      • deleted511D Offline
        deleted511D Offline
        deleted511
        wrote on last edited by
        #5

        I changed the .pro file to the one you had shown, but it does not run if I have the declarations inside the win32 loop, I also tried win64 but it would never enter the loop. Although if I removed the loop and did

        INCLUDEPATH += /Users/admin/Desktop/opencv/opencv/build/include

        LIBS += -LC:/Users/admin/Desktop/opencv/opencv/build/x64/vc12/lib/

        CONFIG(debug, debug|release) {
        LIBS += -lopencv_core2413d -lopencv_highgui2413d -lopencv_imgproc2413d
        }else{
        LIBS += -lopencv_core2413 -lopencv_highgui2413 -lopencv_imgproc2413
        }

        which fixed my unresolved internal issues. It now compiles and runs but it crashes instantly when finished compiling.

        Starting C:\Users\admin\Documents\build-yoyo-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug\debug\yoyo.exe...
        The program has unexpectedly finished.
        C:\Users\admin\Documents\build-yoyo-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug\debug\yoyo.exe crashed.

        Now the problem is with the program crashing. I am using Desktop Qt 5.7.0MSVC2015_64bit kit.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          LuGRU
          wrote on last edited by
          #6

          It crashes because You're missing binaries (like in .dll binaries).
          Either:

          1. add into LIBS+=-L/path/to/lib/bin
          2. copy appropriate libs to executable location
          1 Reply Last reply
          0
          • deleted511D Offline
            deleted511D Offline
            deleted511
            wrote on last edited by
            #7

            This is my location to the bin:

            LIBS += -LC:/Users/admin/Desktop/opencv/opencv/build/x64/vc12/bin/

            which includes all the .dll files, but still same issue. I also copied and pasted all the .dill files from the bin folder and placed them inside my .exe location. Still no difference.

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

              Hi,

              You should use a tool like Dependency Walker to check whether you have anything else missing from OpenCV.

              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
              • deleted511D Offline
                deleted511D Offline
                deleted511
                wrote on last edited by
                #9

                @SGaist @LuGRU I think my problem may be that the .dll files are compiled for VisualStudio not GCC compiler. I am using the MSVC_2015_64bit Kit but someone suggested I should use minGW_32bit instead. But the problem is that my entire project is compiled with MSVC_2015_64bit and would like to keep it that way. Im sure there must be some .dlll files that are compiled for MSVC, rather than just the GCC compiler.

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

                  There's only one option: build everything with the same compiler. You can't mix and match stuff built with different compilers even from different version of VS.

                  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
                  • deleted511D Offline
                    deleted511D Offline
                    deleted511
                    wrote on last edited by
                    #11

                    @SGaist Yes that makes sense but if I download the newest openCV 3.2 (http://opencv.org/) are these .dll files compatible with MSVC? Because every time I run my program with MSCV2015_64bit kit then it compiles and runs but then crashes which means I cannot find the proper .dll files but I am correct labeling my pathway to them. I even transferred the necessary .dll files in my .exe folder of my project.

                    But if compile my project with minGW kit then it has linker issues.

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

                      Check with Dependency Walker that you have all required dependencies.

                      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

                      • Login

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