Raspberry Pi に ORB-SLAM3 をインストールする方法をここにメモします。
ORB-SLAM3 とは
ORB-SLAM3 はスペインのサラゴサ大学の Raúl Mur Artal 氏のチームが開発した ORB-SLAM アルゴリズムを用いたSLAMソフトウェアです。
Raspberry Pi のようなリソース制約のあるデバイスでも動作可能とのことで今回セットアップを試みました。
準備
基本的なツールとライブラリのインストール
$ sudo apt update $ sudo apt install build-essential cmake git libgtk-3-dev libboost-all-dev \ libglew-dev libopencv-dev libeigen3-dev libsuitesparse-dev libatlas-base-dev \ libxi-dev libg2o-dev
OpenCV
ORB-SLAM3 は OpenCV を使用して画像処理を行います。
インストール
Raspberry Pi には以下のコマンドで OpenCV をインストールします。
$ sudo apt install libopencv-dev python3-opencv
Pangolin(ORB-SLAM3 の描画に必要なライブラリ)
Pangolin はビジュアル化ライブラリで、ORB-SLAM3 の 3D ビジュアライゼーションに使用されます。
$ git clone https://github.com/stevenlovegrove/Pangolin.git $ cd Pangolin $ mkdir build $ cd build $ cmake .. $ cmake --build . $ sudo make install
ORB-SLAM3
ソースコード取得
$ cd ~ $ git clone https://github.com/UZ-SLAMLab/ORB_SLAM3.git $ cd ORB_SLAM3
ORB-SLAM3 用の Vocabulary ファイルのダウンロード
ORB-SLAM3 には、ボキャブラリファイル(ORB辞書データ)が必要です。以下のコマンドでダウンロードします。
$ cd Vocabulary $ ./download_vocabulary.sh $ cd ..
Eigen、DBoW2、g2o ビルド
ORB-SLAM3 の依存ライブラリのセットアップを行います。
Eigen インストール
Eigen は行列計算ライブラリで、通常はすでにインストールされていますが、以下のコマンドで確認します。
$ sudo apt install libeigen3-dev
DBoW2 ビルド
DBoW2 は ORB-SLAM3 で使用されるデータベースライブラリです。
$ cd ORB_SLAM3/Thirdparty/DBoW2 $ mkdir build $ cd build $ cmake .. $ make -j4
g2o ビルド
g2o はグラフベースの最適化ライブラリです。
$ cd ../../g2o $ mkdir build $ cd build $ cmake .. $ make -j4
ORB-SLAM3 ビルド
ORB-SLAM3 自体をビルドします。
$ cd ../../../ $ mkdir build $ cd build $ cmake .. -DOpenCV_DIR=/usr/local/share/OpenCV # OpenCVのディレクトリを指定 $ make -j2
ビルドが完了したら、libORB_SLAM3.so という共有ライブラリが生成されます。
Pythonバインディング(オプション)
Python3 対応のバインディングのビルド
Python から ORB-SLAM3 を使いたい場合は、Python バインディングも用意されています。
$ cd ORB_SLAM3/Python $ mkdir build $ cd build $ cmake .. $ make -j2
ORB-SLAM3 実行
ORB-SLAM3 をビルドしたら、カメラ入力や動画ファイルを使って SLAM を実行することができます。
USBカメラでの実行例
$ ./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/Monocular/TUM1.yaml /dev/video0
ビルド時のエラー対応
その1
エラー
make[2]: *** [CMakeFiles/ORB_SLAM3.dir/build.make:76: CMakeFiles/ORB_SLAM3.dir/src/Tracking.cc.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:711: CMakeFiles/ORB_SLAM3.dir/all] Error 2 make: *** [Makefile:84: all] Error 2
回避策
CMakeLists.txt ファイルの最初の行に以下を追加します。
add_compile_options(-std=c++14)
参考: Report an error and solving method · Issue #566 · UZ-SLAMLab/ORB_SLAM3 · GitHub
その2
エラー
KannalaBrandt8.h:59:9: warning: when initialized here [-Wreorder]
回避策
$ cd ~/ORB_SLAM3/ $ sed -i 's/++11/++14/g' CMakeLists.txt
その3
エラー
/home/test/ORB_SLAM3/Thirdparty/DBoW2/DBoW2/BowVector.h:17:10: fatal error: boost/serialization/serialization.hpp: No such file or directory 17 | #include <boost/serialization/serialization.hpp> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. make[2]: *** [CMakeFiles/DBoW2.dir/build.make:118: CMakeFiles/DBoW2.dir/DBoW2/ScoringObject.cpp.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/DBoW2.dir/all] Error 2 make: *** [Makefile:91: all] Error 2