码迷,mamicode.com
首页 > 系统相关 > 详细

ubuntu14下opencv2和opencv3共存

时间:2018-02-21 23:35:17      阅读:914      评论:0      收藏:0      [点我收藏+]

标签:required   rar   min   cpp   imp   directory   tor   imu   /usr   

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共存

标签:required   rar   min   cpp   imp   directory   tor   imu   /usr   

原文地址:https://www.cnblogs.com/lizhongpingchn/p/7868126.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!