1、打开vs2013,新建cuda项目,为vs2013配置OpenCV环境:选择属性管理器,
先后分别在Debug和Release上的Microsoft.Cpp.Win64.user,点击右键,属性,VC++目录:
包含目录:D:\tfiles\opencv-2.4.9\build-vs2013\install\include;
D:\tfiles\opencv-2.4.9\build-vs2013\install\include\opencv;
D:\tfiles\opencv-2.4.9\build-vs2013\install\include\opencv2;
2.可执行文件目录:D:\tfiles\tbb43_20150424oss\bin\intel64\vc12
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\bin
(这是我自己的目录,请根据你的目录添加)
opencv_calib3d249d.lib
opencv_contrib249d.lib
opencv_core249d.lib
opencv_features2d249d.lib
opencv_flann249d.lib
opencv_gpu249d.lib
opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_legacy249d.lib
opencv_ml249d.lib
opencv_nonfree249d.lib
opencv_objdetect249d.lib
opencv_ocl249d.lib
opencv_photo249d.lib
opencv_stitching249d.lib
opencv_superres249d.lib
opencv_ts249d.lib
opencv_video249d.lib
opencv_videostab249d.lib
opencv_calib3d249.lib
opencv_contrib249.lib
opencv_core249.lib
opencv_features2d249.lib
opencv_flann249.lib
opencv_gpu249.lib
opencv_highgui249.lib
opencv_imgproc249.lib
opencv_legacy249.lib
opencv_ml249.lib
opencv_nonfree249.lib
opencv_objdetect249.lib
opencv_ocl249.lib
opencv_photo249.lib
opencv_stitching249.lib
opencv_superres249.lib
opencv_ts249.lib
opencv_video249.lib
opencv_videostab249.lib
见证奇迹的时刻到了,写个程序测试以下吧。
注意看看Debug配置管理器的选择是不是X64平台
#include
#include
#include
#include
#include
int main()
{
int num_devices = cv::gpu::getCudaEnabledDeviceCount();
if (num_devices <= 0)
{
std::cerr << "There is no devoce" << std::endl;
return -1;
}
int enable_device_id = -1;
for (int i = 0; i < num_devices; i++)
{
cv::gpu::DeviceInfo dev_info(i);
if (dev_info.isCompatible())
{
enable_device_id = i;
}
}
if (enable_device_id < 0)
{
std::cerr << "GPU module isn't built for GPU" << std::endl;
return -1;
}
cv::gpu::setDevice(enable_device_id);
cv::Mat src_image = cv::imread("test.jpg");
cv::Mat dst_image;
cv::gpu::GpuMat d_src_img(src_image);//upload src image to gpu
cv::gpu::GpuMat d_dst_img;
cv::gpu::cvtColor(d_src_img, d_dst_img, CV_BGR2GRAY);//canny
d_dst_img.download(dst_image);//download dst image to cpu
cv::imshow("test", dst_image);
cv::waitKey(50000);
return 0;
}