1

I am trying to use OpenCV library in QT but i'm keep getting error which shouldn't suppose to occur.

Here is the code of my simple program.

#include <opencv2/highgui/highgui.hpp>


using namespace cv; //All classes and functions defined in the C++ API of OpenCV are defined within the name space cv.
using namespace std;


int main(){

    Mat image = imread("C:/opencv/opencv/samples/c/cat.jpg",CV_LOAD_IMAGE_GRAYSCALE);

    cout << "Number of Rows: " << image.rows << endl << "Number of coloumn: " << image.cols;

    imshow ("image",image);
    waitKey(0);
}

C:\Users\Cipher\Downloads\Programs\untitled2\main.cpp:1: error: C1083: Cannot open include file: 'highgui.hpp': No such file or directory

The problem is that, the file is there but QT couldn't able to find the file, i can access the file and even when i hold ctrl and move my cursor over #include <opencv2/highgui/highgui.hpp> and click on it i am successfully accessing a file, but still QT keep saying that it could find such file or directory :/ what is the problem with that :/

have a look,

enter image description here

I can access all the methods in the CV namespace then why i am still getting this error ?

have a look,

enter image description here

all functions of opencv are accessible but still i'm getting the error aforementioned.

please guide me.

2 Answers 2

5
  1. Have this in .pro file INCLUDEPATH += path_to_opencv/opencv/build/include

  2. Look in the leftmost pane of Qt Creator. There is a Projects tab. (ctrl+5) should reach you there. Go to Build Environment. Click on Details to get list of System Environment Variables. Goto INCLUDE variable in the list. Select and click Edit. Add path_to_opencv/opencv/build/include.

[ path_to_opencv is the path where your opencv directory resides.]

Sign up to request clarification or add additional context in comments.

2 Comments

This fixed it for me, but I've never had this problem before when linking OpenCV and Qt. Usually just having an INCLUDEPATH is sufficient. Is it specifically an issue with MSVC?
@Josh Hi did you get your answer? I also have this question need to be answered. Thanks!
2
  1. in the .pro file include the headers..
  2. link the libraries...
  3. add the address of the bin folder of opencv to environmental variables.

    Mat image = imread(""C:\\opencv\\opencv\\samples\\c\\cat.jpg",CV_LOAD_IMAGE_GRAYSCALE") use double backslashes..

  4. your .pro file should look like dis..

    INCLUDEPATH += C:\opencv\build\include\ LIBS += -LC:\opencv\build_vs\lib\Debug\

    -lopencv_core243d -lopencv_highgui243d -lopencv_video243d -lopencv_imgproc243d\

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.