Windows环境中编译opencv3.0同时加入OPENCV_contrib库及解决遇到相关问题
因为opencv3.0默认安装中没有加入SIFT、SURF等点特征检测,一百度下一跳,原来这玩意还弄了个其他的库,还只能在GitHub上才能弄到,这两天弄opencv3的contrib库,遇到了一些问题,为了让大家更好、更快用上contrib库,根据谷歌百度的几个问题,现分享给大家完整流程,也欢迎大家与我讨论其他opencv方面的问题。
一、下载安装准备
- github desktop 下载 windows 7or Later : https://desktop.github.com
- opencv3.0.0 下载 Opencv for Windows:http://opencv.org/downloads.html
- OpenCV_contrib 下载 :https://github.com/Itseez/opencv_contrib
- cmake_gui下载 Windows (Win32 Installer):http://www.cmake.org/download/
下载对应版本的以上软件:opencv3.0.0可以直接解压,我的路径为D:\opencv3,解压完成后会生成D:\opencv3\opencv的目录形式。
github软件会在线直接安装,在桌面可以直接使用Git Shell ,($ cd D:\CVRS_Code\GitHub 也可以设定opencv_contrib下载的其他路径),输入以下命令下载opencv_contrib到指定目录。
1 D:\CVRS_Code\GitHub> git clone https://github.com/Itseez/opencv_contrib.git
cmake_gui 软件直接安装。OK,现在准备工作就绪。
二、利用CMake编译opencv和opencv_contrib库
- 打开cmake_gui.
- 把opencv/source文件夹中的CMakeLists.txt文件直接拖入cmake_gui中,where is the source code自动选择opencv的安装目录为D:\opencv3\opencv\source.
- 更改where to build the binaries 目录,即我们将要编译的目录,我的是:D:\opencv3\opencv\Mybuild
- 点击configure,点击确定,选择默认编译器,点击finish。cmake将开始进行编译,如果一切顺利将最后显示Configure Done!表明我们configure完成,在出现的红色区域内找到OPENCV,子目录中找到OPENCV_EXTRA_MODULES_PATH,设置它的值为opencv_contrib/modules的绝对路径,在这里我的设置为D:\opencv3\opencv\sources\modules\opencv_contrib\modules(之前把opencv_contrib放在source文件夹外面,编译不成功,所以这里只介绍我的方法)。
- 可以再红色区域内再次去掉BUILD_OPENCV 和WITH_CUDA等有些硬件不支持的库,再次点击configure,正常情况会成功显示Configure Done! 然后点击Generate生成。
三、利用VS编译Debug和Release库
- 打开D:\opencv3\opencv\mybuild目录下的OpenCV.sln
- 在CMake Target中找到 INSTALL ,在Debug和Release的条件中分别右键选择build,生成debug和release库,这个过程大概持续10-20分钟。
- 我们会在D:\opencv3\opencv\Mybuild\install文件夹中看到这几个文件目录
--bin --etc --include --opencv --opencv2 --x86 --vc10 --bin --lib --staticlib --LICENSE --OpenCVConfig.cmake --OpenCVConfig-version.cmake
四、Windows和VS中配置Opencv3
- 添加环境变量PATH D:\opencv3\opencv\Mybuild\install\x86\vc10\bin ,记得多个需要用分号(;)隔开。
- 任意建立一个新的工程,打开视图(View)->Other Windows->Property Manager。点击Debug,双击Microsoft.Cpp.Win32.user,在其中设置:(以下设置完成之后,重复2的操作,选择Release,同样方式设置Microsoft.Cpp.Win32.user)
- VC++目录-->包含目录,添加:
- D:\opencv3\opencv\Mybuild\install\include
- D:\opencv3\opencv\Mybuild\install\include\opencv
- D:\opencv3\opencv\Mybuild\install\include\opencv2
- VC++目录-->库目录,添加:
D:\opencv3\opencv\Mybuild\install\x86\vc10\lib - 链接器-->输入-->附加依赖项,添加:
opencv_aruco300d.lib
opencv_bgsegm300d.lib
opencv_bioinspired300d.lib
opencv_calib3d300d.lib
opencv_ccalib300d.lib
opencv_core300d.lib
opencv_dnn300d.lib
opencv_face300d.lib
opencv_features2d300d.lib
opencv_flann300d.lib
opencv_highgui300d.lib
opencv_imgcodecs300d.lib
opencv_imgproc300d.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_video300d.lib
opencv_videoio300d.lib
opencv_videostab300d.lib
opencv_xfeatures2d300d.lib
opencv_ximgproc300d.lib
opencv_xobjdetect300d.lib
opencv_xphoto300d.lib
opencv_aruco300.lib
opencv_bgsegm300.lib
opencv_bioinspired300.lib
opencv_calib3d300.lib
opencv_ccalib300.lib
opencv_core300.lib
opencv_dnn300.lib
opencv_face300.lib
opencv_features2d300.lib
opencv_flann300.lib
opencv_highgui300.lib
opencv_imgcodecs300.lib
opencv_imgproc300.lib
opencv_line_descriptor300.lib
opencv_ml300.lib
opencv_objdetect300.lib
opencv_optflow300.lib
opencv_photo300.lib
opencv_reg300.lib
opencv_rgbd300.lib
opencv_saliency300.lib
opencv_shape300.lib
opencv_stereo300.lib
opencv_stitching300.lib
opencv_superres300.lib
opencv_surface_matching300.lib
opencv_video300.lib
opencv_videoio300.lib
opencv_videostab300.lib
opencv_xfeatures2d300.lib
opencv_ximgproc300.lib
opencv_xobjdetect300.lib
opencv_xphoto300.lib
五、遇到相关问题及解决方法
1.在cmake第二次进行编译时候,可能出现了cmake报错:
-- ICV: Downloading ippicv_windows_20140513.tgz... CMake Error at 3rdparty/ippicv/downloader.cmake:71 (file): file DOWNLOAD HASH mismatch for file: [/tmp/dpkg-mkdeb.NSafYgjHYT/src/opencv-3.0.0-alpha/3rdparty/ippicv/downloads/linux-d80cb24f3a565113a9d6dc56344142f6/ippicv_linux_20140513.tgz] expected hash: [d80cb24f3a565113a9d6dc56344142f6] actual hash: [20d82f68c11c137093b960677093fdac] Call Stack (most recent call first): 3rdparty/ippicv/downloader.cmake:108 (_icv_downloader) cmake/OpenCVFindIPP.cmake:212 (include) cmake/OpenCVFindLibsPerf.cmake:12 (include) CMakeLists.txt:449 (include)
这种情况就可以在http://sourceforge.net/projects/opencvlibrary/files/3rdparty/ippicv/ 网站手动下载ippicv压缩包,放到D:\opencv3\opencv\sources\3rdparty\ippicv\downloads\windows-b59f865d1ba16e8c84124e19d78eec57 文件夹中,然后再重新编译cmake。
六、参考资料
【1】https://github.com/Itseez/opencv_contrib/blob/master/README.md 这个是用cmake-gui编译opencv_contrib的英文说明文档。
【2】http://segmentfault.com/a/1190000003496009 poemqiong 博主的opencv_contrib文章参考
【3】http://stackoverflow.com 可以在国外的这个论坛上寻找你遇到各种安装问题,一般解答都挺有效的。