Jovan Slavujević
Jovan Slavujević

Reputation: 31

How to link OpenCV 4 with ROS (cv_bridge)

I'm using OpenCV in ROS Melodic, I need now to use cv::dnn (deep neural network), which is incluced in OpenCV 4, which I have installed, and set it to my CMakeLists.txt like this:

find_package(OpenCV 4 REQUIRED )

this is warning that I'm getting when I do command: catkin_make in my ros workspace:

/usr/bin/ld: warning: libopencv_imgcodecs.so.3.2, needed by /opt/ros/melodic/lib/libcv_bridge.so, may conflict with libopencv_imgcodecs.so.4.1

I ignored that but I can't rosrun any node with opencv right now.

Can someone help me how to set OpenCV 4 in cv_bridge (ROS melodic system)?

Thanks in advance. Best Regards, Jovan.

Upvotes: 2

Views: 9493

Answers (2)

Andreas Serov
Andreas Serov

Reputation: 136

A simple solution is to download a suitable version of vision_opencv from https://github.com/ros-perception/vision_opencv/releases. Then extract the contents (containing some packages cv_bridge image_geometry opencv_tests vision_opencv) to a folder called vision_opencv of your src folder in your catkin workspace.

Now catkin_make or catkin build your workspace and the necessary ros opencv packages will compile and link against the local vision_opencv folder. You might need to clean your workspace before that.

Upvotes: 0

unlut
unlut

Reputation: 3775

There is an opencv shipped with ROS which is used for image related stuff. Some ROS packages such as cv_bridge, image_geometry etc. use this opencv by default. This is the reason you get segmentation fault because different opencv versions are storing image in different formats.

If you want to use a custom opencv within your node, you must include these packages in your working directory and compile them also. For example, you must include cv_bridge source code in your node's cmakelist.

Upvotes: 3

Related Questions