Skip to content

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
Copy link

diophantine86 commented Apr 18, 2017

have you occur g2o error about aligned assertion?

Copy link

nickoala commented May 4, 2017

Not that I am aware of.

Copy link

zanazakaryaie commented Sep 28, 2017

Hi, Thanks for explanations

I used Rapbian jessie with GCC 4.9.2 and everything works well except pangolin. When I run kitti example it loads vocabulary and then throws an error:
Pangolin X11: Unable to retrieve framebuffer options

What should I do?

Copy link

zaddan commented Feb 20, 2018

Thank you for the instructions. I was wondering how much fps were you able to get?

Copy link

q-depot commented Feb 24, 2018

thanks for the tutorial! I've managed to compile on the latest Raspbian Stretch following the instructions on this page, but I had to fix an issue with OpenCV and ORB_SLAM2, in case somebody is interested this is what I did to fix the errors:

Disable OpenCV precompiled heders
Run cmake with the option -DENABLE_PRECOMPILED_HEADERS=OFF


ORB_SLAM2 fix "error: usleep is not declared in this scope"
Include these headers in each file that fails(solution here):

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

Copy link

nickoala commented Mar 2, 2018

@zanazakaryaie, sorry, no clue 😊 I am not actively doing this stuff, after having written it up some 12 months ago.

@zaddan, running on Pi 3, I was able to get 1-2 frames per second.

@q-depot, thank you 😄

Copy link

eggs23 commented Mar 24, 2019

make ORB_SLAM2 not continue and stay at %40 all my 5 trials ?

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