ORB_SLAM2系列之二:ORB_SLAM2跑单目SLAM

接上一篇ORB_SLAM2系列之一:Ubuntu 14.04 ROS indigo下编译安装ORB_SLAM2,ORB_SLAM2提供了单目,双目和rgbd接口,这里我们先来尝试运行下最简单的单目SLAM(MonoSLAM)。

链接库

首先需要解决个错误:

error while loading shared libraries: libGLEW.so.2.1: cannot open shared obj

解决:

ln -s /usr/lib64/libGLEW.so.2.1 /usr/lib/libGLEW.so.2.1

准备工作空间

依次执行以下命令:

mkdir -p /home/catkin_ws/src
cd /home/catkin_ws/src/
catkin_init_workspace
cd .. && catkin_make
echo "source /home/catkin_ws/devel/setup.bash" >> ~/.bashrc
chmod 777 catkin_ws/
source /home/catkin_ws/devel/setup.bash 
source ~/.bashrc

现在/home/catkin_ws目录就是你设定的ROS的工作空间,以后需要其他的库都克隆到/home/catkin_ws/src目录下,然后回退到目录/home/catkin_ws/下,执行catkin_make进行编译。

编译ORB-SLAM2,DBow2和g2o

将ORB-SLAM2克隆到ROS的工作路径/home/catkin_ws/下。DBow和g2o这两个库在ORB-SLAM2的Thirdparty目录中,下载ORB-SLAM2源代码后,使用提供的脚本build.sh即可将它们一并编译了。

cd /home/catkin_ws/src

git clone https://github.com/raulmur/ORB_SLAM2.git

cd ORB_SLAM2

./build.sh

cd ../..

source devel/setup.bash

rospack profile

其中,build.sh内容如下:

echo "Configuring and building Thirdparty/DBoW2 ..."

cd Thirdparty/DBoW2
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j

cd ../../g2o

echo "Configuring and building Thirdparty/g2o ..."

mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j

cd ../../../

echo "Uncompress vocabulary ..."

cd Vocabulary
tar -xf ORBvoc.txt.tar.gz
cd ..

echo "Configuring and building ORB_SLAM2 ..."

mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j

完成DBow2,g2o,ORB-SLAM的编译,解压DBow2字典文件.ORB-SLAM2启动时,也需要载入这个100多M的文件,比较耗时。

笔记本摄像头驱动安装

如果你使用笔记本自带的摄像头,可以使用博世公司的 “usb_cam”:A ROS Driver for V4L USB Cameras。相似地,将usb_cam克隆到ROS的工作路径/home/catkin_ws/下。

cd /home/catkin_ws/src/

git clone https://github.com/bosch-ros-pkg/usb_cam.git

cd ../..

catkin_make

source devel/setup.bash

rospack profile

设定相机参数

#/home/research/ORB_SLAM2/Examples/Monocular/my.yaml

%YAML:1.0

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

# Camera calibration and distortion parameters (OpenCV)
Camera.fx: 517.306408
Camera.fy: 516.469215
Camera.cx: 318.643040
Camera.cy: 255.313989

Camera.k1: 0.262383
Camera.k2: -0.953104
Camera.p1: -0.005358
Camera.p2: 0.002628
Camera.k3: 1.163314

Camera.width: 640
Camera.height: 480

# Camera frames per second
Camera.fps: 30.0

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

#--------------------------------------------------------------------------------------------
# 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

运行

rosrun ORB_SLAM2 Mono /home/catkin_ws/src/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/research/ORB_SLAM2/Examples/Monocular/my.yaml

参考

1.使用自己笔记本摄像头运行orbslam2:http://blog.csdn.net/qq_18661939/article/details/51829157
2.用电脑自带的摄像头跑orb_slam2:https://zhuanlan.zhihu.com/p/29629824
3.ORB-SLAM跑通笔记本摄像头:http://www.cnblogs.com/shang-slam/p/6733322.html
4.在ROS中使用usb摄像头跑ORB SLAM2:http://blog.csdn.net/Goding_learning/article/details/52950993

你可能感兴趣的:(机器人,无人机,ros,计算机视觉,slam)