vs2013 + win8.1 + cuda8.0 手工编译 opencv2.4.9

1. 前言

  1. 由于opencv 默认编译的库文件中是不支持gpu功能的, 为了开启gpu 功能, 需要我们手工编译opencv
  2. 编译过程真的都是泪啊!!!

2. 基本环境

  1. cuda 8.0 https://developer.nvidia.com/cuda-toolkit
    这里写图片描述
  2. windows 8.1
    这里写图片描述
  3. cmake 3.7.2 https://cmake.org/download/
    这里写图片描述
  4. opencv 2.4.9 http://opencv.org/downloads.html
  5. intel tbb https://developer.nvidia.com/cuda-toolkit

3. 配置cmake

这里写图片描述
1. 编译器选择 ‘Visual Studio 12 2013 Win64′
2. 选上 ‘WITH_CUBLAS’, ‘WITH_CUDA’, ‘WITH_OPENGL’, ‘WITH_TBB’
2. 配置cuda 选项
3. 取消 CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE’
4. 查询自己显卡的架构, 设置合适的CUDA_GENERATION
这里写图片描述
5. 由于我们的电脑版本是Thinkpad T420i 很老的机子了。。。。查看显示器可知, 这是nvidia nvs 4200M
6. 然后需要知道nvdia是否支持 http://blog.csdn.net/bendanban/article/details/7595963
这里写图片描述
6. 查询 GPU 架构 http://www.notebookcheck.net/NVIDIA-NVS-4200M.47343.0.html
相关 GPU 架构之间的区别: http://www.cnblogs.com/1024incn/p/4539754.html
最直观的区别是: Fermi 编译的时候是 compute_2x, Kelper 是 compute_3x, Auto 是 compute_1x (这个是编译不同过的)
这里写图片描述
7. 相应的错误: Unsupported gpu architecture ‘compute_11’解决方法http://blog.csdn.net/langb2014/article/details/51658744
http://blog.csdn.net/wang4959520/article/details/51392804

  1. 然后点击 configure 刷新配置, 并设置相应的tbb
    • 把 tbb include path 设置好,例如我的是 “D:\toolkits\tbb43_20140724oss\include”。一定要选到 include文件夹为止。
    • 点击 Configure 刷新
    • 接着可以看到 tbb 的 library 目录自动有了,但是可能是错的,需要改到 Debug 和 Release 文件夹的上级目录为止。例如我的要加上 ‘vc12*,变成 D:/toolkits/tbb43_20140724oss/lib/intel64/vc12〃(不加vc12的话,opencv_core模块都编译不过去,其他的就不用说了)
      点击 Configure 刷新

3. 编译Opencv.sln

3.1 基本操作

右键点击 ALL_BUILD,在点 BUILD
- BUILD 之后在编译一下 INSTALL,来把编译好的文件放在一起到 \install
- 在切换到 Release,重复 ALL_BUILDINSTALL
- Debug 应该会有一个 error
这里写图片描述
这个错误是因为我们默认安装的python 是不提供这个文件的, 如果需要可以手工编译下, 这里我们忽略这个错误
- Release 应该会没有 error

最后将 install 中的文件就是我们编译生成的文件了
这里写图片描述

3.2 遇到的一些bug

  1. NVC.cu, 编译这个文件的时候(gpu 模块)报std 没有max min 成员, 添加一个algorithm 头文件即可
    这里写图片描述
  2. SURF_GPU 未声明的标识符 这是因为opencv2.4.x 中, 将sift, surf 特征算子都移动到了non_free 中, 修改下头文件包含路径即可
    http://blog.csdn.net/holybin/article/details/41144705
    这里写图片描述
  3. HANDLE 未标识, 加入 windows.h 即可
    这里写图片描述
  4. cudalegacy not compile – nppiGraphcut missing
    http://answers.opencv.org/question/95148/cudalegacy-not-compile-nppigraphcut-missing/
  5. 编译器堆空间不足, 清理下多余的应用, 最好只让vs 单独跑

4. 参考文章

http://blog.csdn.net/lanbing510/article/details/41211697

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章