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
后續(xù)安裝安裝BLAS and LAPACK
sudo apt-get install libblas-dev
sudo apt-get install liblapack-dev
- 安裝DBoW2 和 g2o
包含在orb_slam的第三方庫中乾戏,后續(xù)一起安裝
安裝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 驅(qū)動(dòng)
cd catkin_ws/src
git clone https://github.com/bosch-ros-pkg/usb_cam.git
cd ../
catkin_make
運(yùn)行usb_cam 輸出topic為/usb_cam/image_raw
roslaunch usb_cam usb_cam-test.launch
攝像頭標(biāo)定
- 準(zhǔn)備標(biāo)準(zhǔn)黑白棋格盤
- 下載黑白棋盤
- 打印棋盤(可以A4紙打印,粘貼在硬紙板上)
- 測量棋盤單元邊長(A4紙的在0.025 m 左右)
- 安裝測試程序(ros)
$ rosdep install camera_calibration
$ rosmake camera_calibration
- 啟動(dòng)usb_cam程序
sudo apt-get install ros-indigo-usb-cam (如果沒有安裝usb_cam)
roslaunch usb_cam usb-cam-test.launch
- 啟動(dòng)camera_calibration
rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.025 image:=/usb_cam/image_raw camera:=/usb_cam
其中 size是黑白格的橫縱點(diǎn)數(shù)夺荒,square是黑白格邊長崎坊,image是圖像節(jié)點(diǎn)名稱灌旧,camera是相機(jī)名稱。
-
實(shí)際標(biāo)定
標(biāo)定界面出現(xiàn)后,按照x(左右)瘟滨、y(上下)坎藐、size(前后)为牍、skew(傾斜)等方式移動(dòng)棋盤哼绑,知道x,y,size,skew的進(jìn)度條都變成綠色位置,此時(shí)可以按下CALIBRATE按鈕碉咆,等一段時(shí)間就可以完成標(biāo)定抖韩。
標(biāo)定完成后,點(diǎn)擊COMMIT按鈕疫铜,最終的標(biāo)定結(jié)果會(huì)在終端出現(xiàn)茂浮,在usb_cam的終端上會(huì)有yaml文件保存地址。
- 結(jié)果轉(zhuǎn)換
轉(zhuǎn)換結(jié)果如下所示:
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:
參數(shù)值對(duì)應(yīng)席揽。其中ORB參數(shù)與Viewer參數(shù)不變。
最終的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
運(yùn)行demo
- 環(huán)境配置
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
- 啟動(dòng)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
其中有兩個(gè)參數(shù)谓厘,第一個(gè)參數(shù)為加載的字典幌羞,第二個(gè)參數(shù)為相機(jī)參數(shù),更改為自身的相機(jī)參數(shù)即可竟稳。