Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Using cmake to find OpenCV version

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?