2

I want to use OpenCV 3 through CMakeLists.txt, and the CMakeLists.txt is as following:

set(OpenCV_ROOT /usr/local/opencv3)
set(OpenCV_INCLUDE_DIRS ${OpenCV_ROOT}/include)
set(OpenCV_LIBRARIES "${OpenCV_ROOT}/lib")
message("find ${OpenCV_INCLUDE_DIRS}")
.....
include_directories(${OpenCV_INCLUDE_DIRS}) 
target_link_libraries(main ${OpenCV_LIBRARIES})

find OpenCV in: /usr/local/include/opencv;/usr/local/include

But the path of OpenCV 3 is /usr/local/opencv3. It seems that the specified paths didn't work, and CMakeLists.txt use the default opencv 2.4 instead of OpenCV 3.

How to solve this problem? I have worked on it all day.

Rhapsody
  • 77
  • 1
  • 5
  • You forgot to show `find_package()` call in your code. Have you clean build directory (or, at least, `CMakeCache.txt` file) before attempt to find OpenCV at new place? Which `FindOpenCV.cmake` script do you use? The script determines the ways for specifying non-default location of OpenCV. If you don't use `FindOpenCV.cmake` script, then ways for specify package's location includes: 1. Setting `OpenCV_DIR` variable. 2. Setting `CMAKE_PREFIX_PATH` variable. 3. Specifying *PATHS* option for `find_package()` call. – Tsyvarev Dec 06 '17 at 12:38
  • 1
    Thanks! I deleted CMakeCache.txt and CMakeFiles, and tried using find_package(OpenCV PATHS=/usr/local/opencv3), but it cannot solve my question. Then I tried set(OpenCV_DIR /usr/local/opencv3), still cannot solve. "/usr/local/opencv3" is the path where I installed my opencv3 in. – Rhapsody Dec 06 '17 at 13:10
  • Correct: `find_package(OpenCV PATHS /usr/local/opencv3)` (there is no equal sign). This will work if you don't use `FindOpenCV.cmake` script. Do not forget to clear cache again. – Tsyvarev Dec 06 '17 at 13:20

1 Answers1

0

If you built from the source the only thing you need to do is to add the variable to your .bashrc file like here.

export PATH=$PATH:~/installation/OpenCV

and your CMakeLists.txt will find it

Oscar Rangel
  • 848
  • 1
  • 10
  • 18