Difference between revisions of "Install and configure Qt with OpenCV"

From wiki.ferrari.mo.it
Jump to navigation Jump to search
Line 1: Line 1:
 
= Install Qt with OpenCV (Windows 10) =
 
= Install Qt with OpenCV (Windows 10) =
  
Download and install the file
+
1. Download and install the file
  
 
  qt-unified-windows-x86-3.1.1-online.exe
 
  qt-unified-windows-x86-3.1.1-online.exe
Line 10: Line 10:
 
  Qt 5.13.0 64 bit
 
  Qt 5.13.0 64 bit
  
To test the environment, go to File - New File or Project, then select 'Qt Console Application'.
+
2. To test the environment, go to File - New File or Project, then select 'Qt Console Application'.
 
Give it a name, and leave the default build System 'qmake'.
 
Give it a name, and leave the default build System 'qmake'.
  
Line 28: Line 28:
  
 
Click on the debug icon. It should appear a text window with the output.
 
Click on the debug icon. It should appear a text window with the output.
 +
 +
3. Compiler setup
 +
 +
Download and install CMake from cmake.org. During installation, select the option 'Add CMake to the PATH for all users'.
 +
 +
Go to Control Panel - System, and then to 'Advanced System Setting'. Go to the 'Advanced' tab and click on 'Environment Variables'.
 +
Add the MinGW path to the Path variable (in this case, it is C:\Qt\Tools\mingw730_64\bin).
 +
 +
4. Install OpenCV and compile its libraries
 +
 +
Download OpenCV from Sourceforge, then install it (file opencv-4.1.1-vc14_vc15.exe) into the C:\OpenCV\ directory.
 +
 +
Then, go to the CMake directory (C:\Program Files\CMake\bin) and execute cmake-gui.exe.
 +
 +
* Where is the source code: C:/OpenCV/sources
 +
* Where to build the binaries: C:/OpenCV/opencv-build
 +
 +
Click next.
 +
 +
* Specify the generator for this project: MinGW Makefiles
 +
* Specify native compilers
 +
* Compilers C: C:\Qt\Tools\mingw730_64\bin\gcc.exe
 +
* Compilers C++: C:\Qt\Tools\mingw730_64\bin\g++.exe
 +
 +
Click configure for the first time.
 +
 +
Then, a variable list should appear.
 +
 +
* Check the box [X]WITH_QT
 +
* Check the box [X]WITH_OPENGL
 +
 +
Click configure for the second time. If the compiler complains about not finding the Qt5Config.cmake file, add the following variable:
 +
 +
* Qt5_DIR = C:/Qt/5.13.0/mingw73_64/lib/cmake/Qt5
 +
 +
and click configure for the third time.
 +
 +
Some other variables should appear:
 +
 +
* Qt5Concurrent_DIR = C:\Qt\5.13.0\mingw73_64\lib\cmake\Qt5Concurrent
 +
* Qt5Core_DIR = C:\Qt\5.13.0\mingw73_64\lib\cmake\Qt5Core
 +
* Qt5Gui_DIR = C:\Qt\5.13.0\mingw73_64\lib\cmake\Qt5Gui
 +
* Qt5Test_DIR = C:\Qt\5.13.0\mingw73_64\lib\cmake\Qt5Test
 +
* Qt5Widgets_DIR = C:\Qt\5.13.0\mingw73_64\lib\cmake\Qt5Widgets
 +
* Qt5OpenGL_DIR = C:\Qt\5.13.0\mingw73_64\lib\cmake\Qt5OpenGL
 +
 +
and others should be added:
 +
 +
* CMAKE_BUILD_TYPE = Release
 +
* QT_MAKE_EXECUTABLE = C:\Qt\5.13.0\mingw73_64\bin\qmake.exe
 +
* Unckeck the box [ ]ENABLE_PRECOMPILED_HEADERS
 +
 +
then click configure for the fourth time. When finished, click generate.
 +
 +
