Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Ok, thank you it helps me to understand what happened:

There was effectively a conflict between my system opencv version (3.2) and the sources (4.3.0) I wanted to build. I just set the CMAKE_IGNORE_PATH variable correctly to avoid this conflict, so rebuild OpenCV in my catkin_isolated_ws with:

catkin_make_isolated -DWITH_OPENCL=ON -DWITH_V4L=ON -DCMAKE_IGNORE_PATH=/usr/lib/x86_64-linux-gnu;/usr/include -DOPENCV_EXTRA_MODULES_PATH=../../../src/OpenCV/opencv_contrib/modules -DBUILD_EXAMPLES=ON --pkg OpenCV --install

Note: If someone is interested to use recent OpenCV version with ROS, you can find bellow step-by-step procedure to achieve it (this is the procedure I used to use OpenCV 4.3.0 with ros melodic which normally depends on OpenCV 3.2. Note that ROS packages installed via apt-get still depend on OpenCV 3.2. OpenCV 4.3.0 is used only for custom package build in the catkin_ws):

  1. Create a catkin_isolated_ws:
  2. check no ros env is sourced

    env | grep PATH
  3. create isolated workspace and clone sources:

    mkdir -p  ~/catkin_isolated_ws/src
    cd ~/catkin_isolated_ws/src
    git clone --branch 4.3.0 OpenCV
    cd OpenCV
    git clone --branch 4.3.0 opencv_contrib
  4. create a package.xml with the following content:

        <description>Open CV library for catkin</description>
        <maintainer email="your-email">your-name</maintainer>
  5. Source ROS and init workspace:

    source /opt/ros/melodic/setup.bash
  • build and add the eventual opencv system's version to the cmake ignore path (CMAKE_IGNORE_PATH) (to avoid conflict with xfeatures2d):

    cd ~/catkin_isolated_ws/
    catkin_make_isolated -DWITH_OPENCL=ON -DWITH_V4L=ON -DCMAKE_IGNORE_PATH=/usr/lib/x86_64-linux-gnu;/usr/include -DOPENCV_EXTRA_MODULES_PATH=../../../src/OpenCV/opencv_contrib/modules -DBUILD_EXAMPLES=ON --pkg OpenCV --install
    1. Create a catkin_ws layer for packages we want to depend on OpenCV 4.3.0:
    mkdir -p  ~/catkin_ws/src
    cd ~/catkin_ws/src
    source ~/catkin_isolated_ws/install_isolated/setup.bash
    cd ~/catkin_ws
    source ~/catkin_ws/devel/setup.bash
    1. Now we can build ROS packages depending on OpenCV, the first found version will be the one of catkin_isolated_ws which hides the /opt/ros/melodic one which also hides the OpenCV system's version (3.2 for me)

Note: You may have conflicts with ROS package cv_bridge, as it is linked against ros's opencv version (OpenCV 3.2), so you can:

  • build in the catkin_ws your own cv_bridge from sources which will then be build against OpenCV 4.3.0 (to hide native ros cv_bridge package linked to 3.2)

  • or convert ROS sensor_msgs::Image by your own to openCV format