Cuda只支持Nvidia显卡,但也不是支持所有的NVIDIA显卡。在安装之前,先确认下自己的显卡是否支持
可以看出,我显卡的Cuda版本是9.1.83去官网下载即可。现在可以进行安装配置
下载地址https://msdn.itellyou.cn
默认安装即可
网上安装的时候很多建议自定义安装,然后选择只安装cuda,但我自己安装的时候直接按默认安装也成功
cuda下载地址:https://developer.nvidia.com/cuda-91-download-archive
安装完之后进行测试:
在系统变量中添加以下变量
CUDA_PATH = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1
CUDA_SDK_PATH = C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.0
CUDA_LIB_PATH = %CUDA_PATH%\lib\x64
CUDA_BIN_PATH = %CUDA_PATH%\bin
CUDA_SDK_BIN_PATH = %CUDA_SDK_PATH%\bin\win64
CUDA_SDK_LIB_PATH = %CUDA_SDK_PATH%\common\lib\x64
使用cmd测试:出现以下即为成功
下载完之后解压到非中文路径下,像我解压到D盘根目录下并改成opencv3.4.0
opencv3.4.0下载地址:https://opencv.org/releases/page/2/
安装完成后运行
cmake下载地址:https://cmake.org/files/v3.10/
点击Configure,选择Viusal Studio14 2015 Win64,点击finish
完成后下方的日志会出现Cuda detected 9.1。
在上方勾选With Cuda,点击generate。多生成几次,直接上方没有红色部分。
点击Open Project。进入到VS2015界面,选择批生成,勾选ALL_BUILD,INSTALL的Release和Debug,一共4个版本
开始生成,这段时间比较长,我是通宵放它在那里做的。
首先添加Opencv的环境变量,点击此电脑右键-属性
点击新建
重启电脑
新建一个VS2015控制台项目
在属性里面添加库目录和包含目录
在链接器输入的附加依赖项中添加:
Debug版本
opencv_calib3d340d.lib
opencv_core340d.lib
opencv_cudaarithm340d.lib
opencv_cudabgsegm340d.lib
opencv_cudacodec340d.lib
opencv_cudafeatures2d340d.lib
opencv_cudafilters340d.lib
opencv_cudaimgproc340d.lib
opencv_cudalegacy340d.lib
opencv_cudaobjdetect340d.lib
opencv_cudaoptflow340d.lib
opencv_cudastereo340d.lib
opencv_cudawarping340d.lib
opencv_cudev340d.lib
opencv_features2d340d.lib
opencv_flann340d.lib
opencv_highgui340d.lib
opencv_imgcodecs340d.lib
opencv_imgproc340d.lib
opencv_ml340d.lib
opencv_objdetect340d.lib
opencv_photo340d.lib
opencv_shape340d.lib
opencv_stitching340d.lib
opencv_superres340d.lib
opencv_video340d.lib
opencv_videoio340d.lib
opencv_videostab340d.lib
opencv_dnn340d.lib
Release版本
opencv_calib3d340.lib
opencv_core340.lib
opencv_cudaarithm340.lib
opencv_cudabgsegm340.lib
opencv_cudacodec340.lib
opencv_cudafeatures2d340.lib
opencv_cudafilters340.lib
opencv_cudaimgproc340.lib
opencv_cudalegacy340.lib
opencv_cudaobjdetect340.lib
opencv_cudaoptflow340.lib
opencv_cudastereo340.lib
opencv_cudawarping340.lib
opencv_cudev340.lib
opencv_features2d340.lib
opencv_flann340.lib
opencv_highgui340.lib
opencv_imgcodecs340.lib
opencv_imgproc340.lib
opencv_ml340.lib
opencv_objdetect340.lib
opencv_photo340.lib
opencv_shape340.lib
opencv_stitching340.lib
opencv_superres340.lib
opencv_video340.lib
opencv_videoio340.lib
opencv_videostab340.lib
opencv_dnn340.lib
在cpp文件中输入以下代码
#include "stdafx.h"
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;
using namespace cuda;
int main(int argc, char **argv)
{
try
{
cout << getCudaEnabledDeviceCount();
}
catch (const cv::Exception& ex)
{
cout << "Error:" << ex.what() << endl;
}
system("PAUSE");
return 0;
}
运行:结果返回1则为成功。至此配置全部完成