How to setup Qt and openCV on Windows
Jump to Cmake - Download cmake from cmake.org. In this guide, 3.7.2 is used. Start cmake-3.7.2-win64-x64.msi, then choose the following settinge.
- 2Windows 10, Qt 5.9, OpenCV 3.2.0
Introduction
This article shows how to install Qt, build OpenCV, and run a basic OpenCV example. This article assumes Windows 10 has just been installed.
This procedure requires close to 10GB of disk space:
This article uses information from the following pages:http://docs.opencv.org/2.4/doc/tutorials/introduction/windows_install/windows_install.html?highlight=installationhttp://www.laganiere.name/opencvCookbook/chap1s1_2.shtml
Windows 10, Qt 5.9, OpenCV 3.2.0
This guide is actual for Qt 5.12.2 with MinGW 7.3.0 and OpenCV 4.0.1 too
Qt
Installation
Download the Qt installer from www.qt.io, then choose 'Download now'. This will then download qt-unified-windows-x86-2.0.5-online.exe. Execute the program, then choose the following settings:
Testing
Run D:QtToolsQtCreatorbinqtcreator.exe
Now a new project is made. Start debugging by choosing
Now the Qt tab in the Windows taskbar should turn into a progress bar. After some time a new empty window should pop up. Stop debugging either by pressing the red cross in the top right of this new window, or choose
Adjust Qt
When you need to add, remove or update a component of Qt, this can be done by running D:QtMaintenanceTool.exe:
Tortoisegit
Todo
Cmake
Download cmake from cmake.org. In this guide, 3.7.2 is used. Start cmake-3.7.2-win64-x64.msi, then choose the following settinge:
OpenCV
Getting OpenCV
Download openCV from sourceforge. In this guide, version 3.2.0 is used. Start opencv-3.2.0-vc14.exe and let it extract to d: . Now the folder d:opencv is created.
Add minGW to the windows PATH variable
Compiling OpenCV
Start C:Program FilesCMakebincmake-gui.exe then choose the following settings:
Then click Configure, let cmake create the build directory, and choose the following settings:
Then click configure again
Then click configure againThen click generate
Next open cmd, and type the following commands. To speed up the compile, the -j flag can be used to run multiple compile jobs simultaneously. On an 8 core CPU, you can set it to 8 or higher, so all cores are used. On a core [email protected] with 8GB ram, the compile takes about 6 minutes.
If you have the following error : ... windres.exe: unknown option -- W ...
try this : in cmake uncheck ENABLE_PRECOMPILED_HEADERS
If, in the file opencv/sources/modules/videoio/src/cap_dshow.cpp, you have the following error : 'sprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA' was not declared in this scope ...
try this :put the following line: #define NO_DSHOW_STRSAFE, before the line : #include 'DShow.h'
If you have the error: ‘nullptr’ was not declared in this scope..
try this: in cmake check the box ENABLE_CXX11
If, in the file modulesvideoiosrccap_msmf.cpp you have the error: using invalid field '{anonymous}::ComPtr<T>::p'..
try this: in cmake unchecking WITH_MSMF
![Download Download](https://img-blog.csdnimg.cn/20181029153615802.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2dybGxlcnk=,size_27,color_FFFFFF,t_70)
Add OpenCV compiled libraries to the windows PATH variable
Compile and run the example
Run D:QtToolsQtCreatorbinqtcreator.exe
Now a new project is made.
modify the .pro file like this:
and modify mainwindow.cpp like this:
Place an image with the name '1.img' in the root of F:, then run the example. Now 2 windows should pop up. One with the image, and one with an empty window.