(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. 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. 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. 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