vs2019编译opencv349和扩展库

2022/1/28 23:05:25

本文主要是介绍vs2019编译opencv349和扩展库,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 

0环境

  • VS2019
  • CMAKE
  • cuda11.5
  • cudnn

开着飞机上谷歌软件,用于下载依赖

1下载源码

https://github.com/opencv/opencv/releases/tag/3.4.9

 

 

 https://github.com/opencv/opencv_contrib/releases/tag/3.4.9

 

 

 下载

 

 

 

2 编译

 设置路径和生成路径

 

 

 点击configure

 

 

 点击finish

 

 

 等待结束

 

 

 中间有一个警报,不是报错,忽略

 

 

 

3开始配置

3-1 添加cuda

 

 

 3-2 添加扩展库 注意路径 /

 

 

3-3 添加sifit 角点库

 

 

 3-4 添加world库 编译到一个里面

 

 

 3-5 选择编译版本

 

 

 3-6 是否编译python可用的版本(默认选了,但是可不用)

 

 

 

然后点击生成

请注意,开着某飞机上谷歌,而以保证这个过程中下载一些需要的文件,也可以根据后期报错记录,手动下载。

 

 

 

 

 

问题1 缺少没有下载好的库,需要手动下载

这些都是配置过程中没有自动下载下来的,需要手动去网址下载

从下载记录找哪些没被下载,手动下载好,放在对应位置

 

 

 

第一组

 

 

 

 

下载

https://raw.githubusercontent.com/opencv/opencv_3rdparty/548e3c997a80d65f710b9048f1d33371e3a203ac/ffmpeg/opencv_ffmpeg.dll

放在

opencv_349/build/3rdparty/ffmpeg/opencv_ffmpeg.dll"

下载

https://raw.githubusercontent.com/opencv/opencv_3rdparty/548e3c997a80d65f710b9048f1d33371e3a203ac/ffmpeg/opencv_ffmpeg_64.dll

放在

opencv_349/build/3rdparty/ffmpeg/opencv_ffmpeg_64.dll

 

下载

https://raw.githubusercontent.com/opencv/opencv_3rdparty/548e3c997a80d65f710b9048f1d33371e3a203ac/ffmpeg/ffmpeg_version.cmake

 

另存为是txt格式,需要去掉txt

 

 

 放在

opencv349/opencv_349/build/3rdparty/ffmpeg/ffmpeg_version.cmake

 

 

 

下载

https://raw.githubusercontent.com/opencv/opencv_3rdparty/32e315a5b106a7b89dbed51c28f8120a48b368b4/ippicv/ippicv_2019_win_intel64_20180723_general.zip

放在

opencv_349/build/3rdparty/ippicv

然后回自动转移到

opencv_349\.cache\ippicv\1d222685246896fe089f88b8858e4b2f-ippicv_2019_win_intel64_20180723_general.zip

 

 

下载

https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm.i"

 

 

 放到

opencv_349/build/downloads/xfeatures2d/boostdesc_bgm.i

下载

https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm_bi.i

放到

opencv_349/build/downloads/xfeatures2d/boostdesc_bgm_bi.i

下载

https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm_hd.i

放到

opencv_349/build/downloads/xfeatures2d/boostdesc_bgm_hd.i

下载

https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_064.i

放到

opencv_349/build/downloads/xfeatures2d/boostdesc_binboost_064.i

下载

https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_128.i

放到

opencv_349/build/downloads/xfeatures2d/boostdesc_binboost_128.i

下载

https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_256.i

放到

opencv_349/build/downloads/xfeatures2d/boostdesc_binboost_256.i

下载

https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_lbgm.i

放到

opencv_349/build/downloads/xfeatures2d/boostdesc_lbgm.i

下载

https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_48.i

放到

/opencv_349/build/downloads/xfeatures2d/vgg_generated_48.i

下载

https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_64.i

放到

opencv_349/build/downloads/xfeatures2d/vgg_generated_64.i

下载

https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_80.i

放到

opencv_349/build/downloads/xfeatures2d/vgg_generated_80.i

下载

https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_120.i

放到

opencv_349/build/downloads/xfeatures2d/vgg_generated_120.i

下载

https://raw.githubusercontent.com/opencv/opencv_3rdparty/8afa57abc8229d611c4937165d20e2a2d9fc5a12/face_landmark_model.dat

放到

opencv_349/build/testdata/cv/face//face_landmark_model.dat

 

 

重新

 

 

 

 

点击

 

 

 

 

 

 

 

 

