我尝试使用 CMake(GUI 版本)构建 OpenCV 3.1 以启用 Cuda。我已经安装了 Cuda 7.5 64 位版本,CMake 自动找到了 Cuda 工具包的正确路径。我确保WITH_CUDA值设置为ON,并按下配置。这是我对 Cuda 的了解:
CUDA detected: 7.5
CUDA NVCC target flags: -gencode;arch=compute_20,code=sm_20;-gencode;arch=compute_20,code=sm_21;-gencode;arch=compute_30,code=sm_30;-gencode;arch=compute_35,code=sm_35;-gencode;arch=compute_30,code=compute_30
...
Extra dependencies: comctl32 gdi32 ole32 setupapi ws2_32 vfw32 cudart nppc nppi npps cufft -LC:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5/lib/x64
...
Other third-party libraries:
Use IPP: 9.0.1 [9.0.1]
at: C:/OpenCV-3.1.0/opencv/sources/3rdparty/ippicv/unpack/ippicv_win
Use IPP Async: NO
Use Eigen: NO
Use Cuda: YES (ver 7.5)
Use OpenCL: YES
Use custom HAL: NO
NVIDIA CUDA
Use CUFFT: YES
Use CUBLAS: NO
USE NVCUVID: NO
NVIDIA GPU arch: 20 21 30 35
NVIDIA PTX archs: 30
Use fast math: YES
然后我使用 Visual Studio 12 2013 Win64 生成。
接下来,我在 Visual Studio 2013 中打开新生成的 OpenCV.sln 项目并构建该项目。它完成时没有任何错误,但有 103 个警告,如下所示:
LINK : warning LNK4044: unrecognized option '/LC:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5/lib/x64'; ignored
OpenCV 构建得很好,我可以用它构建程序。我还可以毫无问题地包含“opencv2/core/cuda.hpp”。但是,当我尝试使用 cuda::getDevice() 时,出现此错误:
OpenCV Error: No CUDA support (The library is compiled without CUDA support) in throw_no_cuda, file C:\builds\master_PackSlave-win64-vc12-shared\opencv\modules\core\include\opencv2/core/private.cuda.hpp, line 97
当我从 cv::getBuildInformation() 打印信息时,我得到:
Other third-party libraries:
Use IPP: 9.0.1 [9.0.1]
at: C:\builds\master_PackSlave-win64-vc12-shared\opencv\3rdparty/ippicv/unpack/ippicv_win
Use IPP Async: NO
Use Eigen: NO
Use Cuda: NO
Use OpenCL: YES
Use custom HAL: NO
看起来 Cuda 在这个过程中的某个地方被禁用了,但我不明白为什么。我尝试过多次重新配置和重建,但结果相同。希望得到一些帮助!