ORB_SLAM安装
源文件目录https://github.com/raulmur/ORB_SLAM2
安装orb_slam首先需要安装依赖库
- 安装Pangolin
- sudo apt-get install libglew-dev
- sudo apt-get install cmake
- sudo apt-get install libpython2.7-dev
- sudo apt-get install ffmpeg libavcodec-dev libavutil-dev libavformat-dev libswscale-dev
- git clone https://github.com/stevenlovegrove/Pangolin.git
cd Pangolin
mkdir build
cd build
cmake ..
make -j
安装OpenCV
ros中自带安装Eigen3
后续安装安装BLAS and LAPACK
sudo apt-get install libblas-dev
sudo apt-get install liblapack-dev
- 安装DBoW2 和 g2o
包含在orb_slam的第三方库中,后续一起安装
安装orb_slam
- 下载软件包
cd catkin_ws/src
git clone https://github.com/raulmur/ORB_SLAM2.git
- 编译第三方库
cd ORB_SLAM2
chmod +x build.sh
./build.sh
ORB_SLAM测试
安装USB_CAM 驱动
cd catkin_ws/src
git clone https://github.com/bosch-ros-pkg/usb_cam.git
cd ../
catkin_make
运行usb_cam 输出topic为/usb_cam/image_raw
roslaunch usb_cam usb_cam-test.launch
摄像头标定
- 准备标准黑白棋格盘
- 下载黑白棋盘
- 打印棋盘(可以A4纸打印,粘贴在硬纸板上)
- 测量棋盘单元边长(A4纸的在0.025 m 左右)
- 安装测试程序(ros)
$ rosdep install camera_calibration
$ rosmake camera_calibration
- 启动usb_cam程序
sudo apt-get install ros-indigo-usb-cam (如果没有安装usb_cam)
roslaunch usb_cam usb-cam-test.launch
- 启动camera_calibration
rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.025 image:=/usb_cam/image_raw camera:=/usb_cam
其中 size是黑白格的横纵点数,square是黑白格边长,image是图像节点名称,camera是相机名称。
-
实际标定
标定界面出现后,按照x(左右)、y(上下)、size(前后)、skew(倾斜)等方式移动棋盘,知道x,y,size,skew的进度条都变成绿色位置,此时可以按下CALIBRATE按钮,等一段时间就可以完成标定。
标定完成后,点击COMMIT按钮,最终的标定结果会在终端出现,在usb_cam的终端上会有yaml文件保存地址。
- 结果转换
转换结果如下所示:
image_width: 640
image_height: 480
camera_name: usb_cam
camera_matrix:
rows: 3
cols: 3
data: [914.5937398762499, 0, 313.2995046937195, 0, 906.4439566149695, 299.4151672923101, 0, 0, 1]
distortion_model: plumb_bob
distortion_coefficients:
rows: 1
cols: 5
data: [0.09838481350767736, 0.1181389276375996, 0.01127830741538815, 0.006633733461628469, 0]
rectification_matrix:
rows: 3
cols: 3
data: [1, 0, 0, 0, 1, 0, 0, 0, 1]
projection_matrix:
rows: 3
cols: 4
data: [933.7507934570312, 0, 315.2716618576233, 0, 0, 926.8785400390625, 300.85249210037, 0, 0, 0, 1, 0]
而在orb_slam中的格式如下,需要将上面的
camera_matrix:
distortion_coefficients:
参数值对应。其中ORB参数与Viewer参数不变。
最终的mycam.yaml文件保存在:
src/ORB_SLAM2/Examples/Monocular/mycam.yaml
%YAML:1.0
#--------------------------------------------------------------------------------------------
# Camera Parameters. Adjust them!
#--------------------------------------------------------------------------------------------
# Camera calibration and distortion parameters (OpenCV)
Camera.fx: 914.5937398762499
Camera.fy: 906.4439566149695
Camera.cx: 313.2995046937195
Camera.cy: 299.4151672923101
Camera.k1: 0.09838481350767736
Camera.k2: 0.1181389276375996
Camera.p1: 0.01127830741538815
Camera.p2: 0.006633733461628469
Camera.k3: 0
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
运行demo
- 环境配置
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:PATH/ORB_SLAM2/Examples/ROS
- 编译
cd src/ORB_SLAM2/Examples/ROS/ORB_SLAM2
mkdir build
cd build
cmake .. -DROS_BUILD_TYPE=Release
make -j
- 启动demo
rosrun ORB_SLAM2 Mono /home/your_path/catkin_ws/src/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/your_path/catkin_ws/src/ORB_SLAM2/Examples/Monocular/mycam.yaml
其中有两个参数,第一个参数为加载的字典,第二个参数为相机参数,更改为自身的相机参数即可。