How to use OpenCV inside QtCreator?
-
wrote on 18 Mar 2016, 11:39 last edited by Beriol
Hi guys.
I've been trying to make the OpenCV library to work with QtCreator the last couple of days, but I can't make it work.
I've looked at a bunch of guides around the web, and tried each of them several times, but still nothing. Some guides use older versions of OpenCV, so I tried and use those versions, but it didn't work.
All guides pretty much follow the steps reported here: https://zahidhasan.wordpress.com/2014/08/19/qt-5-3-1-64-bit-mingw-windows/
The steps are basically to use CMake to build the OpenCV library (adding the option WITH_QT while doing it), install it, and then link the library to the QtProject.
Although the part with CMake works a little different for me, meaning that it gives me some errors saying that it can't find some folders related to Qt (even though it points exactly where the directories are... which is odd), it still works and I manage to build the library and get the dll files.
But when I try creating a simple project in QtCreator, nothing seems to work.
As of right now, I'm using QtCreator 3.0.1 based on Qt 5.2.1 and OpenCV 2.4.9.
Basically the code is simply this:
#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> int main() { cv::namedWindow("My Image"); return 1; }
So nothing really, it just uses a random OpenCV function.
The .pro file is like this:
QT += core QT -= gui TARGET = OpenCV CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp INCLUDEPATH += D:\Development\opencv-mingw\install\include LIBS += D:\Development\opencv-mingw\install\x64\mingw\bin\libopencv_core249.dll \ D:\Development\opencv-mingw\install\x64\mingw\bin\libopencv_highgui249.dll \ D:\Development\opencv-mingw\install\x64\mingw\bin\libopencv_imgproc249.dll \ D:\Development\opencv-mingw\install\x64\mingw\bin\libopencv_features2d249.dll \ D:\Development\opencv-mingw\install\x64\mingw\bin\libopencv_calib3d249.dll
The paths are alright, the code compiles. But it crashes at startup without giving any errors. If I try using the debugger, it does the same but it also gives me an error:
"An exception was triggered:
Exception at 0x77018f05, code: 0xc000007b; flags=0x0.
During startup program exited with code 0xc000007b."So probably the problem is that it can't find the dlls. But I checked and re-checked, they ARE there, and I added the paths to the system PATH variable, as you can see in this screenshot: http://imgur.com/aYrVkei
So, I'm out of ideas. Can you guys help me linking the libraries? Or maybe there is another problem?
-
Hi,
Aren't you providing the path to a 64bit version of OpenCV while using a 32bit Qt ?
On a side note, you shouldn't link to .dll files but to .lib files.
-
wrote on 18 Mar 2016, 13:38 last edited by
Hei even i tried to follow the instructions from the same link which you attached. In the Cmake i am getting errors after i select c and c++ compilers and enter finish
Error in configuration process, project files may be invalid
Do you know what to do?
-
Hi,
Aren't you providing the path to a 64bit version of OpenCV while using a 32bit Qt ?
On a side note, you shouldn't link to .dll files but to .lib files.
wrote on 18 Mar 2016, 14:14 last edited byDamn, you're right. How did I not see that?
I built the libraries again using the right mingw compiler and now it seems to be working! Thanks a lot! :D
About the .lib files, there are none in the library. Or at least none I could find, only dll.
From what I've seen it's kind of normal for Cmake to throw some errors here and there. If you try hitting the configure botton again what happens?
-
You're welcome !
Late night debugging can have that kind of effect ;)
Since you have it working now, please mark the thread as solved using the "Topic Tool" button so that other forum users may know a solution has been found :)
-
Damn, you're right. How did I not see that?
I built the libraries again using the right mingw compiler and now it seems to be working! Thanks a lot! :D
About the .lib files, there are none in the library. Or at least none I could find, only dll.
From what I've seen it's kind of normal for Cmake to throw some errors here and there. If you try hitting the configure botton again what happens?
wrote on 18 Mar 2016, 23:32 last edited by@Beriol its the same error again and again
can you write in brief what all you have done, it will be much useful for me and others who are trying it for first time. -
@Beriol its the same error again and again
can you write in brief what all you have done, it will be much useful for me and others who are trying it for first time.wrote on 19 Mar 2016, 12:10 last edited byI followed exactly the guide I posted in the first post. For me the hard part was actually linking the libraries, not building them.
Are you sure you selected the right compilers? The path should be something like:
C:\YourPathToQT\Qt\Tools\mingw48_32\bin\gcc.exe <-- for C
C:\YourPathToQT\Qt\Tools\mingw48_32\bin\g++.exe <-- for C++In my case inside the "Tools" folder there is also a folder called MinGW which also contain the bin with the compilers, but do NOT use that (which was my mistake).
Besides this, did you add the path to CMake to your system PATH variable and restarted the computer?
-
I followed exactly the guide I posted in the first post. For me the hard part was actually linking the libraries, not building them.
Are you sure you selected the right compilers? The path should be something like:
C:\YourPathToQT\Qt\Tools\mingw48_32\bin\gcc.exe <-- for C
C:\YourPathToQT\Qt\Tools\mingw48_32\bin\g++.exe <-- for C++In my case inside the "Tools" folder there is also a folder called MinGW which also contain the bin with the compilers, but do NOT use that (which was my mistake).
Besides this, did you add the path to CMake to your system PATH variable and restarted the computer?
wrote on 20 Mar 2016, 13:16 last edited by@Beriol
I downloaded and extracted openCV. Later installed Qt. Added the directories
C:\Qt\5.5\mingw492_32\bin
C:\opencv\build\x86\vc12\bin
to the path in Environment variables.Later downloaded CMake and installed it and added its path
C:\CMake\bin
Created an empty folder opencv-mingw in C-DriveRebooted Laptop
In CMake i selected
the sourcecode Directory asC:\Qt\Tools\mingw492_32\bin
(also tried withC:\Qt\5.5\mingw492_32\bin
)
Buid the binary inC:/opencv-mingw
and hit configure buttonSelected MinGW Makefiles from dropdown menu. Then it asked to specify native compilers
SpecifiedC:/Qt/Tools/mingw491_32/bin/gcc.exe
for C
specifiedC:/Qt/Tools/mingw491_32/bin/g++.exe
for C++
and hit finishIT GAVE ME ERROR
Error in configuration process, Project files may be invalid -
@Beriol
I downloaded and extracted openCV. Later installed Qt. Added the directories
C:\Qt\5.5\mingw492_32\bin
C:\opencv\build\x86\vc12\bin
to the path in Environment variables.Later downloaded CMake and installed it and added its path
C:\CMake\bin
Created an empty folder opencv-mingw in C-DriveRebooted Laptop
In CMake i selected
the sourcecode Directory asC:\Qt\Tools\mingw492_32\bin
(also tried withC:\Qt\5.5\mingw492_32\bin
)
Buid the binary inC:/opencv-mingw
and hit configure buttonSelected MinGW Makefiles from dropdown menu. Then it asked to specify native compilers
SpecifiedC:/Qt/Tools/mingw491_32/bin/gcc.exe
for C
specifiedC:/Qt/Tools/mingw491_32/bin/g++.exe
for C++
and hit finishIT GAVE ME ERROR
Error in configuration process, Project files may be invalidwrote on 20 Mar 2016, 18:44 last edited byThe "sourcecode directory" inside CMake should point to the folder that contains the source code for OpenCV, not the folder that contains compiler executables like the one you're using!
So, you should put the path to the folder where you extracted the OpenCV stuff. Something like "C:/opencv/sources". That's why you're getting the error at start, there are no source files to configure :)
-
The "sourcecode directory" inside CMake should point to the folder that contains the source code for OpenCV, not the folder that contains compiler executables like the one you're using!
So, you should put the path to the folder where you extracted the OpenCV stuff. Something like "C:/opencv/sources". That's why you're getting the error at start, there are no source files to configure :)
wrote on 21 Mar 2016, 10:05 last edited by@Beriol Oh yes, thanks for the that
It was my silly mistake... It is working and I have generated the compilers in Cmake.But in Command prompt after entering
mingw32–make
,
I was left with errors at 31%, I referred the comments in the link and uncheckedWITH_IPP
and regenerated in Cmake.But this time I was a getting errors at 37% in Command prompt.
makefile: 148: recipe for target 'all' failed mingw32-make: ***[all] Error 2
Do you know anything about this?
-
@Beriol Oh yes, thanks for the that
It was my silly mistake... It is working and I have generated the compilers in Cmake.But in Command prompt after entering
mingw32–make
,
I was left with errors at 31%, I referred the comments in the link and uncheckedWITH_IPP
and regenerated in Cmake.But this time I was a getting errors at 37% in Command prompt.
makefile: 148: recipe for target 'all' failed mingw32-make: ***[all] Error 2
Do you know anything about this?
wrote on 21 Mar 2016, 10:39 last edited byIt happened to me too, but I don't remember what exactly fixxed that problem.
Try this: in CMake tick the option "Advanced" (it's on the right after the search bar), and search for CMAKE__MAKE_PROGRAM; make sure that it points to the mingw32-make.exe inside you Qt folder "C:\Qt\Tools\mingw492_32\bin\mingw32-make.exe". I remember that in my case it wasn't set right and I used to get errors because of that.
Besides this I'm not sure what else you could do... Did you check "WITH_QT"?
Also, try unchecking "WITH_CUDA". I remember reading somewhere that it might give problems, but I actually don't remember if it gave me any while building.
1/11