Coexistence of Opencv2 and Opencv3 under UBUNTU14

Source: Internet
Author: User

ubuntu14.04, you have installed OpenCV2 (the default installation path is/usr/local) and now you need to install OpenCV3.2, but you do not want to remove Opencv2

1. First, after downloading the good opencv3.2 (download: https://github.com/opencv/opencv/archive/3.2.0.zip), unzip the source code

2. Modify the CMakeLists.txt file

Change the default installation path:/usr/local to the path you want to install
set(CMAKE_INSTALL_PREFIX "/home/alan/slambook/opencv3" CACHE PATH "Installation Directory")

3. Compiling

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

Set (Opencv_dir "/home/ubuntu/src/opencv-3.1.0/build")

< Span class= "hljs-built_in" > was generated when the OPENCV2 was installed opencv_dir =/USR/LOCAL/SHARE/OPENCV, so it is necessary to use set to change the value of this variable, the new path is the same as the file Opencvconfig.cmake path.

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 the it in default directory set (dbow3_include_dirs "/usr/local/include") Set (dbow3_libs "/usr/local/l Ib/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})

Coexistence of Opencv2 and Opencv3 under UBUNTU14

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.