Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Build ORB-SLAM2 on Raspberry Pi 3

Build ORB-SLAM2 on Raspberry Pi 3

Operating system: Ubuntu Mate 16.04

I use Ubuntu Mate instead of the usual Raspbian Jessie mainly because of the gcc version. ORB-SLAM2 requires C++11 support. Raspbian comes with gcc 4.9, which does not handle C++11 by default. That means you have to play around with some compiler flags in ORB-SLAM2's CMakeLists.txt to make it work. In contrast, Ubuntu Mate's gcc 5.4 handles C++11 naturally.

Note: if the compiler fails with the error double free or corruption, it is likely an indication of a not-new-enough version of gcc.

Swap space

Unlike Raspbian, Ubuntu Mate does not have swap space by default. To avoid running out of RAM during the build process, you should add some swap space:

sudo fallocate /var/swapfile -l 1G
sudo chmod 600 /var/swapfile
sudo mkswap /var/swapfile
sudo swapon /var/swapfile


free -m

If you don't add swap space, you will likely run into an internal compiler error at some point during the build process.

Development Tools

sudo apt-get install cmake git

OpenCV 3.1.0

In theory, ORB-SLAM2 requires OpenCV 2.4, but it's actually compatible with OpenCV 3.1 also. I prefer new stuff, thus OpenCV 3.1.0 here.

I adapt Adrian Rosebrock's excellent instructions here:

sudo apt-get install build-essential pkg-config
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng-dev
sudo apt-get install libtbb-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install libxvidcore-dev libx264-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install python2.7-dev python3-dev python-numpy python3-numpy

Note that I install bindings for Python 2.7 and Python 3, convenient for experimentation.

Then, download OpenCV, unzip, build, and install:

cd ~
wget -O
cd opencv-3.1.0/
mkdir build
cd build

make -j4
sudo make install
sudo ldconfig

Other dependencies

Linear algebra and OpenGL stuff:

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


cd ~
git clone
cd Pangolin
mkdir build
cd build
cmake ..


cd ~
git clone

Find the file CMakeLists.txt and change the line find_package(OpenCV 2.4.3 REQUIRED) to match your OpenCV version, 3.1.0 in my case.

Then, you may run the shell script But I prefer to follow it by hand, knowing what is going on in each step:

cd Thirdparty/DBoW2
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release

cd ../../g2o
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release

cd ../../..
cd Vocabulary
tar -xf ORBvoc.txt.tar.gz

cd ..
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release

Cancel swap space

sudo swapoff /var/swapfile
sudo rm /var/swapfile

have you occur g2o error about aligned assertion?


nickoala commented May 4, 2017

Not that I am aware of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment