一、VS2017+openCV3.4.6+openCV3.4.6 contrib扩展模块安装
https://blog.youkuaiyun.com/YHxiaohao/article/details/105900084
1、手动勾选BUILD_opencv_world和BUILD_EXAMPLES。勾选BUILD_opencv_world,主要是把所有的lib文件都弄到一个opencv_world341d.lib中方便配置,若不勾选在最后会产生大量.lib文件,导致最后配置Opencv到vs会太麻烦,有过OpenCV动态链接库的人都知道。
2、勾选 BUILD_EXAMPLES,就是编译Opencv自带的例程。
3、OPENCV_ENABLE_NONFREE是为了在编译成功后可以使用具有专利保护的算法,如果该变量不被选中,就不能使用例如SIFT算法在内的具有专利保护的算法,
4、找到“OPENCV_EXTRA_MODULES_PATH”变量,该变量的含义是告诉编译器扩展包的源码在哪里,选择我们刚才下载的opencv_contrib安装包里的modules文件夹。如果这个变量为空,在编译过程中也不会报错,只是安装了OpenCV的基础版。
勾选完上述操作后,再次点击configure·,直至所有的都变白,但还是要注意下面画红框的是否报错,如果有报错,你不管,后面的步骤还会在出错,进行不下去,请点击链接,看我的另一篇报错文章详解,链接如下:https://blog.youkuaiyun.com/YHxiaohao/article/details/105901509
3、环境变量配置
上面已经生成之后,接下来是环境变量的配置,环境变量配置包括两方面,一方面是电脑端的,另一方面是软件端的。
电脑端的配置,打开桌面我的电脑,右键属性,打开控制面板,点高级系统设置,再点环境变量,选中path,并点编辑,输入第三张图中where to build the binaries你刚刚建立的文件下,install->x64->vc15->bin路径,之后确定。
以上就是电脑环境变量的设置,设置完之后,你还需要对软件端设置,打开vs2017,新建控制台应用程序,路径随便,
然后在属性管理器中,点击你刚刚生成解决方案时的那个环境,在这里我的是Debug x64,刚在你打开OpenCV.lsn时用的什么环境,你在这里就用什么环境。右键添加现有属性表,此时路径更改到你opencv路径下,这样你能够以后再用就不用配置了,直接加载。
新建属性表之后,右键属性,进入页面,在vc++目录中的包含目录和库目录中加入你第三张图中新建文件路径下以下这些:
包含目录:
D:\software\opencv\opencv_build\install\include\opencv
D:\software\opencv\opencv_build\install\include\opencv2
D:\software\opencv\opencv_build\install\include
库目录:
D:\software\opencv\opencv_build\install\x64\vc15\lib
下面介绍生成配置文件并保存的方法,这样每次只需要一个步骤,添加配置文件就可以了。在菜单栏中选择:View -> Other Windows -> Property Manager
在链接器->输入->中附加依赖项:opencv_world346d.lib。在这里我们不用加载网上说的那些很多的lib,因为在前面我们已经勾选了相关选项,请查看前文。
https://blog.youkuaiyun.com/HYYC___/article/details/89512029
二选一:
Debug模式选:opencv_world343d.lib
Release模式选:opencv_world343.lib
这里因为最开始选的Debug|x64,添加opencv_world343d.lib
其中343是OpenCV版本
这两个文件在xxx\\opencv\\build\\x64\\vc15\\lib下面
如下文中说的
https://blog.youkuaiyun.com/biaobro/article/details/79141868
至此点击确定,并进行保存。可以命名为 opencv_346_debug_x64.props
保存到一个公共的路径中,可以以后使用该功能时,直接打开加载该文件就是了。 不用每次配置
但还没有结束,找到\opencv\opencv_build\install\x64\vc15\bin 下的三个dll 复制到C:\Windows\System32中就可以使用了。
下面可以用一个小程序验证:
#include<iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main()
{
// 读入一张图片
Mat img=imread("pic.jpg");
// 创建一个名为 "游戏原画"窗口
cvNamedWindow("游戏原画");
// 在窗口中显示游戏原画
imshow("游戏原画",img);
// 等待6000 ms后窗口自动关闭
waitKey(6000);
return 0;
}
二、CMake opencv时Download: opencv_ffmpeg.dll、ippicv等失败的解决方法
https://blog.youkuaiyun.com/KayChanGEEK/article/details/79919417
最近OpenCV更新到了3.4.1,下载了OpenCV3.4.1的源码,想编译一个VS2013X64的SDK,在CMake的时候一般会下载一些依赖(ffmpeg*.dll,ippicv*.zip)等。但是现在宿主机没有网络,CMake-Configure就会失败···,或者有时候网络很差,下载速度极慢或者干脆一直下载失败···CMake-Configure也会失败。失败提示如下图:
这几个错误是类似的就是Download failed。那只能手动下载了(没网络的换个有网的下载,下载一直失败也直接手动下载),那么问题来了。
去哪里下载? 下载后放哪里?
仔细看错误信息,可以打开download log file看看,如提示,我的在D:/Kits/OpenCV/opencv-source/opencv-3.4.1/build/CMakeDownloadLog.txt,打开可以看到如下内容:
# 下载获取opencv_ffmpeg.dll的过程
use_cache "D:/Kits/OpenCV/opencv-source/opencv-3.4.1/.cache"
do_copy "opencv_ffmpeg.dll" "b8120c07962d591e2e9071a1bf566fd0" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/0a0e88972a7ea97708378d0488a65f83e7cc5e69/ffmpeg/opencv_ffmpeg.dll" "D:/Kits/OpenCV/opencv-source/opencv-3.4.1/build/3rdparty/ffmpeg"
#missing "D:/Kits/OpenCV/opencv-source/opencv-3.4.1/build/3rdparty/ffmpeg/opencv_ffmpeg.dll"
#cmake_download "D:/Kits/OpenCV/opencv-source/opencv-3.4.1/.cache/ffmpeg/b8120c07962d591e2e9071a1bf566fd0-opencv_ffmpeg.dll" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/0a0e88972a7ea97708378d0488a65f83e7cc5e69/ffmpeg/opencv_ffmpeg.dll"
# timeout on name lookup is not supported
# Trying 151.101.0.133...
# TCP_NODELAY set
# Connected to raw.githubusercontent.com (151.101.0.133) port 443 (#0)
# schannel: SSL/TLS connection with raw.githubusercontent.com port 443 (step 1/3)
# schannel: disabled server certificate revocation checks
# schannel: sending initial handshake data: sending 199 bytes...
# schannel: sent initial handshake data: sent 199 bytes
# schannel: SSL/TLS connection with raw.githubusercontent.com port 443 (step 2/3)
# schannel: failed to receive handshake, need more data
# schannel: SSL/TLS connection with raw.githubusercontent.com port 443 (step 2/3)
# schannel: failed to receive handshake, SSL/TLS connection failed
# Closing connection 0
# schannel: shutting down SSL/TLS connection with raw.githubusercontent.com port 443
# Send failure: Connection was reset
# schannel: failed to send close msg: Failed sending data to the peer (bytes written: 4294967295)
# schannel: clear security context handle
#
# 下载获取opencv_ffmpeg_64.dll的过程
do_copy "opencv_ffmpeg_64.dll" "dc9c50e7b05482acc25d6ce0ac61bf1d" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/0a0e88972a7ea97708378d0488a65f83e7cc5e69/ffmpeg/opencv_ffmpeg_64.dll" "D:/Kits/OpenCV/opencv-source/opencv-3.4.1/build/3rdparty/ffmpeg"
#missing "D:/Kits/OpenCV/opencv-source/opencv-3.4.1/build/3rdparty/ffmpeg/opencv_ffmpeg_64.dll"
#cmake_download "D:/Kits/OpenCV/opencv-source/opencv-3.4.1/.cache/ffmpeg/dc9c50e7b05482acc25d6ce0ac61bf1d-opencv_ffmpeg_64.dll" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/0a0e88972a7ea97708378d0488a65f83e7cc5e69/ffmpeg/opencv_ffmpeg_64.dll"
# timeout on name lookup is not supported
# Trying 151.101.0.133...
# TCP_NODELAY set
# Connected to raw.githubusercontent.com (151.101.0.133) port 443 (#0)
# schannel: SSL/TLS connection with raw.githubusercontent.com port 443 (step 1/3)
# schannel: disabled server certificate revocation checks
# schannel: sending initial handshake data: sending 199 bytes...
# schannel: sent initial handshake data: sent 199 bytes
# schannel: SSL/TLS connection with raw.githubusercontent.com port 443 (step 2/3)
# schannel: failed to receive handshake, need more data
# schannel: SSL/TLS connection with raw.githubusercontent.com port 443 (step 2/3)
# schannel: failed to receive handshake, SSL/TLS connection failed
# Closing connection 0
# schannel: shutting down SSL/TLS connection with raw.githubusercontent.com port 443
# Send failure: Connection was reset
# schannel: failed to send close msg: Failed sending data to the peer (bytes written: 4294967295)
# schannel: clear security context handle
#
# 下载获取ffmpeg_version.cmake的过程
do_copy "ffmpeg_version.cmake" "3b90f67f4b429e77d3da36698cef700c" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/0a0e88972a7ea97708378d0488a65f83e7cc5e69/ffmpeg/ffmpeg_version.cmake" "D:/Kits/OpenCV/opencv-source/opencv-3.4.1/build/3rdparty/ffmpeg"
#missing "D:/Kits/OpenCV/opencv-source/opencv-3.4.1/build/3rdparty/ffmpeg/ffmpeg_version.cmake"
#cmake_download "D:/Kits/OpenCV/opencv-source/opencv-3.4.1/.cache/ffmpeg/3b90f67f4b429e77d3da36698cef700c-ffmpeg_version.cmake" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/0a0e88972a7ea97708378d0488a65f83e7cc5e69/ffmpeg/ffmpeg_version.cmake"
# timeout on name lookup is not supported
# Trying 151.101.0.133...
# TCP_NODELAY set
# Connected to raw.githubusercontent.com (151.101.0.133) port 443 (#0)
# schannel: SSL/TLS connection with raw.githubusercontent.com port 443 (step 1/3)
# schannel: disabled server certificate revocation checks
# schannel: sending initial handshake data: sending 199 bytes...
# schannel: sent initial handshake data: sent 199 bytes
# schannel: SSL/TLS connection with raw.githubusercontent.com port 443 (step 2/3)
# schannel: failed to receive handshake, need more data
# schannel: SSL/TLS connection with raw.githubusercontent.com port 443 (step 2/3)
# schannel: failed to receive handshake, SSL/TLS connection failed
# Closing connection 0
# schannel: shutting down SSL/TLS connection with raw.githubusercontent.com port 443
# Send failure: Connection was reset
# schannel: failed to send close msg: Failed sending data to the peer (bytes written: 4294967295)
# schannel: clear security context handle
#
# 下载获取ippicv_2017u3_win_intel64_general_20170822.zip的过程
do_unpack "ippicv_2017u3_win_intel64_general_20170822.zip" "0421e642bc7ad741a2236d3ec4190bdd" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/dfe3162c237af211e98b8960018b564bc209261d/ippicv/ippicv_2017u3_win_intel64_general_20170822.zip" "D:/Kits/OpenCV/opencv-source/opencv-3.4.1/build/3rdparty/ippicv"
#cmake_download "D:/Kits/OpenCV/opencv-source/opencv-3.4.1/.cache/ippicv/0421e642bc7ad741a2236d3ec4190bdd-ippicv_2017u3_win_intel64_general_20170822.zip" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/dfe3162c237af211e98b8960018b564bc209261d/ippicv/ippicv_2017u3_win_intel64_general_20170822.zip"
# timeout on name lookup is not supported
# Trying 151.101.0.133...
# TCP_NODELAY set
# Connected to raw.githubusercontent.com (151.101.0.133) port 443 (#0)
# schannel: SSL/TLS connection with raw.githubusercontent.com port 443 (step 1/3)
# schannel: disabled server certificate revocation checks
# schannel: sending initial handshake data: sending 199 bytes...
# schannel: sent initial handshake data: sent 199 bytes
# schannel: SSL/TLS connection with raw.githubusercontent.com port 443 (step 2/3)
# schannel: failed to receive handshake, need more data
# schannel: SSL/TLS connection with raw.githubusercontent.com port 443 (step 2/3)
# schannel: failed to receive handshake, SSL/TLS connection failed
# Closing connection 0
# schannel: shutting down SSL/TLS connection with raw.githubusercontent.com port 443
# Send failure: Connection was reset
# schannel: failed to send close msg: Failed sending data to the peer (bytes written: 4294967295)
# schannel: clear security context handle
#
CMake后会发现opencv-source根目录下会出现一个.cache的文件夹,里面有需要下载的内容,如果下载失败所有的内容都是0KB如下图:
再看看CMakeDownloadLog.txt的第一句:use_cache "D:/Kits/OpenCV/opencv-source/opencv-3.4.1/.cache"说的就是这个意思。在看看第二句:do_copy "opencv_ffmpeg.dll" "b8120c07962d591e2e9071a1bf566fd0" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/0a0e88972a7ea97708378d0488a65f83e7cc5e69/ffmpeg/opencv_ffmpeg.dll" "D:/Kits/OpenCV/opencv-source/opencv-3.4.1/build/3rdparty/ffmpeg",说的是从https://raw.githubusercontent.com/opencv/opencv_3rdparty/0a0e88972a7ea97708378d0488a65f83e7cc5e69/ffmpeg/opencv_ffmpeg.dll这个网址下载opencv_ffmpeg.dll到D:/Kits/OpenCV/opencv-source/opencv-3.4.1/build/3rdparty/ffmpeg,其MD值为b8120c07962d591e2e9071a1bf566fd0,然后拷贝到.cache对应的文件夹下(该文件名为MD值+'-'+下载的文件名)。那么这个文件就类似脚本进行自动化下载,那么我们就知道手动要怎么搞了。
回答-去哪里下载: https://raw.githubusercontent.com/opencv/opencv_3rdparty/0a0e88972a7ea97708378d0488a65f83e7cc5e69/ffmpeg/opencv_ffmpeg.dll
回答-下载后放哪里:
很显然下载后放.cache下对应的地方,然后改其名字为MD值+'-'+下载的文件名。比如opencv_ffmpeg.dll这个文件下载后凡在.cache下的ffmpeg下,然后改名为b8120c07962d591e2e9071a1bf566fd0-opencv_ffmpeg.dll替换原来0KB的那个文件。
好了,接下来就是重复以上步骤,将opencv_ffmpeg_64.dll,ffmpeg_version.cmake,ippicv_2017u3_win_intel64_general_20170822.zip到对应的网址下载并放到.cache下对应的文件夹下然后改名字。最终效果如下图:
最后再次CMake-Configure就成功通过了