Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] Impossible to include OpenCV path
Forum Updated to NodeBB v4.3 + New Features

[solved] Impossible to include OpenCV path

Scheduled Pinned Locked Moved Solved General and Desktop
opencvincludepathqmake
9 Posts 2 Posters 13.3k 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.
  • G Offline
    G Offline
    Gmember
    wrote on 16 Jun 2016, 12:02 last edited by Gmember
    #1

    I am trying to configure a new Qt Creator project in order to use OpenCV 3.1.0. I downloaded the precompiled binaries from http://opencv.org/downloads.html, and I created an empty Qt gui project. The problem is that qmake doesn't find the opencv headers, no matter how I try to include their path. Here is my last attempt:

    QT       += core gui
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = App_v1
    TEMPLATE = app
    INCLUDEPATH += C:/OpenCV-3.1.0/opencv/build/include
    LIBS += -L”C:\OpenCV-3.1.0\opencv\build\x64\vc14\lib”
    LIBS += -lopencv_world310d
    SOURCES += main.cpp\
            mainwindow.cpp
    HEADERS  += mainwindow.h
    FORMS    += mainwindow.ui
    

    and in the code:

    #include <iostream>
    
    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/imgproc/imgproc.hpp>
    #include "mainwindow.h"
    #include <QApplication>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        cv::Mat image = cv::Mat::zeros(100, 100, CV_8UC3);
        cv::imshow("image", image);
        cv::waitKey(10);
    
        cout << "Hello cout!" << endl;
        cerr << "Hello cerr!" << endl;
        printf("Hello printf!");
        cout << flush;
    
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    
        return a.exec();
    }
    

    When I try to compile this, I get: "C1083: Cannot open include file: 'opencv2/core/core.hpp": No such file or directory
    (btw thanks Qt Creator for not letting me select and copy the text of the error. Sorry I digress...)
    I am sure that the path is correct, and the funny thing is that when I type cv:: the auto completion finds and lists the classes and functions in the cv namespace.... what is going on here?

    EDIT: I forgot to mention that OpenCV works perfectly with Visual Studio, so I know that it is installed correctly.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 16 Jun 2016, 12:11 last edited by
      #2

      I think the problem is that you have . (the dot) in the path.

      try replacing
      INCLUDEPATH += C:/OpenCV-3.1.0/opencv/build/include
      with
      INCLUDEPATH += "C:/OpenCV-3.1.0/opencv/build/include"

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      G 1 Reply Last reply 16 Jun 2016, 12:28
      0
      • G Offline
        G Offline
        Gmember
        wrote on 16 Jun 2016, 12:22 last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • V VRonin
          16 Jun 2016, 12:11

          I think the problem is that you have . (the dot) in the path.

          try replacing
          INCLUDEPATH += C:/OpenCV-3.1.0/opencv/build/include
          with
          INCLUDEPATH += "C:/OpenCV-3.1.0/opencv/build/include"

          G Offline
          G Offline
          Gmember
          wrote on 16 Jun 2016, 12:28 last edited by
          #4

          @VRonin Thank you for your reply. I tried, but it doesn't have any effect. I do not think that dots cause this problem (or at least, it is not mentioned anywhere). Apparently you need quotes for path with spaces only.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            VRonin
            wrote on 16 Jun 2016, 12:33 last edited by
            #5

            This is strange, the .pro looks correct. if C:/OpenCV-3.1.0/opencv/build/include/opencv2/core/core.hpp definitely exists then try clean your project before building, it might be just some leftovers

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            G 1 Reply Last reply 16 Jun 2016, 12:55
            1
            • V VRonin
              16 Jun 2016, 12:33

              This is strange, the .pro looks correct. if C:/OpenCV-3.1.0/opencv/build/include/opencv2/core/core.hpp definitely exists then try clean your project before building, it might be just some leftovers

              G Offline
              G Offline
              Gmember
              wrote on 16 Jun 2016, 12:55 last edited by
              #6

              @VRonin Yep that was the problem, thank you. I didn't think about cleaning before rebuilding, I believe that it should be automatic... Sadly, now I have another problem:

              :-1: error: LNK1104: cannot open file 'opencv_world310d.lib'

              and again, I know that the name of the file and the path are correct

              1 Reply Last reply
              0
              • V Offline
                V Offline
                VRonin
                wrote on 16 Jun 2016, 12:57 last edited by VRonin
                #7

                try replacing

                LIBS += -L”C:\OpenCV-3.1.0\opencv\build\x64\vc14\lib”
                LIBS += -lopencv_world310d
                

                with
                LIBS += "C:/OpenCV-3.1.0/opencv/build/x64/vc14/lib/opencv_world310d.lib"

                Clean and rebuild

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                G 1 Reply Last reply 16 Jun 2016, 13:10
                1
                • V VRonin
                  16 Jun 2016, 12:57

                  try replacing

                  LIBS += -L”C:\OpenCV-3.1.0\opencv\build\x64\vc14\lib”
                  LIBS += -lopencv_world310d
                  

                  with
                  LIBS += "C:/OpenCV-3.1.0/opencv/build/x64/vc14/lib/opencv_world310d.lib"

                  Clean and rebuild

                  G Offline
                  G Offline
                  Gmember
                  wrote on 16 Jun 2016, 13:10 last edited by
                  #8

                  @VRonin Thank you again, now it works. I also had to copy the dlls from Qt and opencv into the program folder, since it wouldn't find them otherwise. Now the program runs correctly, many thanks.

                  If I may ask one more question, do you know if it is possible to add a path for dlls in qmake? Or is that only related to the windows path variable, since the dlls are to be loaded at runtime after compilation?

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    VRonin
                    wrote on 16 Jun 2016, 13:21 last edited by
                    #9

                    dll paths do not influence the build so they are not included in qmake. if you use QtCreator in the right bar select project and in the build and run tab, select the run subtab and you can customise the run environment adding the paths of the dlls to the run environment PATH

                    otherwise you can use the INSTALLS of qmake to deploy all the binaries where you need them

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    1 Reply Last reply
                    2

                    9/9

                    16 Jun 2016, 13:21

                    • Login

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