Using cmake to find OpenCV version

asked 2016-02-17 00:43:48 -0500

liquidmetal gravatar image

I'm trying to update the cmakefile for another project that depends on OpenCV. What's a good way to identify the correct OpenCV version across multiple platforms? I just need to figure out if OpenCV 3 is available on the current machine or not. Any hints or ideas on how to do this would be useful!

Here's a summary of what I'm trying to accomplish:

  • run locate libopencv_imgcodecs | head -n 1 | wc -l
  • If this command returns 0, assume OpenCV is installed (I know this is potentially a bad assumption)
  • If the command returns a non-zero number, set OpenCV version to 3.
  • Set the variable OPENCV_VERSION based on this.

I don't feel too good about running the shell command (locate, etc).. is there a better way to do this?

edit retag flag offensive close merge delete

Comments

2

IMHO you should

  1. search the lib: find_package(OpenCV REQUIRED)
  2. and then check the version with if(NOT "${OPENCV_VERSION}" STREQUAL "3")̀ ...

For better understanding you can print the version with message(OPENCV_VERSION)

thdrksdfthmn gravatar imagethdrksdfthmn ( 2016-02-17 05:09:39 -0500 )edit
1

find_package requires this additional file code.opencv.org/attachments/196/FindOpenCV.cmake. This requires that I set the variable OpenCV_DIR. Is there a way to locate OpenCV without setting this variable?

liquidmetal gravatar imageliquidmetal ( 2016-02-17 20:26:00 -0500 )edit

I suppose It is hard to do a CMake check if you did not installed the lib with CMake... does this help you?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2016-02-18 03:24:00 -0500 )edit