怎麼在ubuntu下裝ORB-SLAM2,並用單目攝像頭實時跑起來

最新的是ORB-SLAM2,https://github.com/raulmur/ORB_SLAM2(支持單目、雙目和RGB-D接口,最好參照官網安裝)

安裝必備軟件:爲了方便.最好先把要下載的庫先在windows下下載好(注意下載的版

本).不裝在系統盤



(1)更新apt庫

sudo apt-get update

(2)安裝Git

sudo apt-get install git

(3)安裝cmake

sudo apt-get install cmake


(4)安裝Pangolin (for visualization and user interface:可視化與用戶界面)

Pangolin網址:https://github.com/stevenlovegrove/Pangolin


安裝依賴
a、opengl: 
b、GLEW:
sudo apt-get install libglew-dev

c、Boost:

sudo apt-get install libboost-dev libboost-thread-dev libboost-filesystem-dev

d、Python2/Python3:

sudo apt-get install libpython2.7-dev

e、編譯基礎庫

sudo apt-get install build-essential

終端裏輸入

cd Pangolinmkdir build
cd build
cmake -DCPP11_NO_BOOST=1 ..
make -j 
(建議不要使用make -j,使用make。如果用make -j是使用多處理器編譯,可能造成死機)


(5)安裝OpenCV (manipulate images and features: 操縱圖像和特徵點)

安裝依賴:

 

a、編譯器相關:
sudo apt-get install build-essential

b、必須依賴:

sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev
libavformat-dev libswscale-dev

c、可選安裝:

sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

安裝OpenCV: 

a、官網下載OpenCV 2.4.11 for Linux下載地址,解壓到Ubuntu中 

b、進入OpenCV文件夾,配置工程
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

c、編譯

make
sudo make install

(6)安裝Eigen We use modified versions of theDBoW2 library to perform place recognition--進行位置識別 and g2o library to perform non-linear optimizations--進行非線性優化. Both modified libraries (which are BSD) are included in theThirdparty folder.
Eigen下載地址,進入到在解壓後的Eigen文件夾(例如eigen-eigen-07105f7124f9)下

mkdir build
cd build
cmake ..
make
sudo make install

(7)安裝BLAS and LAPACK庫

sudo apt-get install libblas-dev
sudo apt-get install liblapack-dev

ROS (optional)

We provide some examples to process the live input of a monocular, stereo or RGB-D camera using ROS. Building these examples is optional. In case you want to use ROS, a version Hydro or newer is needed.


其實build.sh就是前面第三方庫的編譯+ORB_SLAM2的編譯,以後可以自己寫一個 類似的終端命令腳本,就不需要每次編譯都手敲一遍。如果發現編譯出錯,儘量從github或者官網上面git clone源碼,裏面有很多issus可供參考。


3.安裝ORB_SLAM: 
(1)Clone the repository:

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

(2)編譯:我們提供一個腳本build.sh建立第三方庫和orb-slam2。請確保您已安裝所有所需的依賴項

cd ORB_SLAM2
chmod +x build.sh./build.sh


  • ORB-SLAM2最後編譯遇到的問題

1)強制類型轉換問題

錯誤信息:

/home/melanie/tools/eigen/Eigen/src/Core/AssignEvaluator.h:817:3: error: static assertion failed: YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename ActualDstTypeCleaned::Scalar,typename Src::Scalar); ^CMakeFiles/ORB_SLAM2.dir/build.make:350: recipe for target 'CMakeFiles/ORB_SLAM2.dir/src/Optimizer.cc.o' failedmake[2]: *** [CMakeFiles/ORB_SLAM2.dir/src/Optimizer.cc.o] Error 1CMakeFiles/Makefile2:178: recipe for target 'CMakeFiles/ORB_SLAM2.dir/all' failedmake[1]: *** [CMakeFiles/ORB_SLAM2.dir/all] Error 2Makefile:83: recipe for target 'all' failedmake: *** [all] Error 2

解決方案:

打開Thirdparty/g2o/g2o/solvers/linear_solver_eigen.h,

將以下代碼template <typename MatrixType>

class LinearSolverEigen: public LinearSolver<MatrixType>

