Ubuntu16.04(ROS-kinetic)编译测试ORB-SLAM2

Ubuntu16.04(ROS-kinetic)编译测试ORB-SLAM2

参考

https://blog.csdn.net/learning_tortosie/article/details/79881165
https://blog.csdn.net/lixujie666/article/details/80475451

安装依赖项

具体的依赖项安装参考:
https://blog.csdn.net/learning_tortosie/article/details/79881165

安装ROS kinetic

为了能够在线实时地运行ORB-SLAM2,需要借助ROS。
ubuntu的版本要和ROS版本对应:

column1 column2
Ubuntu 14.04 ROS Indigo Igloo
Ubuntu 16.04 ROS Kinetic Kame
Ubuntu 18.04 ROS Melodic Morenia

我的是ubuntu16.04,对应安装 ROS Kinetic Kame,
官网安装教程http://wiki.ros.org/kinetic/Installation/Ubuntu
个人安装步骤记录如下:

  1. 设置ROS软件源
    添加ROS官方软件源:
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

一般地,ROS官方源速度很慢或者连接不上,推荐使用中科大的软件源.

sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'

题外话:
网上好多推荐使用清华大学的软件源,但后面安装时出现了如下问题
Ubuntu16.04(ROS-kinetic)编译测试ORB-SLAM2
解决方法就是换成中科大的源。

  1. 设置公钥
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

Ubuntu16.04(ROS-kinetic)编译测试ORB-SLAM2

  1. 更新
sudo apt-get update
  1. 安装Desktop-Full Install(桌面完整版)
sudo apt-get install ros-kinetic-desktop-full
  1. 初始化rosdep
sudo rosdep init
rosdep update
  1. 环境设置
echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
  1. 安装相关依赖项
sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential
  1. 刷新配置
source /opt/ros/kinetic/setup.bash
  1. 创建一个ROS工作空间并初始化
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
catkin_make
  1. 刷新,将工作空间添加到ROS系统环境中
$ source ~/catkin_ws/devel/setup.bash

为了避免每打开一个终端都需要运行这句指令,可以如下操作,使其自动进行

 echo “source ~/catkin_ws/devel/setup.bash” >>~/.bashrc

ORB-SLAM2测试自己的USB摄像头

参考:https://blog.csdn.net/lixujie666/article/details/80475451
ORB-SLAM官方主页:http://webdiis.unizar.es/~raulmur/orbslam/
ORB-SLAM2源码地址:https://github.com/raulmur/ORB_SLAM2

  1. 安装依赖库
    编译ORB-SLAM2之前需要安装一些必要的依赖库,按照源码中的README操作即可
  2. 将ORB_SLAM2源码整体下载,然后移到~/catkin_ws/src/目录下
  3. 将包含 Examples/ROS/ORB_SLAM2文件的路径添加到 ROS_PACKAGE_PATH 这个环境变量。具体操作如下
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:~/catkin_ws/src/ORB_SLAM2/Examples/ROS
  1. 执行build_ros.sh脚本
chmod +x build_ros.sh
./build_ros.sh

