Compile opencv4.0.0 with mingw730 in QT (WIN10 system)

QT has been installed, add the following path to the system environment variable PATH:
C:\Qt\Tools\mingw730_64\bin\
C:\Qt\5.12.12\mingw73_64\bin\
Download opencv-4.0.0-vc14_vc15.exe to unzip, https://download.csdn.net/download/wanchengkai/86947474
Use cmake to select source and build directories:
configure
select MinGW Makefiles->Specify native compilers
configure C and C++ compiler path
C:/Qt/Tools/mingw530_32/bin/ gcc.exe
C:/Qt/Tools/mingw530_32/bin/g++.exe
check WITH_OPENGL
check WITH_QT
uncheck WITH_IPP uncheck
ENABLE_PRECOMPILED_HEADERS uncheck
WITH_MSMF
configure->generate
enter build directory
mingw32-make
mingw32-make install

At the bottom of QT's .pro file, add the following content
INCLUDEPATH+=D:\OPENCV4_0\opencv\build\include
             D:\OPENCV4_0\opencv\build\include\opencv
             D:\OPENCV4_0\opencv\build\include\opencv2
LIBS + = D:\OPENCV4_0\opencv\QT_BUILD\lib\libopencv_*.a


Add opencv_contrib-4.0.0, recompile:
QT has been installed, add the following path to the system environment variable PATH:
C:\Qt\Tools\mingw730_64\bin\
C:\Qt\5.12.12\mingw73_64\bin\
Download opencv-4.0.0-vc14_vc15.exe decompression
Use cmake to select source and build directories:
configure
select MinGW Makefiles->Specify native compilers
configure C and C++ compiler path
C:/Qt/Tools/mingw530_32/bin/gcc.exe
C: /Qt/Tools/mingw530_32/bin/g++.exe
check WITH_OPENGL
check WITH_QT
uncheck WITH_IPP
uncheck ENABLE_PRECOMPILED_HEADERS
uncheck WITH_MSMF
OPENCV_ENABLE_NONFREE check

设置OPENCV_EXTRA_MODULES_PATH -》opencv_contrib-4.0.0/modules

CMAKE BUILD TYPE -> RELEASE

configure->generate
into the build directory
mingw32-make

Error: error: 'FILTER_SCHARR' was not declared in this scope Add using namespace cv
to the file D:\OPENCV4_0\opencv_contrib-4.0.0\modules\cvv\src\qtutil\filter\sobelfilterwidget.cpp ; then run mingw32-make

再报错
[ 83%] Building CXX object modules/xfeatures2d/CMakeFiles/opencv_xfeatures2d.dir/src/boostdesc.cpp.obj
D:\OPENCV4_0\opencv_contrib-4.0.0\modules\xfeatures2d\src\boostdesc.cpp:653:20: fatal error: boostdesc_bgm.i: No such file or directory
           #include "boostdesc_bgm.i"
                    ^~~~~~~~~~~~~~~~~
compilation terminated.
mingw32-make[2]: *** [modules\xfeatures2d\CMakeFiles\opencv_xfeatures2d.dir\build.make:101: modules/xfeatures2d/CMakeFiles/opencv_xfeatures2d.dir/src/boostdesc.cpp.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:6449: modules/xfeatures2d/CMakeFiles/opencv_xfeatures2d.dir/all] Error 2
mingw32-make: *** [Makefile:181: all] Error 2

(There are files that have not been downloaded successfully)
Download boostdesc_bgm.i and other files from the Internet, put them in the D:\OPENCV4_0\opencv_contrib-4.0.0\modules\xfeatures2d\src directory
and then run mingw32-make

[ 85%] Building CXX object modules/xfeatures2d/CMakeFiles/opencv_test_xfeatures2d.dir/test/test_features2d.cpp.obj
D:\OPENCV4_0\opencv_contrib-4.0.0\modules\xfeatures2d\test\test_features2d.cpp:51:10: fatal error: features2d/test/test_detectors_regression.impl.hpp: No such file or directory
 #include "features2d/test/test_detectors_regression.impl.hpp"
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
mingw32-make[2]: *** [modules\xfeatures2d\CMakeFiles\opencv_test_xfeatures2d.dir\build.make:96: modules/xfeatures2d/CMakeFiles/opencv_test_xfeatures2d.dir/test/test_features2d.cpp.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:6487: modules/xfeatures2d/CMakeFiles/opencv_test_xfeatures2d.dir/all] Error 2
mingw32-make: *** [Makefile:181: all] Error 2



Copy test_descriptors_invariance.impl.hpp test_descriptors_regression.impl.hpp
test_detectors_invariance.impl.hpp
test_detectors_regression.impl.hpp
test_invariance_utils.hpp under the opencv/modules/features2d/test/
file
to opencv_contrib-4.0.0/modules/ xfeatures2d/test/files Down.

将opencv_contrib-4.0.0/modules/xfeatures2d/test/test_features2d.cpp文件下的
#include "features2d/test/test_detectors_regression.impl.hpp"
#include "features2d/test/test_descriptors_regression.impl.hpp"
改成:
#include "test_detectors_regression.impl.hpp"
#include "test_descriptors_regression.impl.hpp"
将opencv_contrib-4.0.0/modules/xfeatures2d/test/test_rotation_and_scale_invariance.cpp文件下的
#include "features2d/test/test_detectors_invariance.impl.hpp"
#include "features2d/test/test_descriptors_invariance.impl.hpp"
改成:
#include "test_detectors_invariance.impl.hpp"
#include "test_descriptors_invariance.impl.hpp"
mingw32-make

mingw32-make install

在QT的.pro文件中底部,添加如下内容
INCLUDEPATH+=D:\OPENCV4_0\opencv\build\include \
             D:\OPENCV4_0\opencv\build\include\opencv \
             D:\OPENCV4_0\opencv\build\include\opencv2 \
             D:\OPENCV4_0\opencv_contrib-4.0.0\modules\xfeatures2d\include\opencv2 \
#LIBS += D:\OPENCV4_0\opencv\QT_BUILD_RELEASE\lib\libopencv_*.a
LIBS += D:\OPENCV4_0\opencv\QT_BUILD_RELEASE\install\x64\mingw\lib\libopencv_*.a

Add to the system environment variable PATH: D:\OPENCV4_0\opencv\QT_BUILD_RELEASE\install\x64\mingw\bin


 

Guess you like

Origin blog.csdn.net/wanchengkai/article/details/123989334