简体   繁体   中英

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.

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 includecv_bridge source code in your node's cmakelist.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM