QT中用mingw730编译opencv4.0.0(WIN10系统)

QT已安装,在系统环境变量PATH中加入下面路径:
C:\Qt\Tools\mingw730_64\bin\
C:\Qt\5.12.12\mingw73_64\bin\
下载opencv-4.0.0-vc14_vc15.exe解压,https://download.csdn.net/download/wanchengkai/86947474
用cmake选择source、build目录:
configure
选择MinGW Makefiles->Specify native compilers
配置C和C++编译器路径
C:/Qt/Tools/mingw530_32/bin/gcc.exe
C:/Qt/Tools/mingw530_32/bin/g++.exe
勾选 WITH_OPENGL
勾选 WITH_QT
不勾选 WITH_IPP
不勾选 ENABLE_PRECOMPILED_HEADERS
不勾选 WITH_MSMF
configure->generate
进入build目录
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
LIBS += D:\OPENCV4_0\opencv\QT_BUILD\lib\libopencv_*.a


加入opencv_contrib-4.0.0,重新编译了:
QT已安装,在系统环境变量PATH中加入下面路径:
C:\Qt\Tools\mingw730_64\bin\
C:\Qt\5.12.12\mingw73_64\bin\
下载opencv-4.0.0-vc14_vc15.exe解压
用cmake选择source、build目录:
configure
选择MinGW Makefiles->Specify native compilers
配置C和C++编译器路径
C:/Qt/Tools/mingw530_32/bin/gcc.exe
C:/Qt/Tools/mingw530_32/bin/g++.exe
勾选 WITH_OPENGL
勾选 WITH_QT
不勾选 WITH_IPP
不勾选 ENABLE_PRECOMPILED_HEADERS
不勾选 WITH_MSMF
OPENCV_ENABLE_NONFREE 勾上

设置OPENCV_EXTRA_MODULES_PATH -》opencv_contrib-4.0.0/modules

CMAKE BUILD TYPE -> RELEASE

configure->generate
进入build目录
mingw32-make

报错: error: 'FILTER_SCHARR' was not declared in this scope
在文件D:\OPENCV4_0\opencv_contrib-4.0.0\modules\cvv\src\qtutil\filter\sobelfilterwidget.cpp中加入
using namespace cv;
再运行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

(有文件没有下载成功)
网上下载boostdesc_bgm.i等文件,放在D:\OPENCV4_0\opencv_contrib-4.0.0\modules\xfeatures2d\src目录中
再运行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


将opencv/modules/features2d/test/文件下的
test_descriptors_invariance.impl.hpp
test_descriptors_regression.impl.hpp
test_detectors_invariance.impl.hpp
test_detectors_regression.impl.hpp
test_invariance_utils.hpp
拷贝到opencv_contrib-4.0.0/modules/xfeatures2d/test/文件下。

将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

系统环境变量PATH中加入:D:\OPENCV4_0\opencv\QT_BUILD_RELEASE\install\x64\mingw\bin


 

你可能感兴趣的:(opencv,qt)