OpenCV笔记(5)VS2013 + OpenCV3.0.0 + contrib3.0.0 + CUDA8.0 重编译
近期因为需要用到特征检测和匹配去做一些关于融合的事情,而opencv3.x版本内部并没有支持nonfree以及cuda,需要下载opencv_contrib重新编译。
电脑环境:opencv3.0.0+opencv_contrib3.0.0+CUDA8.0,win7,VS2013
下载地址:contrib要与opencv版本保持一致
CMake:https://cmake.org/download/
opencv:https://opencv.org/releases.html
opencv_contrib:https://github.com/opencv/opencv_contrib
TBB:https://github.com/01org/tbb/releases
CUDA:https://developer.nvidia.com/cuda-downloads
在D盘创建文件夹,将下载的opencv源码和opencv_contrib放在下面,并且新建文件夹Mybuild。我这里直接用的sources文件夹,并把opencv_contrib放在opencv的安装路径里。
安装CMake,完成后打开:
输入opencv源码路径还有编译后的文件放置处。
点击Configure,选择VS2013 Win64:
这里我开始选择了VS2013,后面一直提示模块计算机类型“X64”与目标计算机类型“X86”冲突,后来改为选择VS2013 Win 64就行了。
选择后,会跳到下图:
找到OPENCV_EXTRA_MODULES_PATH,输入opencv_contrib源码包的modules目录。
勾选WITH_TBB:
不安装CUDA的话,要注意把所有带CUDA的都勾选掉。
点击Configure:
等待完成,修改TBB的设置:
找到TBB_ENV_INCLUDE,添加include的路径。
找到TBB_ENV_LIB,添加tbb.lib的路径。
找到TBB_ENV_DEBUG,添加tbb_debug.lib的路径。
继续点击Configure,如下图:
等到完成后,找到TBB_VER_FILE,添加tbb_stddef.h的路径。
最后点击Configure,发现此时没有红色:
确保配置无误后,点击Generate:
我这里出现如下所示的错误:
在前面的CU***项里,添加对应的lib库,lib库在CUDA的安装路径里。
继续点击Generate:
到此CMake编译完成。
接下来在刚刚新建的Mybuild文件夹下,找到opencv.sln,点击打开:
选中项目,重新生成解决方案。
成功后,最后生成Install文件:
选择CMakeTargets下的INSTALL,右击:
选择仅生成INSTALL,点击。
完成后在Mybuild文件里会看到install文件夹,打开发现,里面是重新生成的lib、头文件等。
在VS的包含目录和库目录中,分别将lib、头文件添加进去:
添加附加依赖库:
修改环境变量:
到此,重新编译就结束了。
需要添加的依赖库:
opencv_bgsegm300d.lib
opencv_bioinspired300d.lib
opencv_calib3d300d.lib
opencv_ccalib300d.lib
opencv_core300d.lib
opencv_datasets300d.lib
opencv_face300d.lib
opencv_features2d300d.lib
opencv_flann300d.lib
opencv_hal300d.lib
opencv_highgui300d.lib
opencv_imgcodecs300d.lib
opencv_imgproc300d.lib
opencv_latentsvm300d.lib
opencv_line_descriptor300d.lib
opencv_ml300d.lib
opencv_objdetect300d.lib
opencv_optflow300d.lib
opencv_photo300d.lib
opencv_reg300d.lib
opencv_rgbd300d.lib
opencv_saliency300d.lib
opencv_shape300d.lib
opencv_stereo300d.lib
opencv_stitching300d.lib
opencv_superres300d.lib
opencv_surface_matching300d.lib
opencv_text300d.lib
opencv_tracking300d.lib
opencv_ts300d.lib
opencv_video300d.lib
opencv_videoio300d.lib
opencv_videostab300d.lib
opencv_xfeatures2d300d.lib
opencv_ximgproc300d.lib
opencv_xobjdetect300d.lib
opencv_xphoto300d.lib
opencv_cudaarithm300d.lib
opencv_cudabgsegm300d.lib
opencv_cudacodec300d.lib
opencv_cudafilters300d.lib
opencv_cudawarping300d.lib
opencv_cudev300d.lib