win10下编译opencv其实也不复杂,准备工具:
1. cmake-3.19.2
2. opencv源码4.5.1
3.opencv-contrib源码4.5.1
4.opencv-thirdpart, 最新版
其他的依赖,这里一笔带过,能多准备就多准备把。
这里只说ffmpeg和ippcv.
第一个拉仇恨的是ffmpeg。
这里只说关键点:
1. 在源码中找到 D:\win10\opencv400\opencv\sources\3rdparty\ffmpeg\ffmpeg.cmake 文件
看到第一行的编号,到opencv-thirdpart项目中把它checkout出来;
核对 FFMPEG_FILE_HASH_CMAKE 是否一致,如果不一致,修改D:\win10\opencv400\opencv\sources\3rdparty\ffmpeg\ffmpeg.cmake 文件
然后,修改为大致如下的结果:
# Binaries branch name: ffmpeg/master_20181106 # Binaries were created for OpenCV: 2c6f1ab57d4250ee46e32d1b51c056431965b470 ocv_update(FFMPEG_BINARIES_COMMIT "759a23e24ab787a0979f8a93103dcc3105ec10c1") ocv_update(FFMPEG_FILE_HASH_BIN32 "849286ccc527c99e5a218b67f13c6e8c") ocv_update(FFMPEG_FILE_HASH_BIN64 "96444a4645753aaafa296479665c9185") ocv_update(FFMPEG_FILE_HASH_CMAKE "f710891525a04586d565d0e700e62a9c") 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") set(FFMPEG_DOWNLOAD_DIR "${OpenCV_BINARY_DIR}/3rdparty/ffmpeg") set(status TRUE) foreach(id ${ids}) if( 0 ) ocv_download(FILENAME ${name_${id}} HASH ${FFMPEG_FILE_HASH_${id}} URL "$ENV{OPENCV_FFMPEG_URL}" "${OPENCV_FFMPEG_URL}" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${FFMPEG_BINARIES_COMMIT}/ffmpeg/" DESTINATION_DIR ${FFMPEG_DOWNLOAD_DIR} ID FFMPEG RELATIVE_URL STATUS res) endif( 0 ) set(status TRUE) if(NOT res) set(status FALSE) endif() endforeach() if(status) set(${script_var} "${FFMPEG_DOWNLOAD_DIR}/ffmpeg_version.cmake" PARENT_SCOPE) endif() endfunction() if(OPENCV_INSTALL_FFMPEG_DOWNLOAD_SCRIPT) configure_file("${CMAKE_CURRENT_LIST_DIR}/ffmpeg-download.ps1.in" "${CMAKE_BINARY_DIR}/win-install/ffmpeg-download.ps1" @ONLY) install(FILES "${CMAKE_BINARY_DIR}/win-install/ffmpeg-download.ps1" DESTINATION "." COMPONENT libs) endif() ocv_install_3rdparty_licenses(ffmpeg license.txt readme.txt)
这样,点击cmake, config, 应该还是会报错,因为 .cache/中的 ffmpeg_version.cmake 在cmakefile的生成目录中缺少了这个文件。
于是,找到对应的目录,将 ffmpeg_version.cmake 拷贝过去。
再cmake, config 。
一般就能成功了。
ippcv部分差不多也是这个过程。
enjoy!
wish you healthy!