在官网下载opencv-3.4.12.zip和opencv_contrib-3.4.12.zip压缩包,版本需保持一致
分别解压文件到source\opencv-3.4.12 与source\opencv_contrib-3.4.12;
新建build文件夹用于存放cmake生成文件目录,两个目录文件夹不要嵌套
打开cmake目录下的bin\cmake-gui.exe
4.1 分别选择opencv3.4.12源文件目录与build生成目录,然后点Configure,选择自己的编译器版本vs2017和opencv生成库平台,arm或X86或64位,其他默认。等运行结束后会出现一大片红色,先不用管;
4.2 接着,在Search栏搜索排除不必要的模块,jave,test这些都可以取消勾选;
4.3 在OPENCV_EXTRA_MODULES_PATH处输入opencv_contrib-3.4.12/modules的文件夹全路径;
4.4 看一下底部信息栏的提示信息,会有一些红字提示有哪些文件下载失败,查看build/CMakeDownloadLog.txt,打开CMakeDownloadLog.txt文件,里面会提示哪些文件missing,下载失败,以及MD5校验失败等;
//**************************************************************************
#do_copy "opencv_ffmpeg_64.dll" "205db629d893e7d4865fd1459807ff47" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/2a96257b743695a47f8012aab1ffb995a1dee8b4/ffmpeg/opencv_ffmpeg_64.dll" "E:/****/Opencv/build/3rdparty/ffmpeg"
#missing "E:/****/Opencv/build/3rdparty/ffmpeg/opencv_ffmpeg_64.dll"
#check_md5 "E:/****/Opencv/source/opencv-3.4.12/.cache/ffmpeg/205db629d893e7d4865fd1459807ff47-opencv_ffmpeg_64.dll"
#mismatch_md5 "E:/****/Opencv/source/opencv-3.4.12/.cache/ffmpeg/205db629d893e7d4865fd1459807ff47-opencv_ffmpeg_64.dll" "d41d8cd98f00b204e9800998ecf8427e"
#delete "E:/****/Opencv/source/opencv-3.4.12/.cache/ffmpeg/205db629d893e7d4865fd1459807ff47-opencv_ffmpeg_64.dll"
#cmake_download "E:/****/Opencv/source/opencv-3.4.12/.cache/ffmpeg/205db629d893e7d4865fd1459807ff47-opencv_ffmpeg_64.dll" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/2a96257b743695a47f8012aab1ffb995a1dee8b4/ffmpeg/opencv_ffmpeg_64.dll"
#try 1
# timeout on name lookup is not supported
# getaddrinfo(3) failed for raw.githubusercontent.com:443
# Couldn't resolve host 'raw.githubusercontent.com'
# Closing connection 0
//**************************************************************************
缺失的文件都会在source\opencv3.4.12\.cache存在,但是不完整,大小为0;
查看CMakeDownloadLog.txt提示的信息,缺少哪些文件
例如:
missing "E:/****/Opencv/build/3rdparty/ffmpeg/opencv_ffmpeg_64.dll
mismatch_md5 "E:/****/Opencv/source/opencv-3.4.12/.cache/ffmpeg/205db629d893e7d4865fd1459807ff47-opencv_ffmpeg_64.dll"
5.1、打开source\opencv-3.4.12\3rdparty\ffmpeg文件夹对应的缺失文件ffmpeg.cmake,查看文件md5值以及文件版本日期,在github的issues搜索对应日期的文件并下载
# Binaries branch name: ffmpeg/3.4_20200907
# Binaries were created for OpenCV: 03bee14372f5537daa56c62e771ec16181ca1f98
ocv_update(FFMPEG_BINARIES_COMMIT "2a96257b743695a47f8012aab1ffb995a1dee8b4")
ocv_update(FFMPEG_FILE_HASH_BIN32 "5e68a3ff82f43ac6524e50e448a34c9c")
ocv_update(FFMPEG_FILE_HASH_BIN64 "205db629d893e7d4865fd1459807ff47")
ocv_update(FFMPEG_FILE_HASH_CMAKE "3b90f67f4b429e77d3da36698cef700c")
function(download_win_ffmpeg script_var)
set(${script_var} "" PARENT_SCOPE)
set(ids BIN32 BIN64 CMAKE)
set(name_BIN32 "opencv_ffmpeg.dll")
set(name_BIN64 "opencv_ffmpeg_64.dll")
set(name_CMAKE "ffmpeg_version.cmake")
5.2、打开source/opencv-3.4.12/.cache/ffmpeg,会看到大小都是0的文件,将github下载的文件opencv_ffmpeg_64.dll拷贝到此目录,删除大小为0的文件(一个一个操作,先复制名字,再删除源文件,再重命名新文件为原来的文件名),并重命名为源文件205db629d893e7d4865fd1459807ff47-opencv_ffmpeg_64.dll;(命名规则为md5-filename)
5.3、在build/3rdparty目录下查看是否有/ffmpeg目录,没有则手动创建,并将下载的opencv_ffmpeg_64.dll文件拷贝到此目录
5.4、对应CMakeDownloadLog.txt提示的信息,补全缺失文件,重新Configure,即可全部编译成功,然后点Generate即可生成OpenCV.sln,然后就可以使用编译工具编译库文件了;
5.5、BUILD_SHARED_LIBS为全局配置,生成共享库还是静态库
打开OpenCV.sln,右键项目,批生成,分别勾选ALL_BUILD与INSTALL的DEBUG与RELEASE,生成;
程序员的激动时刻,0 error ,0 warning;
生成头文件和库文件在 build\install\目录下,恼火的是需要手动区分debug和release版本;
或者可以根据需要,手动去配置项目属性,比较麻烦就不演示了;
ippicvmt.lib不区分debug与release,其他lib以后缀是否加d区分,如opencv_core3412d.lib为Debug版本,opencv_core3412.lib为Release版本
OpenCV3.4.12&opencv_contrib-3.4.12-C++文档类资源-CSDN文库