I have multiple versions of OpenCV installed, and CMake is finding the wrong one. I have installed opencv and opencv3 using brew, and they exist in the following paths:
/usr/local/opt/opencv3
/usr/local/opt/opencv
My CMakeLists.txt looks like the following:
cmake_minimum_required(VERSION 2.8)
set(ENV{OpenCV_DIR} "/usr/local/opt/opencv3")
project(TestProject)
#OpenCV
find_package( OpenCV 3 REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
MESSAGE ( STATUS "Found OpenCV: ${OpenCV_VERSION}" )
MESSAGE ( STATUS "OpenCV_INCLUDE_DIRS= ${OpenCV_INCLUDE_DIRS}" )
MESSAGE ( STATUS "OpenCV_DIR= $ENV{OpenCV_DIR}" )
I am using OpenCV_DIR to point to the location of the OpenCV that I would like to use (in this example it's set immediately before just to be 100% certain that this variable points to the right place).
My output is this:
-- Found OpenCV: 3.0.0
-- OpenCV_INCLUDE_DIRS= /usr/local/include/opencv
-- OpenCV_DIR= /usr/local/opt/opencv3
So, it's finding the right version of OpenCV (3.0.0), but the include path is set to some other opencv, in this case /usr/local/include/opencv points to /usr/local/opt/opencv, which is the 2.4.8 version.
As a result, none of my programs find the right files to include! Does anyone know how to tell CMake which version to look for, if the OpenCV_DIR environment variable does not seem to work?
You can explicitly assign the path in find_package
. For example,
find_package( OpenCV 3 REQUIRED PATHS "/usr/local/opt/opencv3" )
As indicated OP is using cMake V2.8. Therefore the following applies to include your desired directory.
#OpenCV
find_package( OpenCV 3 REQUIRED )
include_directories([BEFORE] "/usr/local/opt/opencv3") # your cv2 desired folder
# stated here.
The [BEFORE]
argument informs cMake about this particular folder to use first rather than the other CV folder.
For cMake higher than v2.8 you should not use the include_directories
but rather the following:
target_include_directories(test PRIVATE ${YOUR_DIRECTORY})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With