Ubuntu18.04中OpenCV多版本(OpenCV3.4+OpenCV2.4)

在系统原本有OpenCV3.4的基础上,由于工程需要OpenCV版本为2.x,因此进行了以下安装与踩坑:
1、使用命令查看当前系统的OpenCV版本

pkg-config --modversion opencv

2、下载OpenCV安装包并安装

wget https://github.com/Itseez/opencv/archive/2.4.13.zip
unzip 2.4.13.zip
cd opencv-2.4.13
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local .. 
make
sudo make install

3、常见问题
1.在cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..时出现

CMake Warning at cmake/OpenCVPackaging.cmake:23 (message):
CPACK_PACKAGE_VERSION does not match version provided by version.hpp
header!

解决方式:打开OpenCV2.4.13文件夹中的CMakeList.txt,找到以下部分

if(GIT_EXECUTABLE)
  execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --always --dirty --match "2.[0-9].[0-9]*"
    WORKING_DIRECTORY "${OpenCV_SOURCE_DIR}"
    OUTPUT_VARIABLE OPENCV_VCSVERSION
    RESULT_VARIABLE GIT_RESULT
    ERROR_QUIET
    OUTPUT_STRIP_TRAILING_WHITESPACE
  )
  if(NOT GIT_RESULT EQUAL 0)
    set(OPENCV_VCSVERSION "unknown")
  endif()
else()
  # We don't have git:
  set(OPENCV_VCSVERSION "unknown")
endif()

将其中的set(OPENCV_VCSVERSION "unknown")修改为set(OPENCV_VCSVERSION "2.4.13")即可。

你可能感兴趣的:(opencv,计算机视觉)