How to use the OpenCV contrib modules that are installed by apt?

  apt, c++, cmake, opencv

On Ubuntu 20.04 I tried to install and use the OpenCV contrib modules by using sudo apt install libopencv-contrib4.2. The command apt show libopencv-contrib4.2 tell me that

This package contain following contrlib libraries:

...
  • sfm

However, if I try using the module in my projects it doesn’t work.
In CMake find_package(OpenCV 4.2 COMPONENTS sfm REQUIRED) doesn’t work.
Using

find_package(OpenCV 4.2 REQUIRED)
...
target_link_libraries(calibrate_cameras
    ${OpenCV_LIBS}
    stdc++fs
    Boost::program_options
    )
target_include_directories(calibrate_cameras
    PRIVATE
    "include"
    ${OpenCV_INCLUDE_DIRS}
    )

does work, but then when I try to include #include <opencv2/sfm.hpp> it can’t find the header. What am I doing wrong? Do i have to install the Contrib modules from source? And if so, why is there an apt-package that states to install the sfm module?

Source: Windows Questions C++

LEAVE A COMMENT