我在这里遇到编译出错:
undefined reference to symbol '_ZN5boost6system15system_categoryEv'
解决:https://github.com/raulmur/ORB_SLAM2/issues/494
https://blog.csdn.net/sinat_38343378/article/details/78883919
具体操作就是改一下~/ORB_SLAM2/Examples/ROS/ORB_SLAM2/中的CMakeList.txt文件
set(LIBS
${OpenCV_LIBS}
${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${PROJECT_SOURCE_DIR}/../../../Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/../../../Thirdparty/g2o/lib/libg2o.so
${PROJECT_SOURCE_DIR}/../../../lib/libORB_SLAM2.so
-lboost_system
)

  1. 利用ros提供的camera_calibration包进行相机标定
    参考:
    https://blog.csdn.net/heyijia0327/article/details/43538695
    https://blog.csdn.net/qq_30460905/article/details/80390576
  • 先下载读取usb摄像头的包usb_cam,下载地址:https://github.com/bosch-ros-pkg/usb_cam,下载完成后编译安装。或者直接运行指令sudo apt-get install ros-kinetic-usb-cam安装也行。
  • 开启roscore,打开相机
    //launch文件里面默认设备为/dev/video0,
    roscore
    roslaunch usb_cam usb_cam-test.launch
    我这里出现错误:[ERROR] [1567914098.829566811]: select timeout
    解决方法:
    https://devtalk.nvidia.com/default/topic/1036105/logitech-brio-usb-cam-select-timeout-while-capturing/
    大致就是让ubuntu切换到usb3.0模式,然后,将usb_cam的usb接口插到usb3.0的接口。
  • 检查usb_cam package发布的消息:
    rostopic list
    看是否有如下消息,并记住名称
    /usb_cam_node/camera_info
    /usb_cam_node/image_raw
  • 安装camera_calibration
    rosdep install camera_calibration
    #All required rosdeps installed successfully
  • 启动标定程序:
    rosrun camera_calibration cameracalibrator.py --size 7x5 --square 0.025 image:=/usb_cam/image_raw camera:=/usb_cam
    其中参数size 7x5 注意是字母x,他是棋盘内部角点个数,如下图所示。square为棋盘正方形边长,注意刚刚开始标定的时候,CALIBRATE按钮是灰色的。
    不断移动标定板,直到CALIBRATE按钮变亮,点击该按钮就会进行标定。耐心等待几分钟即可。
    标定完成后点击COMMIT按钮将结果保存到默认文件夹,在usb_cam窗口中可以看到如下信息,说明标定结果已经保存在相应文件夹下下次启动usb_cam节点时,会自动调用。
    Ubuntu16.04(ROS-kinetic)编译测试ORB-SLAM2
    图片来自https://blog.csdn.net/heyijia0327/article/details/43538695

标定完成后,将相应的相机参数保存到~/catkin_ws/src/ORB_SLAM2-master/Examples/ROS/ORB_SLAM2/default.yaml
default.yaml是相机的配置参数文件,我的default.yaml内容如下:

%YAML:1.0

#--------------------------------------------------------------------------------------------
# Camera Parameters. Adjust them!
#--------------------------------------------------------------------------------------------

# Camera calibration and distortion parameters (OpenCV) 
Camera.fx: 728.4
Camera.fy: 722.9
Camera.cx: 304.2
Camera.cy: 227.6

Camera.k1: -0.002
Camera.k2: -0.61
Camera.p1: 0.02
Camera.p2: -0.0005

Camera.width: 640
Camera.height: 480

# Camera frames per second 
Camera.fps: 30.0

# IR projector baseline times fx (aprox.)
Camera.bf: 40.0

# Color order of the images (0: BGR, 1: RGB. It is ignored if images are grayscale)
Camera.RGB: 1

# Close/Far threshold. Baseline times.
ThDepth: 40.0

# Deptmap values factor
DepthMapFactor: 1.0

#--------------------------------------------------------------------------------------------
# ORB Parameters
#--------------------------------------------------------------------------------------------

# ORB Extractor: Number of features per image
ORBextractor.nFeatures: 1000

# ORB Extractor: Scale factor between levels in the scale pyramid 	
ORBextractor.scaleFactor: 1.2

# ORB Extractor: Number of levels in the scale pyramid	
ORBextractor.nLevels: 8

# ORB Extractor: Fast threshold
# Image is divided in a grid. At each cell FAST are extracted imposing a minimum response.
# Firstly we impose iniThFAST. If no corners are detected we impose a lower value minThFAST
# You can lower these values if your images have low contrast			
ORBextractor.iniThFAST: 20
ORBextractor.minThFAST: 7

#--------------------------------------------------------------------------------------------
# Viewer Parameters
#--------------------------------------------------------------------------------------------
Viewer.KeyFrameSize: 0.05
Viewer.KeyFrameLineWidth: 1
Viewer.GraphLineWidth: 0.9
Viewer.PointSize:2
Viewer.CameraSize: 0.08
Viewer.CameraLineWidth: 3
Viewer.ViewpointX: 0
Viewer.ViewpointY: -0.7
Viewer.ViewpointZ: -1.8
Viewer.ViewpointF: 500

  1. 启动相机节点,利用usb_cam功能包,发布/camera/image_raw话题
    如果还没有安装usb_cam功能包的话,运行命令安装:
sudo apt-get install ros-kinetic-usb-cam

然后在~/catkin_ws/src文件夹下新建一个名为“usb_cam_node.launch”的launch文件,用来启动usb_cam_node节点,usb_cam_node.launch文件的内容如下:

<launch>
  <node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" >
    <param name="video_device" value="/dev/video1" />
    <param name="image_width" value="640" />
    <param name="image_height" value="480" />
    <param name="pixel_format" value="yuyv" />
    <param name="camera_frame_id" value="usb_cam" />
    <param name="io_method" value="mmap" />
    <remap from="/usb_cam/image_raw" to="/camera/image_raw" />
  </node>
</launch>

保存文件,然后运行命令启动节点:

roscd ~/catkin_ws/src
roslaunch usb_cam_node.launch

新打开一个终端,查看相机节点发布的消息

rostopic list

Ubuntu16.04(ROS-kinetic)编译测试ORB-SLAM2
7.运行ORB-SLAM2 中的Mono

rosrun ORB_SLAM2 Mono /home/selfsongs/catkin_ws/src/ORB_SLAM2-master/Vocabulary/ORBvoc.txt /home/selfsongs/catkin_ws/src/ORB_SLAM2-master/Examples/ROS/ORB_SLAM2/default.yaml

其中default.yaml就是前面标定后保存的相机参数文件
Ubuntu16.04(ROS-kinetic)编译测试ORB-SLAM2

上一篇:发微信模版消息换行用\n


下一篇:微信支付少一分钱