ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The Debian package libopencv-dev installs a cmake project config file. It sets CMake variables after find(OpenCV) is called.

$ dpkg -L libopencv-dev | grep cmake
/usr/lib/x86_64-linux-gnu/cmake
/usr/lib/x86_64-linux-gnu/cmake/opencv4
/usr/lib/x86_64-linux-gnu/cmake/opencv4/OpenCVConfig-version.cmake
/usr/lib/x86_64-linux-gnu/cmake/opencv4/OpenCVConfig.cmake
/usr/lib/x86_64-linux-gnu/cmake/opencv4/OpenCVModules-release.cmake
/usr/lib/x86_64-linux-gnu/cmake/opencv4/OpenCVModules.cmake

Have a look inside the main one

$ vim /usr/lib/x86_64-linux-gnu/cmake/opencv4/OpenCVConfig.cmake

A CMake variable that looks interesting is OpenCV_INSTALL_PATH.

#    Advanced variables:
#      - OpenCV_SHARED                   : Use OpenCV as shared library
#      - OpenCV_INSTALL_PATH             : OpenCV location
#      - OpenCV_LIB_COMPONENTS           : Present OpenCV modules list
#      - OpenCV_USE_MANGLED_PATHS        : Mangled OpenCV path flag

On Ubuntu Focal with OpenCV4 it resolves to /usr/, so one might think the path to the classifier is

${OpenCV_INSTALL_PATH}/share/opencv4/haarcascades/haarcascade_frontalface_alt.xml

However, Debian Buster with OpenCV 3.2 it's a different path

/usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml

It looks like just the directory in share is different. That should be solvable with file(GLOB ...)

file(GLOB haarcascade_file_path "${OpenCV_INSTALL_PATH}/share/*/haarcascades/haarcascade_frontalface_alt.xml")

Then you can use CMake configure_file to generate classifier.yaml from a new classifier.yaml.in file

 classifier_filename: ${haarcascade_file_path}

and the CMake

configure_file(classifier.yaml.in classifier.yaml)

The generated file is in CMAKE_CURRENT_BINARY_DIR, so you'll need to install it to the param folder from the build folder

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/classifier.yaml"
        DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/param
)