ubuntu14下opencv2和opencv3共存

Posted lizhongpingchn

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ubuntu14下opencv2和opencv3共存相关的知识,希望对你有一定的参考价值。

ubuntu14.04,之前已经安装了OpenCV2(默认的安装路径是/usr/local),现在需要安装OpenCV3.2,但是又不想将opencv2删除

1.首先,下载好opencv3.2(download: https://github.com/opencv/opencv/archive/3.2.0.zip)后,将源码解压

2.修改CMakeLists.txt文件

将默认的安装路径:/usr/local修改为你要安装的路径
set(CMAKE_INSTALL_PREFIX "/home/alan/slambook/opencv3" CACHE PATH "Installation Directory")

3.编译

cmake .. make make install
在指定安装的路径下找到对应的头文件和库
4.
如何在工程中加入opencv3.2的库和头文件。
这里需要改变一下,否则很容易链接到位于/usr/local下的opencv2。在工程文件中的CMakeLists.txt加上:

set(OpenCV_DIR "/home/ubuntu/src/opencv-3.1.0/build")

来重新制定opencv的安装路径,因为安装opencv2时已经生成了系统变量
OpenCV_DIR = /usr/local/share/opencv,所以需要用set来改变这个变量的值,新的路径为与文件OpencvConfig.cmake路径相同。

cmake_minimum_required( VERSION 2.8 )
project( loop_closure )

set( CMAKE_BUILD_TYPE "Release" )
set( CMAKE_CXX_FLAGS "-std=c++11 -O3" )

# opencv 
set(OpenCV_DIR "/home/lzp/software/opencv-3.2.0/build")
find_package(OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
message(STATUS "    version: ${OpenCV_VERSION}") 

# dbow3 
# dbow3 is a simple lib so I assume you installed it in default directory 
set( DBoW3_INCLUDE_DIRS "/usr/local/include" )
set( DBoW3_LIBS "/usr/local/lib/libDBoW3.a" )

add_executable( feature_training feature_training.cpp )
target_link_libraries( feature_training ${OpenCV_LIBS} ${DBoW3_LIBS} )

add_executable( loop_closure loop_closure.cpp )
target_link_libraries( loop_closure ${OpenCV_LIBS} ${DBoW3_LIBS} )

add_executable( gen_vocab gen_vocab_large.cpp )
target_link_libraries( gen_vocab ${OpenCV_LIBS} ${DBoW3_LIBS} )

以上是关于ubuntu14下opencv2和opencv3共存的主要内容,如果未能解决你的问题,请参考以下文章

opencv2已有的情况下,安装opencv3以及对应的opencv_contrib

ubuntu16.04安装opencv2.4.10过程中的问题

Ubuntu14.04安装opencv3.1和opencv3.3

ubuntu14.04下安装cudnn5.1.3,opencv3.0,编译caffe及matlab和python接口过程记录

在 Ubuntu 14.04 上从源代码编译时如何链接到 opencv 3.0?

ubuntu14.04下PyCharm使用OPenCV2.4.11