Ubuntu16.04安装配置opencv3.4.6+opencv_contrib3.4.6

Ubuntu16.04安装配置opencv3.4.6+opencv_contrib3.4.6

  • 卸载已安装opencv
  • 资源下载
  • 编译与安装

最近在做图像特征匹配,恰好有机会使用opencv的surf模块,试运行测试demo发现没有安装opencv_contrib 模块,于是有了这篇短笔记。参考资源链接:
https://blog.csdn.net/echoamor/article/details/83022352
https://docs.opencv.org/3.4.3/d7/d9f/tutorial_linux_install.html
http://www.cnblogs.com/mar-q/p/7490271.html

卸载已安装opencv

cd release //release是安装opencv时自己创建的存放cmake结果的目录
sudo make uninstall
//删除系统目录中opencv相关的文件和目录
sudo rm -rf /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv*
//再次确保删除usr目录中opencv相关项
cd /usr/
find . -name "*opencv*" | xargs sudo rm -rf
//移除python相关项
sudo apt-get remove opencv-doc opencv-data python-opencv

资源下载

资源链接:https://github.com/opencv
分别在界面中的opencv 和 opencv_contrib 模块下载各自源码,注意二者的版本一定要匹配,版本号在源码界面的Branch下拉单中选择。解压后的opencv_contrib源码可以放在opencv源码所在的目录中,便于管理。

编译与安装

cmake阶段可以通过两种方式实现:cmake-gui实现和代码实现。第一个参考链接中以cmake-gui实现,该笔记仅列出代码实现的方式:

cd release // release是自己创建的存放cmake结果的目录
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_EXTRA_MODULES_PATH=/opencv_contrib路径/modules ..
make -j8
sudo make install

其中, OPENCV_ENABLE_NONFREE这一项要加上,如果使用cmake-gui,同样需要将该项选上,否则在使用opencv_contrib模块时很有可能报与下面类似的错误:

Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function ‘cv::xfeatures2d::SIFT::create’

你可能感兴趣的:(opencv)