我尝试使用CMake(GUI版本)构建OpenCV 3.1以启用Cuda。我已安装了Cuda 7.5 64位版本,并且CMake自动找到了正确的Cuda工具包路径。我确保WITH_CUDA值设置为ON,然后按configure按钮。这是关于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,但我无法弄清原因。我已经尝试重新配置和重建多次,但结果都一样。希望能得到帮助!