1、下载OpenCV4.5.0源码;下载地址:https://github.com/opencv/opencv/releases
下载opencv_contrib-4.5.0;下载地址:https://github.com/opencv/opencv_contrib
contrib解压好做备用;
2、编译之前修改“C:\Windows\System32\drivers\etc\hosts”文件,添加一行
151.101.108.133 raw.githubusercontent.com
解决GitHub的raw.githubusercontent.com无法连接问题,如图:
3、打开CMake开始编译,配置环境
4、勾选:
“BUILD_opencv_dnn”、“OPENCV_DNN_CUDA”、“OPENCV_DNN_OPENCL”、“BUILD_TBB”;
勾选:“OPENCV_ENABLE_NONFREE”,此处版权选项;
5、取消勾选:
“BUILD_CUDA_STUBS”、“BUILD_EXAMPLES”、“BUILD_JAVA”、“BUILD_opencv_java_bingdings_generator”、“BUILD_PERF_TESTS”、“BUILD_TESTS”、
6、设置MKL_ROOT_DIR,选择安装路径,本机是:C:/CodeTools/intelMKL
7、设置opencv-contrib路径:
设置“OPENCV_EXTRA_MODULES_PATH”,路径为\opencv_contrib-4.5.0\modules,本机为:
8、最终勾选项如下
9、点击“Configure”配置,“Generate”配置;“Open Project”打开项目开始编译;
10、VS2017中,使用批生成,只选择Install即可;
11、编译完成