Create a gist now

Instantly share code, notes, and snippets.

Embed
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

Check:

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 opencv.zip https://github.com/Itseez/opencv/archive/3.1.0.zip
unzip opencv.zip
cd opencv-3.1.0/
mkdir build
cd build

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
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

Pangolin

cd ~
git clone https://github.com/stevenlovegrove/Pangolin
cd Pangolin
mkdir build
cd build
cmake ..
make

ORB-SLAM2

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

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 build.sh. 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
make

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

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

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

Cancel swap space

sudo swapoff /var/swapfile
sudo rm /var/swapfile
@diophantine86

This comment has been minimized.

Show comment
Hide comment
@diophantine86

diophantine86 Apr 18, 2017

have you occur g2o error about aligned assertion?

have you occur g2o error about aligned assertion?

@nickoala

This comment has been minimized.

Show comment
Hide comment
@nickoala

nickoala May 4, 2017

Not that I am aware of.

Owner

nickoala commented May 4, 2017

Not that I am aware of.

@zanazakaryaie

This comment has been minimized.

Show comment
Hide comment
@zanazakaryaie

zanazakaryaie 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?

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?

@zaddan

This comment has been minimized.

Show comment
Hide comment
@zaddan

zaddan Feb 20, 2018

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

zaddan commented Feb 20, 2018

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

@q-depot

This comment has been minimized.

Show comment
Hide comment
@q-depot

q-depot 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

cmake -DENABLE_PRECOMPILED_HEADERS=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

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>

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

cmake -DENABLE_PRECOMPILED_HEADERS=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

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>

@nickoala

This comment has been minimized.

Show comment
Hide comment
@nickoala

nickoala 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 😄

Owner

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 😄

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