opencv 4.2.0 编译

一、软件下载

下载opencv 4.2.0 source,cmake,opencv-contrib 4.2.0,VS2019.

二、CMake编译

  1. 解压opencv source命名opencv-4.2.0,解压opencv_contrib 4.2.0更名为opencv_contrib,并放入opencv-4.2.0文件夹中,并新建文件夹build。
  2. 打开cmake软件按图填写


    image.png
  3. 点击configure 选择VS版本 点击继续
  4. configure成功后,search BUILD_opencv_world打钩,OPENCV_EXTRA_MODULES_PATH=opencv-4.2.0\opencv_contrib\modules,再次configure
  5. 点击generate,在build目录下生成opencv.sln

三、VS2019编译

  1. 用VS2019打开opencv.sln,点击菜单栏生成,批生成


    image.png
  2. 编译成功后,系统path变量添加E:\opencv-4.2.0\build\install\x64\vc16\bin
    新建VS项目配置属性表,
    C++附加包含目录包括:build\install\include,build\install\include\opencv2
    VC++包含目录: build\install\include,build\install\include\opencv2
    VC++库目录:build\install\x64\vc16\lib
    链接器输入:opencv_world420d.lib

四、测试代码

#include 
#include 
#include 
#include 

using namespace cv;
using namespace std;

int main()
{
    Mat image = Mat::zeros(300, 600, CV_8UC3);
    circle(image, Point(250, 150), 100, Scalar(0, 255, 128), -100);
    circle(image, Point(350, 150), 100, Scalar(255, 255, 255), -100);
    imshow("Display Window", image);
    waitKey(0);
    return 0;
}

image.png

四、error及解决措施

  1. CMake编译报错
CMake Warning at cmake/OpenCVGenSetupVars.cmake:54 (message):
  CONFIGURATION IS NOT SUPPORTED: validate setupvars script in install
  directory
Call Stack (most recent call first):
  CMakeLists.txt:947 (include)

解决方法: 无视

  1. CMake编译报错 : 找不到python2


    image.png

    解决方法:Anaconda 新建一个python27环境,CMake界面search中搜索PYTHON_LIBRARY,选择anaconda新建python27虚拟环境中,选择Libs/python27.lib
    同样,把python3的也改掉。

  2. CMake编译报错: ippicv_2019_win_intel64_20180723_general.zip下载失败


    image.png

4.CMake编译报错: opencv_videoio_ffmpeg.dll下载失败


image.png

5.CMake编译报错: opencv_videoio_ffmpeg_64.dll下载失败


image.png
  1. CMake编译报错: ffmpeg_version.cmake下载失败


    image.png
解决方法:

以上问题由科学上网造成的,先查看opencv4.2.0文件夹下的.cache,如ffmpeg文件夹内


image.png

三个文件都是0kb,文件名称是哈希码+文件名
查看build目录下CMakeDownloadLog.txt

#match_hash_in_cmake_cache "OCV_DOWNLOAD_ADE_HASH_3rdparty_ade_v0_1_1f_zip"
#do_copy "opencv_videoio_ffmpeg.dll" "5de6044cad9398549e57bc46fc13908d" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/a66a24e9f410ae05da4baeeb8b451912664ce49c/ffmpeg/opencv_videoio_ffmpeg.dll" "E:/opencv-4.2.0/build/3rdparty/ffmpeg"
#missing "E:/opencv-4.2.0/build/3rdparty/ffmpeg/opencv_videoio_ffmpeg.dll"
#check_md5 "E:/opencv-4.2.0/.cache/ffmpeg/5de6044cad9398549e57bc46fc13908d-opencv_videoio_ffmpeg.dll"
#mismatch_md5 "E:/opencv-4.2.0/.cache/ffmpeg/5de6044cad9398549e57bc46fc13908d-opencv_videoio_ffmpeg.dll" "d41d8cd98f00b204e9800998ecf8427e"
#delete "E:/opencv-4.2.0/.cache/ffmpeg/5de6044cad9398549e57bc46fc13908d-opencv_videoio_ffmpeg.dll"
#cmake_download "E:/opencv-4.2.0/.cache/ffmpeg/5de6044cad9398549e57bc46fc13908d-opencv_videoio_ffmpeg.dll" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/a66a24e9f410ae05da4baeeb8b451912664ce49c/ffmpeg/opencv_videoio_ffmpeg.dll"
#try 1
# timeout on name lookup is not supported
#   Trying 199.232.4.133:443...
# Connected to raw.githubusercontent.com (199.232.4.133) port 443 (#0)
# schannel: ALPN, offering h2
# schannel: ALPN, offering http/1.1
# 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: -1)

手动下载opencv_videoio_ffmpeg.dll,复制到.cache对应的文件夹下并更改名称(哈希码+文件名字)
下载地址:https://raw.githubusercontent.com/opencv/opencv_3rdparty/a66a24e9f410ae05da4baeeb8b451912664ce49c/ffmpeg/opencv_videoio_ffmpeg.dll
问题1-6都可由此方法解决

注意!!

ffmpeg_version.cmake链接由网页打开后不是直接下载,而是直接打开了这个文本,不要复制新建txt。要另存为然后该名称。

  1. CMake编译报错:在安装目录中验证setupvars脚本


    image.png

    解决方法:无视掉,貌似不影响,未验证

  2. VS编译错误 找不到python38.lib

解决方法:直接不编译python接口


image.png

你可能感兴趣的:(opencv 4.2.0 编译)