ORBSLAM2 运行记录
运行记录
1、源码下载下来后 ,首先执行:./build.sh 进行编译
2、 (这一步不是必须)进入Examples/ROS文件夹 ,为ROS包重新命一个自己喜欢的名字 ,保持原来的名字ORBSLAM2也可以,这样是为了以后有多个ORBSLAM2版本代码时可以很方便的切换要运行的版本。
3、进入~/.bashrc文件,加入ROS包的路径
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/home/lwh/catkin_ws/src/ORB_SLAM2_lwh/Examples/ROS/lwh_ORB_SLAM2
source ~/.bashrc
一定要记得source!
3、使用ROS: 直接执行 ./build_ros.sh
进行编译 ,但是发现问题-
后面查询资料发现,出错原因为:libboost_system.so 与libboost_filesystem.so找不到链接目录 ,参考下面链接的说明 ,编译成功。
https://blog.csdn.net/sinat_38343378/article/details/78883919
但是,随后正常运行可执行文件的时候却发现下面的错误:
1、无法打开参数文件
Failed to open settings file at: Examples/ROS/Raw_ORB_SLAM2/Asus.yaml
2、OpenCV Error: Bad argument (Invalid pointer to file storage) in cvGetFileNodeByName, file /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/core/src/persistence.cpp, line 861
terminate called after throwing an instance of ‘cv::Exception’
what(): /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/core/src/persistence.cpp:861: error: (-5) Invalid pointer to file storage in function cvGetFileNodeByName
然后 检查执行文件的库链接情况发现,执行文件同时连接了opencv2.4 与 opencv3.3
执行命令:ldd Mono | grep opencv
窗口输出:
libopencv_calib3d3.so.3.3 => /opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_calib3d3.so.3.3 (0x00007fcd2f961000)
libopencv_highgui3.so.3.3 => /opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_highgui3.so.3.3 (0x00007fcd2f720000)
libopencv_objdetect3.so.3.3 => /opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_objdetect3.so.3.3 (0x00007fcd2f1ac000)
libopencv_core3.so.3.3 => /opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_core3.so.3.3 (0x00007fcd2e272000)
libopencv_imgcodecs3.so.3.3 => /opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3 (0x00007fcd2bf1d000)
libopencv_imgproc3.so.3.3 => /opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgproc3.so.3.3 (0x00007fcd2931f000)
libopencv_calib3d.so.2.4 => /usr/local/lib/libopencv_calib3d.so.2.4 (0x00007fcd27bb9000)
libopencv_features2d.so.2.4 => /usr/local/lib/libopencv_features2d.so.2.4 (0x00007fcd27912000)
libopencv_highgui.so.2.4 => /usr/local/lib/libopencv_highgui.so.2.4 (0x00007fcd275c1000)
libopencv_imgproc.so.2.4 => /usr/local/lib/libopencv_imgproc.so.2.4 (0x00007fcd270bc000)
libopencv_core.so.2.4 => /usr/local/lib/libopencv_core.so.2.4 (0x00007fcd26c1e000)
libopencv_features2d3.so.3.3 => /opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_features2d3.so.3.3 (0x00007fcd2693c000)
libopencv_flann3.so.3.3 => /opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_flann3.so.3.3 (0x00007fcd266e2000)
libopencv_flann.so.2.4 => /usr/local/lib/libopencv_flann.so.2.4 (0x00007fcd214c9000)
然后经过网上查找解决方案才知道,这是因为,ROS中是通过的cv_bridge与OPENCV库连接的,而
cv_bridge是与ROS自带的OPENCV3.3连接,而本人电脑中安装的OPENCV版本是2.4的,编译ORBSLAM2生成libORB_SLAM2.so时连接 的是opencv2.4,于是导致了冲突。本人的解决方案是,
在保留之前安装的OPENCV 2.4的情况下在电脑上再安装一个OPENCV 3,然后编译ORBSLAM2的时候使用OPENCV3 ,这样最后在ROS下编译时产生的执行文件连接的就都是OPENCV3了,也就避免了冲突。
修改方案如下:
在安装好OPENCV3后,修改ORB-SLAM2/CMakeLists.txt,将自己安装opencv3库的路径设置到OpenCV_DIR中,如下
set(OpenCV_DIR /usr/local/opencv3/share/OpenCV)
这样后面使用的就是OPENCV 3了。
清理完build文件与删除libORB_SLAM2.so后重新编译,再执行./build_ros.sh,就能顺利运行了。
使用RGBD xtion相机在ROS下运行ORBSLAM2
1、下载驱动
sudo apt-get install ros-kinetic-rgbd-launch ros-kinetic-openni2-camera ros-kinetic-openni2-launch
2、启动相机
roslaunch openni2_launch openni2.launch
3、启动ORBSLAM2
rosrun ORB_SLAM2 RGBD Vocabulary/ORBvoc.txt Examples/ROS/ORB_SLAM2/Asus.yaml