ROS comes with OpenCV and local OpenCV version conflict resolution

1. Error message

First, there is no problem with catkin_make compiling the function package, and 100% of the target files are generated, but a warning is reported: the library file libmyslam.so requires libopencv_core.so.3.4, which may conflict with libopencv_core.so.3.2. According to engineering experience, ignore the warning and run it directly.

[100%] Linking CXX executable /home/dzh/Demo/VO/devel/lib/ros_vo/run_vo
/usr/bin/ld: warning: libopencv_core.so.3.4, needed by /home/dzh/Demo/VO/src/ros_vo/lib/libmyslam.so, may conflict with libopencv_core.so.3.2
/usr/bin/ld: warning: libopencv_imgcodecs.so.3.4, needed by /usr/local/lib/libopencv_highgui.so.3.4.5, may conflict with libopencv_imgcodecs.so.3.2
/usr/bin/ld: warning: libopencv_imgproc.so.3.4, needed by /usr/local/lib/libopencv_highgui.so.3.4.5, may conflict with libopencv_imgproc.so.3.2
[100%] Built target run_vo

After roscore and rosrun, there is an error that the core has been dumped. The error analysis of the search is that cv_bridge calls the OpenCV version 3.2.0 that comes with ros by default. I installed OpenCV3.4.5 locally, and the package found in the CMakeLists.txt under the function package is also 3.4.5, so cv_bridge reports an error.

OpenCV Error: Bad argument (Unknown interpolation method) in resize, 
file /build/opencv-L2vuMj/opencv-3.2.0+dfsg/modules/imgproc/src/imgwarp.cpp, line 3367
terminate called after throwing an instance of 'cv::Exception'
what():  /build/opencv-L2vuMj/opencv-3.2.0+dfsg/modules/imgproc/src/imgwarp.cpp:3367: 
error: (-5) Unknown interpolation method in function resize
已放弃 (核心已转储)

2. Solution

1. First, you need to download the cv_bridge project, only cv_bridgethe folders in it.

insert image description here2. Put it in the src directory of your project, it is equivalent to a function package.

Modify the name of the project in the cv_bridge/CMakeLists.txt file:

project(cv_bridge)   改为   project(cv_bridge_1) 

Modify the package name in cv_bridge/package.xml:

 <name>cv_bridge</name>  改为  <name>cv_bridge_1</name>

Modify the OpenCV version required in the cv_bridge/CMakeLists.txt file to your local version:

find_package(OpenCV 3.4.5 REQUIRED
  COMPONENTS
    opencv_core
    opencv_imgproc
    opencv_imgcodecs
  CONFIG
)

3. Then execute catkin_make to compile the function package in your project root directory/src.

insert image description here
4. The libcv_bridge_1.so file will be generated in the devel/lib directory. This is the library file we need. It no longer uses the OpenCV that comes with ros.

insert image description here
We create a new lib directory under our own function package, put the above shared library, and then put the header file libcv_bridge_1.soin include .cv_bridge

insert image description here
5. Start the most important thing - modify the CMakeLists.txt under your own function package.

  • Remove the previously searched cv_bridge library.
find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  sensor_msgs
  image_transport 
  message_generation
)
  • Add header file path include
include_directories(
  include
  ${
    
    catkin_INCLUDE_DIRS}
)
  • Include directory lib
link_directories(
  lib
  ${
    
    catkin_LIB_DIRS}
)
  • Link library file libcv_bridge_1.so
target_link_libraries(run_vo
  ${
    
    catkin_LIBRARIES}
  ${
    
    OpenCV_LIBS}
  libcv_bridge_1.so
)

6. Re-catkin_make, and then rosrun can run successfully, and there is no core dump error.

insert image description here

After exploring for an hour and trying various methods, I finally summed up my own set of methods.

Guess you like

Origin blog.csdn.net/qq_42257666/article/details/131450279