Installing OTB has never been so easy
You've heard about the Orfeo Toolbox library and its wonders, but urban legends say that it is difficult to install. Don't believe that. Maybe it was difficult to install, but this is not the case anymore.
Thanks to the heroic work of the OTB core development team, installing OTB has never been so easy. In this post, you will find the step-by-step procedure to compile OTB from source on a Debian 8.0 Jessie GNU/Linux distribution.
Prepare the user account
I assume that you have a fresh install. The procedure below has been tested in a virtual machine running under VirtualBox. The virtual machine was installed from scratch using the official netinst ISO image.
During the installation, I created a user named otb
that I will use
for the tutorial below. For simplicity, I give this user root
privileges in order to install some packages. This can be done as
follows. Log in as root or use the command:
su -
You can then edit the /etc/sudoers
file by using the following
command:
visudo
This will open the file with the nano
text editor. Scroll down to
the lines containing
# User privilege specification root ALL=(ALL:ALL) ALL
and copy the second line and below and replace root
by otb
:
otb ALL=(ALL:ALL) ALL
Write the file and quit by doing C^o
ENTER
C^x
.
Log out and log in as otb
. You are set!
System dependencies
Now, let's install some packages needed to compile OTB. Open a
terminal and use aptitude
to install what we need:
sudo aptitude install mercurial \ cmake-curses-gui build-essential \ qt4-dev-tools libqt4-core \ libqt4-dev libboost1.55-dev \ zlib1g-dev libopencv-dev curl \ libcurl4-openssl-dev swig \ libpython-dev
Get OTB source code
We will install OTB in its own directory. So from your $HOME
directory create a directory named OTB
and go into it:
mkdir OTB
cd OTB
Now, get the OTB sources by cloning the repository (depending on your network speed, this may take several minutes):
hg clone http://hg.orfeo-toolbox.org/OTB
This will create a directory named OTB
(so in my case, this is
/home/otb/OTB/OTB
).
Using mercurial commands, you can choose a particular version or you can go bleeding edge. You will at least need the first release candidate for OTB-5.0, which you can get with the following commands:
cd OTB hg update 5.0.0-rc1 cd ../
Get OTB dependencies
OTB's SuperBuild is a procedure which deals with all external libraries needed by OTB which may not be available through your Linux package manager. It is able to download source code, configure and install many external libraries automatically.
Since the download process may fail due to servers which are not
maintained by the OTB team, a big tarball has been prepared for you.
From the $HOME/OTB
directory, do the following:
wget https://www.orfeo-toolbox.org/packages/SuperBuild-archives.tar.bz2 tar xvjf SuperBuild-archives.tar.bz2
The download step can be looooong. Be patient. Go jogging or something.
Compile OTB
Once you have downloaded and extracted the external dependencies, you
can start compiling OTB. From the $HOME/OTB
directory, create the
directory where OTB will be built:
mkdir -p SuperBuild/OTB
At the end of the compilation, the $HOME/OTB/SuperBuild/
directory
will contain a classical bin/
, lib/
, include/
and share/
directory tree. The $HOME/OTB/SuperBuild/OTB/
is where the
configuration and compilation of OTB and all the dependencies will be
stored.
Go into this directory:
cd SuperBuild/OTB
Now we can configure OTB using the cmake
tool. Since you are on a
recent GNU/Linux distribution, you can tell the compiler to use the
most recent C++ standard, which can give you some benefits even if OTB
still does not use it. We will also compile using the Release
option
(optimisations). The Python wrapping will be useful with the OTB
Applications. We also tell cmake
where the external dependencies
are. The options chosen below for OpenJPEG make OTB use the gdal
implementation.
cmake \ -DCMAKE_CXX_FLAGS:STRING=-std=c++14 \ -DOTB_WRAP_PYTHON:BOOL=ON \ -DCMAKE_BUILD_TYPE:STRING=Release \ -DCMAKE_INSTALL_PREFIX:PATH=/home/otb/OTB/SuperBuild/ \ -DDOWNLOAD_LOCATION:PATH=/home/otb/OTB/SuperBuild-archives/ \ -DOTB_USE_OPENJPEG:BOOL=ON \ -DUSE_SYSTEM_OPENJPEG:BOOL=OFF \ ../../OTB/SuperBuild/
After the configuration, you should be able to compile. I have 4 cores
in my machine, so I use the -j4
option for make
. Adjust the value
to your configuration:
make -j4
This will take some time since there are many libraries which are going to be built. Time for a marathon.
Test your installation
Everything should be compiled and available now. You can set up some
environment variables for an easier use of OTB. You can for instance
add the following lines at the end of $HOME/.bashrc
:
export OTB_HOME=${HOME}/OTB/SuperBuild export PATH=${OTB_HOME}/bin:$PATH export LD_LIBRARY_PATH=${OTB_HOME}/lib
You can now open a new terminal for this to take effect or use:
cd source .bashrc
You should now be able to use the OTB Applications. For instance, the command:
otbcli_BandMath
should display the documentation for the BandMath application.
Another way to run the applications, is using the command line application launcher as follows:
otbApplicationLauncherCommandLine BandMath $OTB_HOME/lib/otb/applications/
Conclusion
The SuperBuild procedure allows to easily install OTB without having to deal with different combinations of versions for the external dependencies (TIFF, GEOTIFF, OSSIM, GDAL, ITK, etc.).
This means that once you have cmake
and a compiler, you are pretty
much set. QT4 and Python are optional things which will be useful for
the applications, but they are not required for a base OTB
installation.
I am very grateful to the OTB core development team (Julien, Manuel, Guillaume, the other Julien, Mickaƫl, and maybe others that I forget) for their efforts in the work done for the modularisation and the development of the SuperBuild procedure. This is the kind of thing which is not easy to see from the outside, but makes OTB go forward steadily and makes it a very mature and powerful software.