WIN10 VS2015 Cmake编译 opencv3.3 cuda9.0

WIN10 VS2015 Cmake编译 opencv3.3 cuda9.0

由于opencv 和cuda版本不匹配 在Windows端经常出现安装失败,或者with_cuda_on 但在实际代码中缺报错 The library is compiled without CUDA support 。这其实都是版本不同导致的结果 。

目前cuda9.0和opencv3.3可以匹配 cuda8.0和opencv3.2可以匹配;

本篇讲讲述 在win10系统中 利用cmake3.9.6 编译opencv3.3 with cuda9.0 测试有效

确保自己的win10 系统可以正常安装CUDA9.0 ,测试是否正常安装可以在cmd下
这里写图片描述

之后安装cmake 3.9.6
这里写图片描述

下载opencv3.3.0 exe版本 并且安装到一个目录下
WIN10 VS2015 Cmake编译 opencv3.3 cuda9.0_第1张图片

在sources -> cmake 文件夹中找到FindCUDA.cmake文件
找到行
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)

找到行
set(CUDA_npp_LIBRARY “ CUDAnppcLIBRARY; {CUDA_nppi_LIBRARY}; CUDAnppsLIBRARY)set(CUDAnppLIBRARY {CUDA_nppc_LIBRARY}; CUDAnppialLIBRARY; {CUDA_nppicc_LIBRARY}; CUDAnppicomLIBRARY; {CUDA_nppidei_LIBRARY}; CUDAnppifLIBRARY; {CUDA_nppig_LIBRARY}; CUDAnppimLIBRARY; {CUDA_nppist_LIBRARY}; CUDAnppisuLIBRARY; {CUDA_nppitc_LIBRARY};${CUDA_npps_LIBRARY}”)

找到行
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
在文件中找到
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”)
更改为
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”)

最后一步 在头文件中加入 #include “cuda_fp16.h”
添加至 opencv\modules\cudev\include\opencv2\cudev\common.hpp

其次由于在编译过程中会下载几个文件 但是文件的服务器在国外 所以下载大概率会失败 所以下面给出这几个文件的下载办法
前往https://github.com/opencv/opencv_3rdparty/branches/all
下什么版本可以在
D:\opencv3.3.0\opencv\sources\3rdparty\ffmpeg
D:\opencv3.3.0\opencv\sources\3rdparty\ippicv 里面的 ffmpeg或ippicv.cmake文件中查看到
比如说
WIN10 VS2015 Cmake编译 opencv3.3 cuda9.0_第2张图片
里面第一行为对应的版本

下面开始拷贝下载文件
将下载目录中的 ffmpeg_version.cmake、opencv_ffmpeg.dll、opencv_ffmpeg_64.dll 三项复制到 “path to your OpenCV\opencv\sources\3rdparty\ffmpeg” 目录下。

编辑 ffmpeg.cmake
在 “path to your OpenCV\opencv\sources\3rdparty\ffmpeg” 中打开文件 ffmpeg.cmake ,将其内容修改为:
message(STATUS “FFMPEG: Package successfully downloaded”)
include(${CMAKE_CURRENT_LIST_DIR}/ffmpeg_version.cmake)

保存完毕

在前面下载解压的目录“..\opencv_3rdparty-ippicv-master_20170822\ippicv” 中将ippicv_windows_20170822.zip 解压到当前目录。
在 “path to your OpenCV \opencv\sources\3rdparty\ippicv” 中创建文件夹unpack,将解压得到的ippicv_win 复制到新创建的unpack 中。
编辑 downloader.cmake
将downloader.cmake 的内容修改为:

#

The script downloads ICV package

#

On return this will define:

OPENCV_ICV_PATH - path to unpacked downloaded package

#

function(_icv_downloader)
# Commit SHA in the opencv_3rdparty repo
set(IPPICV_BINARIES_COMMIT “81a676001ca8075ada498583e4166079e5744668”)
# Define actual ICV versions
if(APPLE)
set(OPENCV_ICV_PACKAGE_NAME “ippicv_macosx_20151201.tgz”)
set(OPENCV_ICV_PACKAGE_HASH “4ff1fde9a7cfdfe7250bfcd8334e0f2f”)
set(OPENCV_ICV_PLATFORM “macosx”)
set(OPENCV_ICV_PACKAGE_SUBDIR “/ippicv_osx”)
elseif(UNIX)
if(ANDROID AND NOT (ANDROID_ABI STREQUAL x86 OR ANDROID_ABI STREQUAL x86_64))
return()
endif()
set(OPENCV_ICV_PACKAGE_NAME “ippicv_linux_20151201.tgz”)
set(OPENCV_ICV_PACKAGE_HASH “808b791a6eac9ed78d32a7666804320e”)
set(OPENCV_ICV_PLATFORM “linux”)
set(OPENCV_ICV_PACKAGE_SUBDIR “/ippicv_lnx”)
elseif(WIN32 AND NOT ARM)
set(OPENCV_ICV_PACKAGE_NAME “ippicv_windows_20151201.zip”)
set(OPENCV_ICV_PACKAGE_HASH “04e81ce5d0e329c3fbc606ae32cad44d”)
set(OPENCV_ICV_PLATFORM “windows”)
set(OPENCV_ICV_PACKAGE_SUBDIR “/ippicv_win”)
else()
return() # Not supported
endif()

set(OPENCV_ICV_UNPACK_PATH “ CMAKECURRENTLISTDIR/unpack)set(OPENCVICVPATH {OPENCV_ICV_UNPACK_PATH}${OPENCV_ICV_PACKAGE_SUBDIR}”)

message(STATUS “ICV: Package successfully downloaded”)
set(OPENCV_ICV_PATH “${OPENCV_ICV_PATH}” PARENT_SCOPE)
endfunction()

_icv_downloader()

保存完毕

之后开始打开camke
WIN10 VS2015 Cmake编译 opencv3.3 cuda9.0_第3张图片

源文件路径 和 目标文件路径自己条件 之后会问你是否生成这个目录 点击是 即可
在编译环境中选择vs2015 win64 选项 之后确定 configure generate 上面红色区域要完全消失才可 记得勾选opencv_world

打开工程先编译opencv_world部分 看是否出现错误
之后可以编译ALL-BUILD
release 和 DEBUG 版本 都编译一下 之后编译INSTALL
WIN10 VS2015 Cmake编译 opencv3.3 cuda9.0_第4张图片

最后的结果都在install文件中

你可能感兴趣的:(WIN10 VS2015 Cmake编译 opencv3.3 cuda9.0)