xdspacelab/openvslam

cmake finds incorrect OpenCV

navid-mahmoudian opened this issue · 0 comments

Hello,
Thank you for providing this very nice library. I have several versions of OpenCV on my computer (3.4.10, 4.3.0, 4.5.1). I want to force the CMake to use OpenCV 4.5.1. For that, I set the OpenCV_DIR to point to the place that OpenCVConfog.cmake exists, but the CMake finds the path related to the older OpenCV 3.4.10 version. I think it is because in your CMakeLists.txt you first check for find_package(OpenCV 3.3.1 QUIET ) and since it already finds version 3.4, it works with this older version. I changed the following part in your CMakeLists.txt


find_package(OpenCV 3.3.1 QUIET
             COMPONENTS
             core imgcodecs videoio features2d calib3d highgui)
if(NOT OpenCV_FOUND)
    find_package(OpenCV 4.0 REQUIRED
                 COMPONENTS
                 core imgcodecs videoio features2d calib3d highgui)
    if(NOT OpenCV_FOUND)
        message(FATAL_ERROR "OpenCV >= 3.3.1 not found")
    endif()
endif()
message(STATUS "Use OpenCV ${OpenCV_VERSION}")

to


find_package(OpenCV REQUIRED
             COMPONENTS
             core imgcodecs videoio features2d calib3d highgui)
message(STATUS "Use OpenCV ${OpenCV_VERSION}")

and now the CMake works perfectly. If you accept this solution, I can make a pull request and also add a version control at the end of the above code to have OpenCV >= 3.3.1.