github安装https://github.com/raulmur/ORB_SLAM2
首先需要安装Ubuntu系统,并安装好ros,ros安装可参考https://blog.csdn.net/weixin_48953899/article/details/107640581再安装基本工具vim、cmake、git、gcc、g++、opencv,这些安装都非常简单,可以自行安装不再一一赘述。
sudo apt-get install libboost-all-dev libblas-dev liblapack-dev
创建工作空间orbslam_ws在此空间内安装,eigen3.2、g2o、DBoW2、Pangolin。
2.1安装eigen3.2
下载源码包https://eigen.tuxfamily.org/index.php?title=Main_Page
解压缩
mkdir build (在解压后的目录中执行)
cd build
cmake ..
make
sudo make install
2.2安装g2o
下载源码包
解压缩
mkdir build
cd build
cmake ..
-DCMAKE_BUILD_TYPE=Release
make
sudo make install
2.3安装DBoW2、Pangolin
下载代码源后与g2o安装一样此处不再赘述,代码源百度都有官网
cd ~orbslam_ws/src
git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
cd ORB_SLAM2
打开ORB_SLAM2中的build.sh文件,将所有的make -j改为make,之后修改文件权限并运行编译:
chmod +x build.sh
./build.sh
登录http://vision.in.tum.de/data/datasets/rgbd-dataset/download,下载freiburg1_xyz数据集并解压,建议将其移动至~/catkin_ws/src。
其次,执行下面的命令。(针对freiburg1,freiburg2和freiburg3序列分别将TUMX.yaml更改为TUM1.yaml,TUM2.yaml或TUM3.yaml。将PATH_TO_SEQUENCE_FOLDER更改为未压缩的序列文件夹路径。)
./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/Monocular/TUMX.yaml PATH_TO_SEQUENCE_FOLDER
freiburg1对应的代码为(在/orbslam_ws/src/ORB_SLAM2下执行):
(单目)./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/Monocular/TUM1.yaml ~/orbslam_ws/src/rgbd_dataset_freiburg1_xyz
(参考rgb-d运行命令)./Examples/RGB-D/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUM1.yaml ~/slam/practice/vo/rgbd_dataset_freiburg2_pioneer_slam ~/slam/practice/vo/rgbd_dataset_freiburg2_pioneer_slam/associate.txt
(参考rgb-d运行命令)./Examples/RGB-D/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUM1.yaml ~/orbslam_ws/src/rgbd_dataset_freiburg1_xyz ~/orbslam_ws/src/rgbd_dataset_freiburg1_xyz/associate.txt
(参考双目运行命令)./Examples/Stereo/stereo_kitti Vocabulary/ORBvoc.txt Examples/Stereo/KITTI00-02.yaml ~/slam/practice/ch13/00
在clion中运行orbslam2
(rgb)(都输入到程序参数)/home/pzw/slam/ORB_SLAM2_modified/Vocabulary/ORBvoc.txt /home/pzw/slam/ORB_SLAM2_modified/Examples/RGB-D/TUM1.yaml /home/pzw/orbslam_ws/src/rgbd_dataset_freiburg1_xyz /home/pzw/orbslam_ws/src/rgbd_dataset_freiburg1_xyz/associate.txt
运行结果
5.1安装ros实例
根据github网站上的说明https://github.com/raulmur/ORB_SLAM2,首先要将包括Examples / ROS / ORB_SLAM2的路径添加到ROS_PACKAGE_PATH环境变量。打开.bashrc文件,并在末尾添加以下行。用ORB_SLAM2的文件夹路径替换PATH:这里的路径PATH是~/orbslam_ws…
cd ~
gedit .bashrc
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:PATH/ORB_SLAM2/Examples/ROS
由于后续会使用usb_cam,该节点发布的话题为/usb_cam/image_raw,而ORB SLAM2默认订阅的话题是/camera/image_raw,因此我们首先对其进行修改
cd ~/orbslam_ws/src/ORB_SLAM2/Examples/ROS/orb_slam2/src
gedit ros_mono.cc
对第64行的/camera/image_raw修改为/usb_cam/image_raw然后执行build_ros.sh
cd ~/catkin_ws/src/ORB_SLAM2
gedit build_ros.sh
chmod +x build_ros.sh
./build_ros.sh
编译时出现如下错误:
可以直接在ORBSLAM2/Examples/ROS/ORBSLAM2下的Cmakelists.txt中添加一行,-lboost_system
5.2摄像头调试
(奥比中光摄像头安装https://blog.csdn.net/weixin_48953899/article/details/113029282)
下文为笔记本摄像头
sudo apt-get install ros-kinetic-usb-cam
roslaunch usb_cam usb_cam-test.launch
rqt_image_view
下面测试一下usb摄像头
1.打开新的终端,运行roscore
roscore
2.打开launch文件,根据摄像头编号对文件进行修改。一般笔记本自身的摄像头是video0,usb摄像头是video1。
cd ~/catkin_ws/src/usb_cam/launch
gedit launch
3.运行测试。
cd ~/catkin_ws/src/usb_cam/launch
roslaunch usb_cam usb_cam-test.launch
5.3相机校准
如果已知相机内参,可直接对Asus.yaml进行修改。如果不知道内参,可以通过matlab、opencv等多种方式计算内参。这里提供一种ROS提供的单目相机校准,http://wiki.ros.org/camera_calibration/Tutorials/MonocularCalibration。
当完成内参计算后,进入/tmp,将标定的压缩包calibrationdata.tar.gz解压,打开ost.yaml,根据相机内参对~/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/Asus.yaml进行修改。
5.4实时运行ORB SLAM2
根据我们所安装的路径,代码为
cd ~/orbslam_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2
rosrun ORB_SLAM2 Mono ~/orbslam_ws/src/ORB_SLAM2/Vocabulary/ORBvoc.txt ~/orbslam_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/Asus.yaml
1 离线数据的运行
./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/Monocular/TUM1.yaml ~/orbslam_ws/src/rgbd_dataset_freiburg1_xyz
2 实时运行单目ORB SLAM2的代码是
#打开第一个终端,开启ROS
cd ~
roscore
#打开第二个终端,调用摄像头
roslaunch usb_cam usb_cam-test.launch
#打开第三个终端,标定单目摄像头
#其中size是棋盘内角点的个数,square是棋盘单个小格的边长
rosrun camera_calibration cameracalibrator.py --size 7x5 --square 0.005 image:=/usb_cam/image_raw camera:=/usb_cam
#进入/tmp,将标定的压缩包解压,取出ost.yaml放入~/orbslam_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/,内有相机内参,并和原文件Asus.yaml合并
#打开第四个终端,运行实时SLAM
cd ~/orbslam_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2
rosrun ORB_SLAM2 Mono ~/orbslam_ws/src/ORB_SLAM2/Vocabulary/ORBvoc.txt ~/orbslam_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/Asus.yaml
奥比中光摄像头启动orbslam2
roscore
~/orbslam_ws/src/ros_astra_camera/launch$ roslaunch astra.launch
rosrun ORB_SLAM2 Mono ~/orbslam_ws/src/ORB_SLAM2/Vocabulary/ORBvoc.txt ~/orbslam_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/Asus.yaml