vins-fusion环境配置,解决opencv3->4的cv::bridge问题

本文主要介绍如何搭建vins-fusion的运行环境,以及解决vins-fusion编译运行时遇到的环境冲突问题,并在此基础上实现例程的运行。

本文是在已经安装好 ROS 的基础上,在 Ubuntu20.04 系统下,完成 vins-fusion 的环境搭建,主要涉及到 opencv3.4.11、ceres-solver1.14.0、eigen3 的安装,解决了 vins对ros自带的opencv4不兼容 、 ceres对c++的版本要求 、以及一些 常见编译错误 的问题,还解决了运行vins-fusion时出现 ==段错误(核心已转储)==的问题。

解决段错误(核心已转储)

在配置好环境后(配置环境超详细教程),我先用 单目+IMU 的方式跑数据集,命令如下


roslaunch vins vins_rviz.launch
rosrun vins vins_node ~/vins/src/vins-fusion-master/config/euroc/euroc_mono_imu_config.yaml
rosrun loop_fusion loop_fusion_node ~/vins/src/vins-fusion-master/config/euroc/euroc_mono_imu_config.yaml
rosbag play ~/SLAM/test_data/MH_04_difficult.bag

运行到第二条的时候报错:


cam calib path:/home/xwj/vins-fusion/src/VINS-Fusion/config/euroc/camo_mei.yaml
段错误(核心已转储)

第三条会报错:


cam calib path:/home/xwj/vins-fusion/src/VINS-Fusion/config/euroc/camo_mei.yaml
段错误(核心已转储)

这里由于 noetic 的 opencv4 头文件和参数名与 vins-fusion 所使用的 opencv3 不同造成的,需要使用非 ROS Noetic 自带 OPENCV 版本编译工程,通过修改 cv_bridge 配置文件来把 vins-fusion工程链接到 opencv3 库上

首先找到 cv_bridge 配置文件所在位置


cd /opt/ros/noetic/share/cv_bridge/cmake
sudo gedit cv_bridgeConfig.cmake

在94-96行,修改成如下内容


if(NOT "include;/usr/include;/usr/include/opencv " STREQUAL " ")
  set(cv_bridge_INCLUDE_DIRS "")
  set(_include_dirs "include;/usr/include;/usr/local/include/opencv")

修改前为:

vins-fusion环境配置,解决opencv3->4的cv::bridge问题_第1张图片

修改后为:

vins-fusion环境配置,解决opencv3->4的cv::bridge问题_第2张图片

之后将指定库文件也修改为自己安装的opencv库文件,需要对


set(libraries "cv_bridge;/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_dnn.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_features2d.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_flann.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_ml.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_objdetect.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_photo.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_stitching.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_video.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_videoio.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_aruco.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_bgsegm.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_bioinspired.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_ccalib.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_datasets.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_dnn_objdetect.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_dnn_superres.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_dpm.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_face.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_freetype.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_fuzzy.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_hdf.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_hfs.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_img_hash.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_line_descriptor.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_optflow.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_phase_unwrapping.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_plot.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_quality.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_reg.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_rgbd.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_saliency.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_shape.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_stereo.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_structured_light.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_superres.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_surface_matching.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_text.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_tracking.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_videostab.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_viz.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_ximgproc.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_xobjdetect.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_xphoto.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_core.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.4.2.0;/usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.4.2.0")
vins-fusion环境配置,解决opencv3->4的cv::bridge问题_第3张图片

进行修改。

需要把"cv_bridge;…到 …")之间的内容换成自己的库文件,这里如果要一点一点的修改比较麻烦,可以使用 locate命令 来查看自己的库文件,输入Ctrl+Alt+T打开新的一个终端,在命令行输入


locate opencv
vins-fusion环境配置,解决opencv3->4的cv::bridge问题_第4张图片

向下滑动到 /usr/local/lib开头的文件,复制/usr/local/lib/libopencv_calib3d.so到 /usr/local/lib/libopencv_viz.so.3.4.11的全部内容。然后把代码片里面的内容复制下来,将119行(主要是看内容,行数不一定准确,大致在附近)的内容替换掉