{ public: typedef Eigen::SparseMatrix<double, Eigen::ColMajor> SparseMatrix;

typedef Eigen::Triplet<double> Triplet;

typedef Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic, SparseMatrix::Index> PermutationMatrix;

修改爲:

template <typename MatrixType>

class LinearSolverEigen: public LinearSolver<MatrixType>

{ public:

typedef Eigen::SparseMatrix<double, Eigen::ColMajor> SparseMatrix;

typedef Eigen::Triplet<double> Triplet;

typedef Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic, int> PermutationMatrix;

2)usleep未定義:

錯誤信息:

/home/melanie/source/SmartCar/ORM_SLAM2/ORB_SLAM2/src/Viewer.cc:159:28:

error: ‘usleep’ was not declared in this scope usleep(3000);

^CMakeFiles/ORB_SLAM2.dir/build.make:494: recipe for target

'CMakeFiles/ORB_SLAM2.dir/src/Viewer.cc.o' failedmake[2]:

*** [CMakeFiles/ORB_SLAM2.dir/src/Viewer.cc.o]

Error 1CMakeFiles/Makefile2:178: recipe for target 'CMakeFiles/ORB_SLAM2.dir/all' failedmake[1]: *** [CMakeFiles/ORB_SLAM2.dir/all]

Error 2Makefile:83: recipe for target 'all' failed

make: *** [all] Error 2

解決方案:

在source文件的開頭增加include#include <unistd.h>

需要增加unistd.h的文件有:

Examples/Monocular/mono_euroc.cc

Examples/Monocular/mono_kitti.cc

Examples/Monocular/mono_tum.cc

Examples/RGB-D/rgbd_tum.cc

Examples/Stereo/stereo_euroc.cc

Examples/Stereo/stereo_kitti.cc

src/LocalMapping.cc

src/LoopClosing.cc

src/System.cc

src/Tracking.cc

src/Viewer.cc

4.測試ORB_SLAM2

(1)官網下載測試數據集

 下載內存較大,最好用硬盤下好

Monocular 實例

TUM 數據集

  1. Download a sequence from http://vision.in.tum.de/data/datasets/rgbd-dataset/download and uncompress it.
  2. Execute the following command. Change TUMX.yaml to TUM1.yaml,TUM2.yaml or TUM3.yaml for freiburg1, freiburg2 and freiburg3 sequences respectively. Change PATH_TO_SEQUENCE_FOLDERto the uncompressed sequence folder.
./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/Monocular/TUMX.yaml PATH_TO_SEQUENCE_FOLDER

KITTI 數據集

  1. Execute download the dataset (grayscale images) from  http://www.cvlibs.net/datasets/kitti/eval_odometry.php
  2. e the following command. Change KITTIX.yaml by KITTI00-02.yaml, KITTI03.yaml or KITTI04-12.yaml for sequence 0 to 2, 3, and 4 to 12 respectively. Change PATH_TO_DATASET_FOLDER to the uncompressed dataset folder. Change SEQUENCE_NUMBER to 00, 01, 02,.., 11.
./Examples/Monocular/mono_kitti Vocabulary/ORBvoc.txt Examples/Monocular/KITTIX.yaml PATH_TO_DATASET_FOLDER/dataset/sequences/SEQUENCE_NUMBER

Stereo 實例

KITTI 數據集

  1. Download the dataset (grayscale images) from http://www.cvlibs.net/datasets/kitti/eval_odometry.php
  2. Execute the following command. Change KITTIX.yamlto KITTI00-02.yaml, KITTI03.yaml or KITTI04-12.yaml for sequence 0 to 2, 3, and 4 to 12 respectively. Change PATH_TO_DATASET_FOLDER to the uncompressed dataset folder. Change SEQUENCE_NUMBER to 00, 01, 02,.., 11.
./Examples/Stereo/stereo_kitti Vocabulary/ORBvoc.txt Examples/Stereo/KITTIX.yaml PATH_TO_DATASET_FOLDER/dataset/sequences/SEQUENCE_NUMBER

RGB-D 實例

TUM 數據集

