Using opencv3.1 with Qt5.5 in Windows 10
-
I want to use opencv-3.1 with Qt 5.5 on Windows 10. I read and watched lots of different tutorials but I could not set up it. Actually most of them was for previous version of opencv and qt. Everytime I got problems. Can anyone show me how to setup opencv step by step. Thanks in advance.
-
Hi and welcome to devnet,
What do you mean by "setup OpenCV" ? Build it ? Use it in your Qt project ?
-
Hi and welcome to devnet,
What do you mean by "setup OpenCV" ? Build it ? Use it in your Qt project ?
-
What exact problem do you have currently ?
-
Ok let me say what I did so far;
- First I extracted opencv3.1 to directory C:\opencv2. Therefore initially there was two folders in this directory namely "source" and "build". Then I created a new folder named "release".
- To build libraries I used C make 3.4.3. I selected "C:/opencv2/sources" as a source directory and selected "C:/opencv2/release" to build binaries.
- I clicked "Configure" and selected "MinGW Makefiles" as generetor and selected "Specify native compilers". Then I selected "C:/Qt/Tools/mingw491_32/bin/gcc.exe" as the C compiler and "C:/Qt/Tools/mingw491_32/bin/g++.exe" as the C++ compiler. (By the way I am using Qt 5.4)
- I did not change any other options and clicked configure till all red lines disappear. Next I clicked "generate" and closed Cmake gui.
5)Then I opened CMD window I opened the directory C:\opencv2\release and I typed "mingw32-make", it took about 30 minutes. Then I typed "mingw32-make install" .
System variables that I added is shown in the picture.
http://i.hizliresim.com/v5LnJr.png6)Then I created Qt console application and I added these to .pro file
INCLUDEPATH += C:\opencv2\release\install\include LIBS += -LC:\\opencv2\\release\\install\\x86\\mingw\\bin\ libopencv_core310 \ libopencv_highgui310 \ libopencv_imgproc310 \ libopencv_features2d310 \ libopencv_calib3d310 \ Then I clicked "run qmake"
In the source file
#include <QCoreApplication> #include <opencv2/opencv.hpp> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); return a.exec(); }
But I get the error,
error: LNK1104: cannot open file 'libopencv_core310.obj' -
Ok let me say what I did so far;
- First I extracted opencv3.1 to directory C:\opencv2. Therefore initially there was two folders in this directory namely "source" and "build". Then I created a new folder named "release".
- To build libraries I used C make 3.4.3. I selected "C:/opencv2/sources" as a source directory and selected "C:/opencv2/release" to build binaries.
- I clicked "Configure" and selected "MinGW Makefiles" as generetor and selected "Specify native compilers". Then I selected "C:/Qt/Tools/mingw491_32/bin/gcc.exe" as the C compiler and "C:/Qt/Tools/mingw491_32/bin/g++.exe" as the C++ compiler. (By the way I am using Qt 5.4)
- I did not change any other options and clicked configure till all red lines disappear. Next I clicked "generate" and closed Cmake gui.
5)Then I opened CMD window I opened the directory C:\opencv2\release and I typed "mingw32-make", it took about 30 minutes. Then I typed "mingw32-make install" .
System variables that I added is shown in the picture.
http://i.hizliresim.com/v5LnJr.png6)Then I created Qt console application and I added these to .pro file
INCLUDEPATH += C:\opencv2\release\install\include LIBS += -LC:\\opencv2\\release\\install\\x86\\mingw\\bin\ libopencv_core310 \ libopencv_highgui310 \ libopencv_imgproc310 \ libopencv_features2d310 \ libopencv_calib3d310 \ Then I clicked "run qmake"
In the source file
#include <QCoreApplication> #include <opencv2/opencv.hpp> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); return a.exec(); }
But I get the error,
error: LNK1104: cannot open file 'libopencv_core310.obj'@brotify This should be changed:
LIBS += -LC:\\opencv2\\release\\install\\x86\\mingw\\bin\ libopencv_core310 \ libopencv_highgui310 \ libopencv_imgproc310 \ libopencv_features2d310 \ libopencv_calib3d310 \
to:
LIBS += -LC:/opencv2/release/install/x86/mingw/bin\ -lopencv_core310 \ -lopencv_highgui310 \ -lopencv_imgproc310 \ -lopencv_features2d310 \ -lopencv_calib3d310 \
In pro files you should use forward slashes in paths and not back slashes (even on Windows).
Are the libraries directly in C:\opencv2\release\install\x86\mingw\bin? -
@brotify This should be changed:
LIBS += -LC:\\opencv2\\release\\install\\x86\\mingw\\bin\ libopencv_core310 \ libopencv_highgui310 \ libopencv_imgproc310 \ libopencv_features2d310 \ libopencv_calib3d310 \
to:
LIBS += -LC:/opencv2/release/install/x86/mingw/bin\ -lopencv_core310 \ -lopencv_highgui310 \ -lopencv_imgproc310 \ -lopencv_features2d310 \ -lopencv_calib3d310 \
In pro files you should use forward slashes in paths and not back slashes (even on Windows).
Are the libraries directly in C:\opencv2\release\install\x86\mingw\bin?INCLUDEPATH += C:\opencv2\release\install\include LIBS += -LC:/opencv2/release/install/x86/mingw/bin\ -lopencv_core310 \ -lopencv_highgui310 \ -lopencv_imgproc310 \ -lopencv_features2d310 \ -lopencv_calib3d310 \
INCLUDEPATH += C:/opencv2/release/install/include LIBS += -LC:/opencv2/release/install/x86/mingw/bin\ -lopencv_core310 \ -lopencv_highgui310 \ -lopencv_imgproc310 \ -lopencv_features2d310 \ -lopencv_calib3d310 \
I tried both of them but this time I get this error:
LNK1104: cannot open file 'opencv_core310.lib'Let me show the screenshot of what is inside "C:\opencv2\release\install\x86\mingw\bin"
http://i.hizliresim.com/0nkDAY.png -
Hi. You have to build OpenCV with MinGW only if you want to use Qt on Windows builded with MinGW.
The OpenCV package already has the vs libraries.
Anyway which are your cmake switches?@mrdebug
I have to say that I am not experienced developer. Therefore I did not fully understand what are saying. I used Mingw because in the tutorials thay were using Cmake and Mingw. If there are another method to use opencv in Qt project, it will be good to me to know. -
Sorry but all the tutorials that I have tried in order to to use OpenCV in all platforms are not perfectly usable. To setup OpenCV with Qt is more difficult than to write a OpenCV program.
To start: what qt version are you using? The Qt version based on mingw32 or the version based on vc? -
INCLUDEPATH += C:\opencv2\release\install\include LIBS += -LC:/opencv2/release/install/x86/mingw/bin\ -lopencv_core310 \ -lopencv_highgui310 \ -lopencv_imgproc310 \ -lopencv_features2d310 \ -lopencv_calib3d310 \
INCLUDEPATH += C:/opencv2/release/install/include LIBS += -LC:/opencv2/release/install/x86/mingw/bin\ -lopencv_core310 \ -lopencv_highgui310 \ -lopencv_imgproc310 \ -lopencv_features2d310 \ -lopencv_calib3d310 \
I tried both of them but this time I get this error:
LNK1104: cannot open file 'opencv_core310.lib'Let me show the screenshot of what is inside "C:\opencv2\release\install\x86\mingw\bin"
http://i.hizliresim.com/0nkDAY.png -
It seems like you are trying to use OpenCV built using MinGW with Qt built with Visual Studio. There are two things you can do.
-
use OpenCV pre built. Which is in your build folder of OpenCV downloaded zip
-
change the kit in your Qt Creator to use MinGW build of Qt.
Hope this helps
-
-
It seems like you are trying to use OpenCV built using MinGW with Qt built with Visual Studio. There are two things you can do.
-
use OpenCV pre built. Which is in your build folder of OpenCV downloaded zip
-
change the kit in your Qt Creator to use MinGW build of Qt.
Hope this helps
Please note that I have solved my problem but I will not delete this post because it may help other people.
@asanka424
Thanks, I selected Mingw32 as the kit and it worked but this time I get a different error. I tried a simple opencv program which shows the image however it gives this error:
undefined reference to `cv::imread(cv::String const&, int)'Here is my code,
#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace cv; using namespace std; int main( ) { Mat image; image = imread("img.jpg", CV_LOAD_IMAGE_COLOR); if(! image.data ) { cout << "Could not open or find the image" << std::endl ; return -1; } namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display. imshow( "Display window", image ); waitKey(0); return 0; }
and here is my .pro file
QT += core QT -= gui CONFIG += c++11 TARGET = untitled CONFIG += console CONFIG -= app_bundle INCLUDEPATH += C:/opencv2/release/install/include LIBS += -LC:/opencv2/release/install/x86/mingw/bin\ -lopencv_core310 \ -lopencv_highgui310 \ -lopencv_imgproc310 \ -lopencv_features2d310 \ -lopencv_calib3d310 \ TEMPLATE = app SOURCES += main.cpp
And lastly can you show me how to use first method that is using opencv pre-built?
-
-
Sorry but all the tutorials that I have tried in order to to use OpenCV in all platforms are not perfectly usable. To setup OpenCV with Qt is more difficult than to write a OpenCV program.
To start: what qt version are you using? The Qt version based on mingw32 or the version based on vc? -
Hello
I am also in a same situation, i did not find any solution till now.
I am using Qt creator 5.5 with mingw492_32 and openCv 3.10 with VC.
When i try to write a small code to read the image matrix usingcv::imread()
it gives me error.error: undefined reference to `cv::imread(cv::String const&, int)
this is my
test.pro
QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = Test TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp HEADERS += mainwindow.h FORMS += mainwindow.ui INCLUDEPATH += LC:\opencv\build\include LIBS += C:\opencv\build\x64\vc14\lib\opencv_world310.lib \ C:\opencv\build\bin\opencv_ffmpeg310.dll
i have only one library file in the openCV folder
Do you have any idea what i am suppose to do? -
Hi.
You can't use the vc libraries of OpenCV with Qt built with Mingw. If you want to use Qt with mingw you have to build OpenCV with Mingw.
I confirm Qt 5.5 works perfectly with OpenCV 3.
http://www.denisgottardello.it/ComputerVisionStudio/index.php -
Is there any link which explains perfect installation of OpenCV 3 and Qt5.5?
-
These lines of code work perfectly with Qt 5.5.0 and OpenCV 3.0
set PATH=%PATH%;C:\Qt\Qt5.5.0\Tools\mingw492_32\bin;C:\Program Files (x86)\CMake 2.8\bin
cmake -G "MinGW Makefiles" -DWITH_FFMPEG=OFF -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_opencv_videoio=ON -DWITH_IPP=OFF -DWITH_OPENCL=OFF -DWITH_JASPER=OFF -DWITH_OPENEXR=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DOPENCV_EXTRA_MODULES_PATH=modules/opencv_contrib-master/modules .mingw32-make -j 4
I have only some problems with webcams in some 64 bit machines.
Another hard problem is to setup the pro file. You have to include the libraries in a particular order (depends from your program). Some libraries can be included more than one time.
This solution sounds to be very strange but I assure, to have OpenCV working I have spent a lot of time.If you need professional support please send me an email at info@denisgottardello.it
-
These lines of code work perfectly with Qt 5.5.0 and OpenCV 3.0
set PATH=%PATH%;C:\Qt\Qt5.5.0\Tools\mingw492_32\bin;C:\Program Files (x86)\CMake 2.8\bin
cmake -G "MinGW Makefiles" -DWITH_FFMPEG=OFF -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_opencv_videoio=ON -DWITH_IPP=OFF -DWITH_OPENCL=OFF -DWITH_JASPER=OFF -DWITH_OPENEXR=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DOPENCV_EXTRA_MODULES_PATH=modules/opencv_contrib-master/modules .mingw32-make -j 4
I have only some problems with webcams in some 64 bit machines.
Another hard problem is to setup the pro file. You have to include the libraries in a particular order (depends from your program). Some libraries can be included more than one time.
This solution sounds to be very strange but I assure, to have OpenCV working I have spent a lot of time.If you need professional support please send me an email at info@denisgottardello.it
@mrdebug
I seriously did not understand from 3rd line (cmake).I set the paths of Qt and CMake
Below are my paths
C:\Qt\5.5\mingw492_32\bin
C:\CMake\bin
I don't understand what I have to do in CMake?
Can you say me any step by step procedure or any other way?