Then, open a command prompt and, from the C:\OpenCV\opencv-build directory, execute
 +
 +
mingw32-make -j 4
 +
mingw32-make install
 +
 +
Then, copy all the *.dll from C:\OpenCV\opencv-build\bin\ to C:\Qt\5.13.0\mingw73_64\bin\

Revision as of 16:21, 18 August 2019

Install Qt with OpenCV (Windows 10)

1. Download and install the file

qt-unified-windows-x86-3.1.1-online.exe

During installation (or you can restart the installation wizard from the Control Panel - Programs and Functionalities, select the following:

MinGW 7.3.0 64 bit
Qt 5.13.0 64 bit

2. To test the environment, go to File - New File or Project, then select 'Qt Console Application'. Give it a name, and leave the default build System 'qmake'.

In the next screen, deselect the default Kit, and instead, select the previously installed MinGW 7.3.0 64 bit.

Then, modify the main.cpp file in order to have this:

#include <QCoreApplication>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    qDebug() << "Hello World";
    return a.exec();
}

Click on the debug icon. It should appear a text window with the output.

3. Compiler setup

Download and install CMake from cmake.org. During installation, select the option 'Add CMake to the PATH for all users'.

Go to Control Panel - System, and then to 'Advanced System Setting'. Go to the 'Advanced' tab and click on 'Environment Variables'. Add the MinGW path to the Path variable (in this case, it is C:\Qt\Tools\mingw730_64\bin).

4. Install OpenCV and compile its libraries

Download OpenCV from Sourceforge, then install it (file opencv-4.1.1-vc14_vc15.exe) into the C:\OpenCV\ directory.

Then, go to the CMake directory (C:\Program Files\CMake\bin) and execute cmake-gui.exe.

  • Where is the source code: C:/OpenCV/sources
  • Where to build the binaries: C:/OpenCV/opencv-build

Click next.

  • Specify the generator for this project: MinGW Makefiles
  • Specify native compilers
  • Compilers C: C:\Qt\Tools\mingw730_64\bin\gcc.exe
  • Compilers C++: C:\Qt\Tools\mingw730_64\bin\g++.exe

Click configure for the first time.

Then, a variable list should appear.

  • Check the box [X]WITH_QT
  • Check the box [X]WITH_OPENGL

Click configure for the second time. If the compiler complains about not finding the Qt5Config.cmake file, add the following variable:

  • Qt5_DIR = C:/Qt/5.13.0/mingw73_64/lib/cmake/Qt5

and click configure for the third time.

Some other variables should appear:

  • Qt5Concurrent_DIR = C:\Qt\5.13.0\mingw73_64\lib\cmake\Qt5Concurrent
  • Qt5Core_DIR = C:\Qt\5.13.0\mingw73_64\lib\cmake\Qt5Core
  • Qt5Gui_DIR = C:\Qt\5.13.0\mingw73_64\lib\cmake\Qt5Gui
  • Qt5Test_DIR = C:\Qt\5.13.0\mingw73_64\lib\cmake\Qt5Test
  • Qt5Widgets_DIR = C:\Qt\5.13.0\mingw73_64\lib\cmake\Qt5Widgets
  • Qt5OpenGL_DIR = C:\Qt\5.13.0\mingw73_64\lib\cmake\Qt5OpenGL

and others should be added:

  • CMAKE_BUILD_TYPE = Release
  • QT_MAKE_EXECUTABLE = C:\Qt\5.13.0\mingw73_64\bin\qmake.exe
  • Unckeck the box [ ]ENABLE_PRECOMPILED_HEADERS

then click configure for the fourth time. When finished, click generate.

Then, open a command prompt and, from the C:\OpenCV\opencv-build directory, execute

mingw32-make -j 4
mingw32-make install

Then, copy all the *.dll from C:\OpenCV\opencv-build\bin\ to C:\Qt\5.13.0\mingw73_64\bin\