0

I am working on windows 7, and installed and compiled OPENCV 2.4.6, it worked perfectly well with microsoft studio 2012, so I know how to find the path of OPENCV include and lib, and configure the path of bin in the system variables

But when it comes to QT, it totally didn't work at all. I know on the stackoverflow there are many questions about how to link opencv with QT in windows, But I tried all the answers, but it never worked out for me.

Here is my configuration which works for visual studio 2012.

system variable path:

  1. D:\Program Files\opencv\build\x64\vc11\bin;

include path:

  1. D:\Program Files\opencv\build\include\;
  2. D:\Program Files\opencv\build\include\opencv;
  3. D:\Program Files\opencv\build\include\opencv2;

lib path:

  1. D:\Program Files\opencv\build\x64\vc11\lib;

I have downloaded and installed QT 5.1.1, and started a project. In the pro, I edited like this,

INCLUDEPATH += D:\Program Files\opencv\build\include \

I assume this should be working, but in the main(), when I added the header

#include "opencv/cv.h"
#include <opencv/highgui.h>

QT compiler will always tell me 'no such file or directory'

This kind of stupid problem has stuck me in for days, I don't know where it goes wrong, could some people help me.

update: Thanks for everybody, Gibby's answer has helped me to solve the first issue of 'headers can't be found', but now then running the program, I got issues like 'release\test.exe:-1: error:LNK1120: 6 unresolved externals'

so it is definitely due to the linking of libraries , I have tried

LIBS += -LD:\Program Files\opencv\build\x64\vc11\lib \
    -lopencv_core246 \
    -lopencv_highgui246 \
    -lopencv_imgproc246 \
    -lopencv_features2d246 \
    -lopencv_calib3d246 \ 

or

LIBS += -LD:\Program Files\opencv\build\x64\vc11\lib \
    -lopencv_core246.lib \
    -lopencv_highgui246.lib \
    -lopencv_imgproc246.lib \
    -lopencv_features2d246.lib \
    -lopencv_calib3d246.lib \ 

or from How to link opencv in QtCreator and use Qt library

LIBS += -LD:\Program Files\opencv\build\x64\vc11\lib \
    libopencv_core246 \
    libopencv_highgui246 \
    libopencv_imgproc246 \
    libopencv_features2d246 \
    libopencv_calib3d246 \

but none of these work

Community
  • 1
  • 1
user824624
  • 7,077
  • 27
  • 106
  • 183
  • Did you checked that "opencv" is a really subdirectory of D:\Program Files\opencv\build\include? – Guid Dec 02 '13 at 17:31
  • yes, I did check many times, 'opencv' and 'opencv2' are subdirectory of that path. And I even checked the header files inside. still, no idea what went wrong – user824624 Dec 02 '13 at 17:33
  • I did like this -- INCLUDEPATH += "D:\Program Files\opencv\build\include" \ , still the same problem. I also tried -- INCLUDEPATH += "D:\Program Files\opencv\build\include\" , it would output a error 'missing the quote' – user824624 Dec 02 '13 at 17:40

3 Answers3

3

You need to build OpenCV with Qt. The steps are,

  1. Install Qt on your computer (I use Qt4 for all versions of OpenCV since my applications are based on it but you can use Qt5 as well).
  2. Make a note of the install path (for me, it is D:/Qt/4.8.5/ and put it in your Path environment variable.
  3. Open CMake and start the build process for OpenCV. Make sure you select the option WITH_QT under CMAKE.
  4. My CMAKE_INSTALL_PREFIX ss D:/Program Files/opencv and it is there on my Path environment variable`as well; you can change yours accordingly.
  5. Build with other options are required. Generate the files and then build the binaries and install OpenCV in the above mentioned path.
  6. Your OpenCV installation now supports Qt and you can use it inside VS and Qt Creator. For further reference, please head to this link.

HTH

Community
  • 1
  • 1
scap3y
  • 1,188
  • 10
  • 27
1

I had the same problem and resolved it by setting the project to release(bottom left in the qt window) instead of debug and then copying the qt and opencv library into the bin folder. Once you have set your project to build a .exe file will be generated in the bin folder. running that application will tell you what dll is still missing, find the opencv dll's at opencv/build/x64/vc11/bin and the qt ones at Qt/Qt(version)/(version)/(compiler)/bin

~Gibby

Gibby
  • 458
  • 1
  • 4
  • 14
0

Because of the space character.

qmake might consider "D:\Program" and "Files\opencv\build\include" as separated.

Just surround your path with double-quotes.

Guid
  • 2,137
  • 2
  • 20
  • 33