  1. Associate RGB images and depth images using the python script associate.py. We already provide associations for some of the sequences in Examples/RGB-D/associations download a sequence fromhttp://vision.in.tum.de/data/datasets/rgbd-dataset/download and uncompress it.
  2. /. You can generate your own associations file executing:
  3. python associate.py PATH_TO_SEQUENCE/rgb.txt PATH_TO_SEQUENCE/depth.txt > associations.txt
  4. Execute the following command. Change TUMX.yaml to TUM1.yaml,TUM2.yaml or TUM3.yaml for freiburg1, freiburg2 and freiburg3 sequences respectively. Change PATH_TO_SEQUENCE_FOLDERto the uncompressed sequence folder. Change ASSOCIATIONS_FILE to the path to the corresponding associations file.
./Examples/RGB-D/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUMX.yaml PATH_TO_SEQUENCE_FOLDER ASSOCIATIONS_FILE

ROS 實例

處理你自己的實例

      你需要創建一個配置文件來校正你的攝像機。可以參照我們爲TUM 和 KITTI 數據集提供的例子在monocular, stereo and RGB-D cameras情況下. 我們使用OpenCV的攝像機校正模型。 See the examples to learn how to create a program that makes use of the ORB-SLAM2 library and how to pass images to the SLAM system. Stereo input must be synchronized and rectified. RGB-D input must be synchronized and depth registered.

SLAM 和 Localization 模式

你可以使用GUI在SLAM 和 Localization 模式下自由切換

SLAM 模式

      這是默認模式. 此模式下,系統有三個線程並行工作: Tracking, Local Mapping and Loop Closing. 系統不斷定位相機,構建新的地圖然後試圖閉合環形路徑

Localization 模式

       當你有一個比較好的地圖的時候,你可以使用此模式。在這種模式下,局部地圖構建以及環路閉合將不起作用。 系統在你提供的地圖上定位相機 (which is no longer updated), using relocalization if needed.


參考博客:http://blog.csdn.net/zhjm07054115/article/details/51706706

             https://github.com/raulmur/ORB_SLAM2


5.實時用攝像頭(可筆記本自帶或者外加攝像頭)跑數據

(1)安裝usb_cam package

      
    $ cd ~/catkin_ws/src  
    $ git clone https://github.com/bosch-ros-pkg/usb_cam.git  
    $ cd ~/catkin_ws  
    $ catkin_make  
筆記本自帶的攝像頭的設備號一般爲/dev/video0    外接攝像頭一般是
<param name="video_device"value="/dev/video1"/><br><br>




(2)把ORB-SLAM2,和 usb_cam放到catkin下src目錄下
     $ cd ~/catkin_ws/src  
    $ roscore    //初始化
    $ roslaunch usb_cam usb_cam-test.launch     //啓動usb_cam包下的.launch文件啓動攝像頭


此時證明攝像頭可以正常使用

~~~使用自定義 launch 文件設置攝像頭:
usb_cam 給了我們一個默認的 launch 文件在如下目錄

如果想要自定義一個我們自己的launch文件,我們可以複製這個文件爲一個 usb_cam.launch,然後打開這個文件:

其中 /div/video0 表示是第一個攝像頭,如果你有多個攝像頭,可以將此改爲 /div/video1 等等。想要查看當前連接設備,使用如下命令即可:

修改好後運行這個文件:

Error1: [rospack] Error: package 'image_view' not found

表明你的 image_view 沒有安裝,可以執行以下命令安裝即可:

sudo apt-get install ros-indigo-image-view

(3)用ORB-SLAM2實時跑數據記住:若是用外加攝像頭,需要在usb_cam-test.launch和usb_cam_node.cpp把攝像頭的設備號改爲/dev/video1

  $ cd ~/catkin_ws/src  
  $ rosrun ORB_SLAM2 Mono /home/ubantu/catkin_ws/src/ORB_SLAM2/Vocabulary/ORBvoc.txt 
       /home/ubantu/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/Asus.yaml    
       (即 rosrun ORB-SLAN2 Mono    ORBvoc.txt路徑    Asus.yaml路徑)

6.標定攝像頭(爲了防止鏡頭下的圖片發生畸變)

1)攝像頭標定時所處的平面位置一旦改變,一般會影響相機內參,需重新標定

2)將標定後的參數替換相機原有的內參,重新跑一遍即可。




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章