Ubuntu14.04 ROS自带opencv2.4.8和opencv3.1多版本共存

        由于在安装ROS时自带的版本是opencv2.4.8的,这几天调试程序需要使用opencv3.1.0的版本,这就需要opencv多版本的共存,在网上搜集了很多资料,结合自己安装的过程记录一下:     

使用命令查看当前的opencv版本:

pkg-config --modversion opencv 

ROS系统自带的是opencv-2.4.8

安装opencv3.1
–首先下载新版本的opencv安装包,之后解压,安装opencv的依赖项。

1、从OpenCV官网上下载OpenCV官网上下载OpenCV的未编译源代码:opencv官网下载

2、国内很多网络打开OpenCV官网速度缓慢,可以点击如下地址直接从GitHub上下载OpenCV 3.1的源代码:giuhub地址

sudo apt-get install build-essential libgtk2.0-dev libvtk5-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev libtbb-dev  

–进入解压后的opencv安装包,新建目录,目录名为build,并进入该目录

mkdir build && cd build 

输入命令

cmake -D CMAKE_BUILD_TYPE=RELEASE -D WITH_TBB=ON  -D WITH_V4L=ON -D CMAKE_INSTALL_PREFIX=/usr/local/opencv310 ..  
make 
sudo make install  
在这里,我将opencv3.1的安装目录放在了/usr/local/opencv310文件夹

紧接着需要配置下文件,通过修改bashrc文件来设置PKG_ CONFIG_PATH(后来发现好像还需要改一下LD_LIBRARY_PATH)

sudo gedit ~/.bashrc 

在文件末尾加上

 export PKG_CONFIG_PATH=/usr/local/opencv310/lib/pkgconfig  
 export LD_LIBRARY_PATH=/usr/local/opencv310/lib  

保存之后,再使用命令

source ~/.bashrc  

这时候使用  

pkg-config --modversion opencv命令,opencv版本已经变成3.1了

配置
当你使用的是cmake工具时,在Cmakelist中加入路径即可使用opencv3.1,当你想返回使用opencv2时,将 find_package(OpenCV 3.1 REQUIRED )换成 find_package(OpenCV REQUIRED )即可,其余删除。

#find_package(OpenCV REQUIRED)      #使用opencv2
cmake_minimum_required(VERSION 2.8)   #要求>2.8的版本
set(OpenCV_DIR /usr/local/opencv310/share/OpenCV)
find_package( OpenCV 3.1 REQUIRED )    #使用opencv3.1
#if(NOT OpenCV_FOUND)
#   find_package(OpenCV 3.1.0 QUIET)
#   if(NOT OpenCV_FOUND)
#      message(FATAL_ERROR "OpenCV > 3.0.0 not found.")
#   endif()
#endif()

include_directories(${OpenCV_INCLUDE_DIRS} /usr/local/opencv310/include)
find_package( "/usr/local/opencv310/include/opencv2" )
include_directories(${OpenCV_LIBRARY_DIRS} /usr/local/opencv310/lib)

如果需要卸载OpenCV,执行:

make uninstall
cd ..
sudo rm -r build
sudo rm -r /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*

平时的小问题:报错:[Error] ‘setprecision’ is not a member of ‘std’

解决:需要加上头文件 便可通过编译 :

#include 
#include 


你可能感兴趣的:(opencv)