前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >win10_opencv4.2_cuda11_vs2019 编译

win10_opencv4.2_cuda11_vs2019 编译

原创
作者头像
shirishiyue
发布2020-09-10 15:49:11
3.6K2
发布2020-09-10 15:49:11
举报
文章被收录于专栏:全栈码全栈码

查看cuda11支持的vs版本:https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html

1,安装 visual studio 2019 community 免费版

2,下载安装CUDA Toolkit,https://developer.nvidia.com/cuda-downloads?target_os=Windows&target_arch=x86_64&target_version=10,一种是网络下载安装,一种是独立安装包,建议第二个,可以反复装,而且不会有奇怪错误。

3,下载opencv4.2 source包和扩展包

代码语言:javascript
复制
https://github.com/opencv/opencv/releases/download/4.2.0/opencv-4.2.0-vc14_vc15.exe
https://github.com/opencv/opencv_contrib/archive/4.2.0.zip

4,下载cmake最新版本

cmake-3.18.2-win64-x64

5,解压后,目录有如下:

代码语言:javascript
复制
-D:\software
    -build_opencv                    //存放cmake目标文件
    -cmake-3.18.2-win64-x64          //cmake安装包位置
    -opencv-4.2.0                    //opencv4.2源码包
       -opencv_contrib-4.2.0         //上面的扩展包 opencv_contrib 加压后放在这里

————第1阶段:配置cmake

6,双击 cmake-3.18.2-win64-x64\bin\cmake-gui.exe 打开cmake界面

目录填写参考上面的
目录填写参考上面的

7,点击【configure】目标,弹出对话框选择如下:

8,然后点击【Finish】完成config之后,然后找到 OPENCV_EXTRA_MODULES_PATH 设置扩展模块的源代码路径【注意:是下级modules 目录!!!】 ,如下:

9,再configure

10,在搜索框中 WITH_CUDABUILD_CUDA_STUBS,都打勾,点击【configure】按钮。

11,在搜索框中 CUDA_FAST_MATH,打勾,再configure。没有错误,完成。

12,点击【generate】按钮,生成项目。

两个done
两个done

————第2阶段:使用vs生成lib库

这个时候去 build_opencv 这里目录下,双击打开 OpenCV.sln(VS2019工程文件),

默认debug版本,生成的lib和dll带有字母d的后缀
默认debug版本,生成的lib和dll带有字母d的后缀

Debug 版本,点击顶部生成菜单,点击重新生成解决方案。

很多失败的。。。
很多失败的。。。

The problem is in the configuration step. Before pressing generate button, be sure that you specified the appropriate configurations. In this link , you can find an example of configuration to build opencv. Especially, take attention to 'WITH' segments.

重新来一遍 cmake 。。。

关闭vs,删掉build_opencv内容,重新打开cmake

依旧大量错误:

代码语言:javascript
复制
error MSB6006: “cmd.exe”已退出,代码为 1。
LINK : fatal error LNK1104: 无法打开文件“..\..\lib\Debug\opencv_gapi420d.lib”
...

再次搜问题,找到opencv issue里,https://github.com/opencv/opencv/issues/9908,解释如下:

代码语言:javascript
复制
I have encountered this problem today, using VS 2017 and CUDA 9.0.
The actual problem is the first error MSB6006 which leads to the other LNK1104 errors. I searched in google and find this solution:
https://stackoverflow.com/questions/45918446/compiling-opencv-3-3-with-cuda-9-0rc
When using CMAKE to generate the project, change the CUDA_HOST_COMPILER parameter to:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX64\x64\cl.exe
The path of Visual Studio has changed in VS 2017 which leads to the errors.

This can solve most of problems you list, but some errors like: C2610, C2535, .etc still exists, but it seems affect only the performance tests. All OpenCV libraries are generated successfully and the INSTALL procedure also works fine.

好,再来一遍,我默认安装的vs2019 cl.exe路径为:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\bin\Hostx64\x64\cl.exe

新增 cmake配置项为:CUDA_HOST_COMPILER ,(输入后,手动再选择一次,路径是斜杠,不是反斜杠)

依旧是如上错误,不得解。。。。。

头疼。

继续搜发现,

这个配置项 Build_CUDA_STUBS 一定不要 ✔ !!!!

接下来总下总结一下:

1. 换成了opencv4.4版本

2.配置了 OPENCV_EXTRA_MODULES_PATH,WITH_CUDA,CUDA_FAST_MATH,ENABLE_FAST_MATCH,BUILD_opencv_world。

编译时间非常长,大约在2--4个小时时间 编译好后应该不会有什么错。如果有一两个Matlab啊Python啊之类的错误请无视之。如果几十个几百个错可能就会很大程度上影响使用了。

编译好后,找到解决方案目录里的 [CMakeTargets] 项展开的 [INSTALL] 项,右键 -> [Project Only(仅项目)] -> [Build Only INSTALL (仅生成INSTALL)]。 就可以关闭vs2019了

1.2G巨大的debug版dll
1.2G巨大的debug版dll

接下来可以继续生成 release 版本的。

靠谱文章:https://blog.csdn.net/sinat_38679789/article/details/73466834

靠谱文章:https://kazusa.im/2020/08/08/compilingopencv4-4-0withcudaandopencv-python/

参考:https://cloud.tencent.com/developer/article/1523416

OPENCV_DNN_CUDA 这个配置项如果没有自己下载扩展包,就不要勾选,cmake会报错。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • ————第1阶段:配置cmake
  • ————第2阶段:使用vs生成lib库
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档