set(libraries "cv_bridge;/usr/local/lib/libopencv_calib3d.so;/usr/local/lib/libopencv_calib3d.so.3.4;/usr/local/lib/libopencv_calib3d.so.3.4.11;/usr/local/lib/libopencv_core.so;/usr/local/lib/libopencv_core.so.3.4;/usr/local/lib/libopencv_core.so.3.4.11;/usr/local/lib/libopencv_dnn.so;/usr/local/lib/libopencv_dnn.so.3.4;/usr/local/lib/libopencv_dnn.so.3.4.11;/usr/local/lib/libopencv_features2d.so;/usr/local/lib/libopencv_features2d.so.3.4;/usr/local/lib/libopencv_features2d.so.3.4.11;/usr/local/lib/libopencv_flann.so;/usr/local/lib/libopencv_flann.so.3.4;/usr/local/lib/libopencv_flann.so.3.4.11;/usr/local/lib/libopencv_highgui.so;/usr/local/lib/libopencv_highgui.so.3.4;/usr/local/lib/libopencv_highgui.so.3.4.11;/usr/local/lib/libopencv_imgcodecs.so;/usr/local/lib/libopencv_imgcodecs.so.3.4;/usr/local/lib/libopencv_imgcodecs.so.3.4.11;/usr/local/lib/libopencv_imgproc.so;/usr/local/lib/libopencv_imgproc.so.3.4;/usr/local/lib/libopencv_imgproc.so.3.4.11;/usr/local/lib/libopencv_ml.so;/usr/local/lib/libopencv_ml.so.3.4;/usr/local/lib/libopencv_ml.so.3.4.11;/usr/local/lib/libopencv_objdetect.so;/usr/local/lib/libopencv_objdetect.so.3.4;/usr/local/lib/libopencv_objdetect.so.3.4.11;/usr/local/lib/libopencv_photo.so;/usr/local/lib/libopencv_photo.so.3.4;/usr/local/lib/libopencv_photo.so.3.4.11;/usr/local/lib/libopencv_shape.so;/usr/local/lib/libopencv_shape.so.3.4;/usr/local/lib/libopencv_shape.so.3.4.11;/usr/local/lib/libopencv_stitching.so;/usr/local/lib/libopencv_stitching.so.3.4;/usr/local/lib/libopencv_stitching.so.3.4.11;/usr/local/lib/libopencv_superres.so;/usr/local/lib/libopencv_superres.so.3.4;/usr/local/lib/libopencv_superres.so.3.4.11;/usr/local/lib/libopencv_video.so;/usr/local/lib/libopencv_video.so.3.4;/usr/local/lib/libopencv_video.so.3.4.11;/usr/local/lib/libopencv_videoio.so;/usr/local/lib/libopencv_videoio.so.3.4;/usr/local/lib/libopencv_videoio.so.3.4.11;/usr/local/lib/libopencv_videostab.so;/usr/local/lib/libopencv_videostab.so.3.4;/usr/local/lib/libopencv_videostab.so.3.4.11;/usr/local/lib/libopencv_viz.so;/usr/local/lib/libopencv_viz.so.3.4;/usr/local/lib/libopencv_viz.so.3.4.11")

之后,重新编译即可

运行VINS

Monocualr camera + IMU


roslaunch vins vins_rviz.launch
rosrun vins vins_node ~/vins-fusion/src/VINS-Fusion/config/euroc/euroc_mono_imu_config.yaml
rosrun loop_fusion loop_fusion_node ~/vins-fusion/src/VINS-Fusion/config/euroc/euroc_mono_imu_config.yaml
rosbag play ~/SLAM/test_data/MH_04_difficult.bag
vins-fusion环境配置,解决opencv3->4的cv::bridge问题_第5张图片
vins-fusion环境配置,解决opencv3->4的cv::bridge问题_第6张图片

最终效果:vins-fusion 上跑单目+imu数据集

vins-fusion环境配置,解决opencv3->4的cv::bridge问题_第7张图片

你可能感兴趣的:(vins_fusion,ubuntu,linux,c++)