WINDOWS下OpenCV+Contrib+CUDA配置(CUDA10.1,VS2017,opencv3.4.5)

搞了两天终于搞定了,头大!!刚开始用的VS2019,编译了四五次一直不成功,一气之下,卸载VS2019,CUDA,重新安装VS2017,CUDA,然后一次可成功了,就是这么神奇!

重要参考文章:

配置过程

1,先装VS2017,必须先安装这个,因为接下来安装CUDA,依赖这个。

2,安装CUDA。

3,下载opencv,以及opencv_contrib,二者的版本号一定要一致。在我电脑上二者的路径为:

D:\Softwares\opencv3.4.5
D:\Softwares\opencv3.4.5\opencv_contrib-3.4.5

4,下载Cmake,我用的版本是3.14.6

5,开始编译,编译过程请参照上面的链接文章,写的很详细。特别注意的是,Configure过程中,如果有红色,请一直Configure,直到红色消失,不然不会成功。build目录在opencv3.4.5目录下,新建的build_gpu文件夹:之后生成的东西都在这里。

D:\Softwares\opencv3.4.5\opencv\build_gpu

6,用VS2017打开OpenCV.sln,选择生成-重新生成解决方案时,这个过程很漫长,我自己的电脑需要两个小时,还一直输出warning信息,这个可以忽视它,不影响最终结果。我生成完毕后,输出成功171个,失败4个,但是没找到失败的是哪四个,很尴尬。这四个应该可以之后再单独生成的。

7,验证安装是否成功时,

新建VS2017控制台应用程序,x64的

工程属性--配置属性--VC++目录--包含目录  中添加:

D:\Softwares\opencv3.4.5\opencv\build_gpu\install\include
D:\Softwares\opencv3.4.5\opencv\build_gpu\install\include\opencv
D:\Softwares\opencv3.4.5\opencv\build_gpu\install\include\opencv2

 

工程属性--配置属性--VC++目录--库目录  中添加:

D:\Softwares\opencv3.4.5\opencv\build_gpu\install\x64\vc15\lib

工程属性--配置属性--链接器--输入--附加依赖项 中添加:(一共56个)

opencv_aruco345d.lib
opencv_bgsegm345d.lib
opencv_bioinspired345d.lib
opencv_calib3d345d.lib
opencv_ccalib345d.lib
opencv_core345d.lib
opencv_cudaarithm345d.lib
opencv_cudabgsegm345d.lib
opencv_cudacodec345d.lib
opencv_cudafeatures2d345d.lib
opencv_cudafilters345d.lib
opencv_cudaimgproc345d.lib
opencv_cudalegacy345d.lib
opencv_cudaobjdetect345d.lib
opencv_cudaoptflow345d.lib
opencv_cudastereo345d.lib
opencv_cudawarping345d.lib
opencv_cudev345d.lib
opencv_datasets345d.lib
opencv_dnn345d.lib
opencv_dpm345d.lib
opencv_face345d.lib
opencv_features2d345d.lib
opencv_flann345d.lib
opencv_fuzzy345d.lib
opencv_highgui345d.lib
opencv_img_hash345d.lib
opencv_imgcodecs345d.lib
opencv_imgproc345d.lib
opencv_line_descriptor345d.lib
opencv_ml345d.lib
opencv_objdetect345d.lib
opencv_optflow345d.lib
opencv_phase_unwrapping345d.lib
opencv_photo345d.lib
opencv_plot345d.lib
opencv_reg345d.lib
opencv_rgbd345d.lib
opencv_saliency345d.lib
opencv_shape345d.lib
opencv_stereo345d.lib
opencv_stitching345d.lib
opencv_structured_light345d.lib
opencv_superres345d.lib
opencv_surface_matching345d.lib
opencv_text345d.lib
opencv_tracking345d.lib
opencv_video345d.lib
opencv_videoio345d.lib
opencv_videostab345d.lib
opencv_xfeatures2d345d.lib
opencv_ximgproc345d.lib
opencv_xobjdetect345d.lib
opencv_xphoto345d.lib
opencv_dnn_objdetect345d.lib
opencv_hfs345d.lib

8,验证程序:

#include "stdafx.h"
#include 
#include "opencv2/opencv_modules.hpp"
#include "opencv2/core.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/cudafeatures2d.hpp"
#include "opencv2/xfeatures2d/cuda.hpp"

using namespace std;
using namespace cv;
using namespace cv::cuda;

int main()
{
	//测试显卡方法1(此方法可以读取显卡型号)
	printShortCudaDeviceInfo(getDevice());

	//测试显卡方法2
	int iDevicesNum = getCudaEnabledDeviceCount();
	cout << "Devices Num:"<

输出结果如下:

Device 0:  "GeForce MX250"  2048Mb, sm_61, Driver/Runtime ver.10.10/10.10
Devices Num:1
IsGPUDeviceOK : 1
请按任意键继续. . .

第一行是我的电脑的显卡信息,第二行是说明只有一块,第三行是程序识别到了GPU。

你可能感兴趣的:(CUDA)