Maintaining Different Version of OpenCV

Saurav Solanki
1 min readJul 11, 2021

Sometimes in a project, we need to maintain different version of OpenCV and link to it in organised way. This can be template for your cmake project.

cmake_minimum_required(VERSION 3.1)

project( DisplayImage )

# Enable C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

# For OpenCV 4
SET(OpenCV_DIR <current-path>/OpenCV-master/lib/cmake/opencv4)

# For OpenCV 3
# SET(OpenCV_DIR "<current-path>/opencv3.4.8/installation/OpenCV-3.4.8/share/OpenCV/")

# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")

find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage main.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )

I have detailed explained the instalation and running an example using OpenCV C++ here.

If you like it, please give it a clap.

References:

  1. https://github.com/opencv/opencv/blob/master/CMakeLists.txt
  2. https://docs.opencv.org/4.5.2

--

--