Qt & OpenCV development environment construction


Preliminary preparation:
Download cmake, install it and configure the bin directory environment variables
Download opencv source code

1. Install Qt

Download address: https://download.qt.io/archive/qt/5.14/5.14.2/
or download: mirror address University of Science and Technology of China , Tsinghua University , Beijing Institute of Technology , China Internet Network Information Center
Installation options: (Install It takes about 6G) to
insert image description here
configure the Qt system environment variables:
E:\Qt\Qt5.14.2\5.14.2\mingw73_64\bin
E:\Qt\Qt5.14.2\Tools\mingw730_64\bin

Second, compile opencv

And compile:
1. Click Configure [Configure download encountered problems view] to handle all download problems until completion
insert image description here
, compile the opencv452 extension again, error handling:
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
check Advanced For variables: set CMAKE_MAKE_PROGRAM to mingw32-make.exe in the QT directory.
insert image description here

2. Modify the following configuration: (using Search)

Options
WITH_OPENGL (selected)
WITH_QT (selected)
WITH_IPP (unselected)
OPENCV_ENABLE_ALLOCATOR_STATS (unselected, otherwise a compilation error will be reported)
OPENCV_GENERATE_SETUPVARS (unselected)
Additional: Because of writing C++, bind java, python, js related (such as: BUILD_opencv_python3, etc.) Generate all unchecked.

3. After clicking Configure, modify the related configuration of Qt as follows: Configure again, after no error is reported, click Generate (as shown below)
insert image description here

The content is as follows:

E:\Qt\Qt5.14.2\5.14.2\mingw73_64\lib\cmake\Qt5
E:\Qt\Qt5.14.2\5.14.2\mingw73_64\lib\cmake\Qt5Concurrent
E:\Qt\Qt5.14.2\5.14.2\mingw73_64\lib\cmake\Qt5Core
E:\Qt\Qt5.14.2\5.14.2\mingw73_64\lib\cmake\Qt5Gui
E:\Qt\Qt5.14.2\5.14.2\mingw73_64\lib\cmake\Qt5OpenGL
E:\Qt\Qt5.14.2\5.14.2\mingw73_64\lib\cmake\Qt5Test
E:\Qt\Qt5.14.2\5.14.2\mingw73_64\lib\cmake\Qt5Widgets

The generated file directory is as follows: (Partial screenshot)
insert image description here
Open the terminal in this folder to execute compilation and installation:
Compile and mingw32-make -j 8
installmingw32-make install

The screenshots of the compilation part are as follows: The
insert image description here
screenshots of the installation part are as follows:
insert image description here

Error report: gcc: error: long: No such file or directory
Error solution: Uncheck OPENCV_ENABLE_ALLOCATOR_STATS in CMake
At this point, the compilation and installation are completed, and the installation directory is: E:\opencv3\opencv\sources\build\install.

3. Test

1. Configure opencv environment variables:
E:\opencv3\opencv\sources\build\install\x64\mingw\bin
2. Create a new Qt project and configure it

INCLUDEPATH += E:\opencv3\opencv\sources\build\install\include\
               E:\opencv3\opencv\sources\build\install\include\opencv2\
               E:\opencv3\opencv\sources\build\install\include\opencv

LIBS += -L E:\opencv3\opencv\sources\build\install\x64\mingw\lib\libopencv_*.a

*.pro file
insert image description here
test
insert image description here

Reference:
opencv452 error reporting solution: https://blog.csdn.net/cchmsn/article/details/118642433
https://blog.csdn.net/coolermzb3/article/details/116278830

https://blog.csdn.net/qq_42564908/article/details/108750807
https://blog.csdn.net/Mr_robot_strange/article/details/110677323

Error: mingw32-make[2]: *** [modules\hdf\CMakeFiles\opencv_hdf.dir\build.make:125: bin/libopencv_hdf452.dll] Error 1
After looking for a long time, I found that the environment variables of Anaconda need to be blocked.

Guess you like

Origin blog.csdn.net/wsp_1138886114/article/details/122688381