第二个报错

 

 

 

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_nppicom_LIBRARY (ADVANCED)
    linked by target "opencv_test_phase_unwrapping" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_core" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_highgui" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_videostab" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_cudaarithm" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_core" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_rgbd" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_features2d" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_cudafeatures2d" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_imgcodecs" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_cudaarithm" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_flann" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_objdetect" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_line_descriptor" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_hdf" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_cudafeatures2d" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_imgproc" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_videoio" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_cudalegacy" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_stereo" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_imgproc" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_line_descriptor" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_ml" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_cudafilters" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_reg" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_reg" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_cudastereo" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_video" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_tracking" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_video" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_cudabgsegm" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_stereo" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_xphoto" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_cudabgsegm" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_shape" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_cudafilters" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_cudaimgproc" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_cudaimgproc" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_cudawarping" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_dnn" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_cudawarping" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_bioinspired" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_photo" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_dnn" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_features2d" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_cudacodec" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_fuzzy" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_xphoto" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_imgcodecs" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_videoio" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_photo" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_bgsegm" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_text" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_calib3d" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_cudacodec" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_calib3d" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_cudastereo" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_objdetect" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_structured_light" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_tracking" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_xfeatures2d" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_xfeatures2d" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_ximgproc" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_ximgproc" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_aruco" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_bioinspired" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_cudalegacy" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_cudaobjdetect" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_cudaobjdetect" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_cudaoptflow" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_cudaoptflow" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_face" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_optflow" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_optflow" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_stitching" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_stitching" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_test_superres" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_perf_superres" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_world" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_world" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/world
    linked by target "opencv_img_hash" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_contrib_349/modules/img_hash
    linked by target "opencv_img_hash" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_contrib_349/modules/img_hash
    linked by target "opencv_test_img_hash" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_contrib_349/modules/img_hash
    linked by target "opencv_ts" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/ts
    linked by target "opencv_ts" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/modules/ts
    linked by target "opencv_traincascade" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/apps/traincascade
    linked by target "opencv_createsamples" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/apps/createsamples
    linked by target "opencv_annotation" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/apps/annotation
    linked by target "opencv_visualisation" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/apps/visualisation
    linked by target "opencv_interactive-calibration" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/apps/interactive-calibration
    linked by target "opencv_version_win32" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/apps/version
    linked by target "opencv_version" in directory D:/dongdong/v1_Tool/v3_dll/opencv349/opencv_349/apps/version

Generating done

  

 

 

 

第一个报错 解决方案

https://stackoverflow.com/questions/46584000/cmake-error-variables-are-set-to-notfound 

 

 

 

 1) 寻找符合以下条件的行:

find_cuda_helper_libs(nppi)

  

 

 并将其替换为以下行:

 find_cuda_helper_libs(nppial)
  find_cuda_helper_libs(nppicc)
  find_cuda_helper_libs(nppicom)
  find_cuda_helper_libs(nppidei)
  find_cuda_helper_libs(nppif)
  find_cuda_helper_libs(nppig)
  find_cuda_helper_libs(nppim)
  find_cuda_helper_libs(nppist)
  find_cuda_helper_libs(nppisu)
  find_cuda_helper_libs(nppitc)

  

 

 

 

我尝试了以下方法并且成功了:

FindCUDA.cmake在库中更改nppi为几个拆分的。这必须在 3 个地方完成。请记住,此更改只是为了使其与 CUDA 9.0 一起使用,我不会检查版本或任何内容,如果您打算将其提供给具有不同 CUDA 版本的不同人,则应该这样做。

1) 寻找符合以下条件的行:

find_cuda_helper_libs(nppi)

并将其替换为以下行:

  find_cuda_helper_libs(nppial)
  find_cuda_helper_libs(nppicc)
  find_cuda_helper_libs(nppicom)
  find_cuda_helper_libs(nppidei)
  find_cuda_helper_libs(nppif)
  find_cuda_helper_libs(nppig)
  find_cuda_helper_libs(nppim)
  find_cuda_helper_libs(nppist)
  find_cuda_helper_libs(nppisu)
  find_cuda_helper_libs(nppitc)

2)找到行

set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}")

  

 

 

 并将其更改为

set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppial_LIBRARY};${CUDA_nppicc_LIBRARY};${CUDA_nppicom_LIBRARY};${CUDA_nppidei_LIBRARY};${CUDA_nppif_LIBRARY};${CUDA_nppig_LIBRARY};${CUDA_nppim_LIBRARY};${CUDA_nppist_LIBRARY};${CUDA_nppisu_LIBRARY};${CUDA_nppitc_LIBRARY};${CUDA_npps_LIBRARY}")

  

3)找到未设置的变量并添加新变量所以,找到

unset(CUDA_nppi_LIBRARY CACHE)

  

 

 

 并将其更改为:

unset(CUDA_nppial_LIBRARY CACHE)
unset(CUDA_nppicc_LIBRARY CACHE)
unset(CUDA_nppicom_LIBRARY CACHE)
unset(CUDA_nppidei_LIBRARY CACHE)
unset(CUDA_nppif_LIBRARY CACHE)
unset(CUDA_nppig_LIBRARY CACHE)
unset(CUDA_nppim_LIBRARY CACHE)
unset(CUDA_nppist_LIBRARY CACHE)
unset(CUDA_nppisu_LIBRARY CACHE)
unset(CUDA_nppitc_LIBRARY CACHE)

  

 

 

 

此外,OpenCVDetectCUDA.cmake您还必须删除不再受支持的 2.0 架构。

 

 

 

它有:

  ...
  set(__cuda_arch_ptx "")
  if(CUDA_GENERATION STREQUAL "Fermi")
    set(__cuda_arch_bin "2.0")
  elseif(CUDA_GENERATION STREQUAL "Kepler")
    set(__cuda_arch_bin "3.0 3.5 3.7")
  ...

 

 

 

 

 它应该是:

    基本上删除了第一个 if 并且第一个 elif 变成了一个 if。

 ...
  set(__cuda_arch_ptx "")
  if(CUDA_GENERATION STREQUAL "Kepler")
    set(__cuda_arch_bin "3.0 3.5 3.7")
  elseif(CUDA_GENERATION STREQUAL "Maxwell")
    set(__cuda_arch_bin "5.0 5.2")
  ...

  

 

 

 

同时修改,去掉2.0

set(__cuda_arch_bin "2.0 3.0 3.5 3.7 5.0 5.2 6.0 6.1") 

 

 

 修改后

set(__cuda_arch_bin "3.0 3.5 3.7 5.0 5.2 6.0 6.1") 

  

 



这篇关于vs2019编译opencv349和扩展库的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程