http://blog.csdn.net/eagelangel/article/details/50727643
说明一下,当我编译OpenCV_contrib时,已经是要配合OpenCV3.1的版本才能编译通过,所以有要自己编译OpenCV_contrib的请尽量使用较新的OpenCV版本。
一、下载安装
-
OpenCV3.1下载地址:http://sourceforge.net/projects/opencvlibrary/files/opencv-win/3.1.0/
-
OpenCVcontrib下载地址:https://github.com/Itseez/opencvcontrib
-
cmake-gui下载地址:http://www.cmake.org/cmake/resources/software.html
下载以上内容并安装opencv和cmake-gui,我的OpenCV安装路径为D:\opencv3
二、使用cmake生成OpenCV.sln
-
打开cmake-gui
-
在where is the source code选择opencv的安装目录,我的是D:\opencv3\opencv\sources
-
在where to build the binaries里面选择要将opencv编译到的目录下面,我的是:D:\opencv3\opencv\mybuild
-
点击configure,在弹出的对话框内选择 Visual Studio 2013和default参数,点击finish。(这里需要注意一下,如果系统是x64的,选择的编译工具也必须是x64的,否则后续编译会出错。)
-
过程可能会出现下载不到ippicv_windows_20151201.zip,自己下载一个放进去就可以了。下载CSDN资源区就有
-
这个时候cmake会开始编译不知道什么东西,然后会在屏幕中间出现一堆参数包括Name和Value,在其中找到Name为OPENCV_EXTRA_MODULES_PATH的参数,然后把它的Value设置为opencvcontrib的路径,我的是D:/Files/Codes/Tracking/Exp/opencvcontrib-master/opencvcontrib-master/modules
-
然后再次点击configure,没问题后点击Generate,等待。中间报了两次错,我去掉了BUILDopencvadas和WITH_CUDA等一系列看起来没用的东西,然后就完成了。
三、用VS编译生成debug和release库
-
打开D:\opencv3\opencv\mybuild目录下的OpenCV.sln
-
编译debug版本库:在“解决方案'OpenCV'(416个项目)”上面点击右键-->重新生成解决方案。
-
找到CMakeTargets中的INSTALL,然后右键选择“仅限于项目”-->“仅生成INSTALL”,然后就在D:\opencv3\opencv\mybuild\install中发现了许多东东。至此,debug版本的opencv的库文件就安装完成了。release版本的,方法相同,重复2、3即可。
四、新建、配置自己的项目
-
VC++目录-->包含目录,添加:
D:\opencv3\opencv\mybuild\install\include -
VC++目录-->库目录,添加:
D:\opencv3\opencv\mybuild\install\x86\vc12\lib
D:\opencv3\opencv\mybuild\install\x86\vc12\staticlib -
链接器-->输入-->附加依赖项,添加: (下面添加的release的版本,注意添加的库与编译选项要一致)
opencv_aruco310.lib
opencv_bgsegm310.lib
opencv_bioinspired310.lib
opencv_calib3d310.lib
opencv_ccalib310.lib
opencv_core310.lib
opencv_datasets310.lib
opencv_dnn310.lib
opencv_dpm310.lib
opencv_face310.lib
opencv_features2d310.lib
opencv_flann310.lib
opencv_fuzzy310.lib
opencv_highgui310.lib
opencv_imgcodecs310.lib
opencv_imgproc310.lib
opencv_line_descriptor310.lib
opencv_ml310.lib
opencv_objdetect310.lib
opencv_optflow310.lib
opencv_photo310.lib
opencv_plot310.lib
opencv_reg310.lib
opencv_rgbd310.lib
opencv_saliency310.lib
opencv_shape310.lib
opencv_stereo310.lib
opencv_stitching310.lib
opencv_structured_light310.lib
opencv_superres310.lib
opencv_surface_matching310.lib
opencv_text310.lib
opencv_tracking310.lib
opencv_ts310.lib
opencv_video310.lib
opencv_videoio310.lib
opencv_videostab310.lib
opencv_xfeatures2d310.lib
opencv_ximgproc310.lib
opencv_xobjdetect310.lib
opencv_xphoto310.lib
ippicvmt.lib