1、报错信息
首先catkin_make编译功能包没有任何问题,100%生成目标文件,但是报了警告:库文件libmyslam.so需要的是libopencv_core.so.3.4,可能会与libopencv_core.so.3.2冲突。根据工程经验,警告不用管,直接运行完事。
[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
roscore、rosrun之后出现核心已转储的报错。查找报错分析是cv_bridge默认调用的是ros自带的OpenCV版本3.2.0,我本地安装的是OpenCV3.4.5,在功能包下的CMakeLists.txt中找的package也是3.4.5,所以导致cv_bridge报错。
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、解决方法
1、首先,需要下载cv_bridge工程,只需要其中的cv_bridge
文件夹。
2、放到你的工程src目录下,它就相当于一个功能包。
修改cv_bridge/CMakeLists.txt文件中工程的名称:
project(cv_bridge) 改为 project(cv_bridge_1)
修改cv_bridge/package.xml中的包名称:
<name>cv_bridge</name> 改为 <name>cv_bridge_1</name>
修改cv_bridge/CMakeLists.txt文件中需要的OpenCV版本,改成你本地的版本:
find_package(OpenCV 3.4.5 REQUIRED
COMPONENTS
opencv_core
opencv_imgproc
opencv_imgcodecs
CONFIG
)
3、然后在你的工程根目录/src下进行catkin_make编译功能包。
4、在devel/lib目录下会生成libcv_bridge_1.so文件,这就是我们需要的库文件,它现在用的不再是ros自带的OpenCV了。
我们在自己的功能包下新建lib目录,放入上面这个libcv_bridge_1.so
共享库,然后在include中放入cv_bridge
的头文件。
5、开始重中之重——修改自己的功能包下的CMakeLists.txt。
- 去掉原先查找的cv_bridge库。
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
sensor_msgs
image_transport
message_generation
)
- 添加头文件路径include
include_directories(
include
${catkin_INCLUDE_DIRS}
)
- 包含目录lib
link_directories(
lib
${catkin_LIB_DIRS}
)
- 链接库文件libcv_bridge_1.so
target_link_libraries(run_vo
${catkin_LIBRARIES}
${OpenCV_LIBS}
libcv_bridge_1.so
)
6、重新catkin_make,然后rosrun即可成功运行,再无核心转储的报错。
探索了1小时,试了多种方法,最后总结出自己的一套方法。