# 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 specificationroot    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 apt-get to install what we need:

sudo apt-get install git \
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


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): git clone https://git@git.orfeo-toolbox.org/git/otb.git OTB  This will create a directory named OTB (so in my case, this is /home/otb/OTB/OTB). Using git commands, you can choose a particular version. The master branch will give you the last official release. You can go bleeding edge using the develop branch. cd OTB git checkout develop 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-trunk.tar.bz2
tar xvjf SuperBuild-archives-trunk.tar.bz2


The download step can be looooong. Be patient. Go jogging or something.

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, Rashad, Christophe, 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.

## 14 thoughts on “Installing OTB has never been so easy”

1. Hi Jordi,
What is the difference between this installation and the precompiled package accessible (or sooner accessible) from debian rep ?
Anyway, I do love running four hours, so I will test this install for next week 😉
Regards,
Mathieu

1. Jordi says:

I may be wrong, but I don’t think there is a debian package available. There will be Ubuntu packages. However, the SuperBuild install allows you to build your OTB using the most up to date and stable versions of the dependencies (ITK, gdal, ossim, etc.) which may not be available as packages in your distribution.

I you are training for a marathon, it’s worth trying.

2. Ok, thanks. Manuel told me that such a package should be available soon. We may discuss about that next week.
Bye,
Mathieu

3. Cedric Lardeux says:

Hello,

Thanks for this tutorial which works very well.

In order to use change detection tools between to images I would like to use Change detection tools of OTB like Kullback Leibler that seems to be in the library but not compile by default in standard packages (Ubuntu gis unstable ppa or Osgeo4w installer ot MVD2)

For this reason I compile OTB on my ubuntu. However I supposed that I need to add some option ins de cmake command in order to compile all existing OTB programe. However I don’t know how to update the cmake keywords.

Can you help me to that ?

Best regards

1. Jordi says:

Hi, there are a set of examples in the source tree
(Examples/ChangeDetection) which can be compiled setting the
BUILD_EXAMPLES flag in cmake to ON.

4. Jordi says:

Post updated to use git instead of mercurial.

5. Jaime says:

Hi Jordi,

I followed all your steps, but I’m having some problems installing OTB. This is the error I get:

gdalserver.c: In function ‘CreateSocketAndBindAndListen’:
gdalserver.c:124:21: error: storage size of ‘sHints’ isn’t known
struct addrinfo sHints;
^
gdalserver.c:126:31: error: invalid application of ‘sizeof’ to incomplete type ‘struct addrinfo’
memset(&sHints, 0, sizeof(struct addrinfo));
^
gdalserver.c:129:23: error: ‘AI_PASSIVE’ undeclared (first use in this function)
sHints.ai_flags = AI_PASSIVE;
^
gdalserver.c:129:23: note: each undeclared identifier is reported only once for each function it appears in
gdalserver.c:132:12: warning: implicit declaration of function ‘getaddrinfo’ [-Wimplicit-function-declaration]
nRet = getaddrinfo(NULL, pszService, &sHints, &psResults);
^
gdalserver.c:135:48: warning: implicit declaration of function ‘gai_strerror’ [-Wimplicit-function-declaration]
fprintf(stderr, “getaddrinfo(): %s\n”, gai_strerror(nRet));
^
gdalserver.c:135:25: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘int’ [-Wformat=]
fprintf(stderr, “getaddrinfo(): %s\n”, gai_strerror(nRet));
^
gdalserver.c:141:39: error: dereferencing pointer to incomplete type ‘struct addrinfo’
psResultsIter = psResultsIter->ai_next)
^
gdalserver.c:162:5: warning: implicit declaration of function ‘freeaddrinfo’ [-Wimplicit-function-declaration]
freeaddrinfo(psResults);
^
gdalserver.c:124:21: warning: unused variable ‘sHints’ [-Wunused-variable]
struct addrinfo sHints;
^
../GDALmake.opt:566: fallo en las instrucciones para el objetivo ‘gdalserver.lo’
make[4]: *** [gdalserver.lo] Error 1
GNUmakefile:69: fallo en las instrucciones para el objetivo ‘apps-target’
make[3]: *** [apps-target] Error 2
CMakeFiles/GDAL.dir/build.make:124: fallo en las instrucciones para el objetivo ‘GDAL/src/GDAL-stamp/GDAL-build’
make[2]: *** [GDAL/src/GDAL-stamp/GDAL-build] Error 2
CMakeFiles/Makefile2:495: fallo en las instrucciones para el objetivo ‘CMakeFiles/GDAL.dir/all’
make[1]: *** [CMakeFiles/GDAL.dir/all] Error 2
Makefile:83: fallo en las instrucciones para el objetivo ‘all’
make: *** [all] Error 2

Do you know why this is happening? Any possible solution? Thanks. Regards,
Jaime

1. Jaime says:

Thank you so much!! That worked nicely!

BTW, I had to install libboost-all-dev instead of libboost1.55-dev. May it be because I’m using Ubuntu 16.04??

Thanks again!

6. Jeewantha Bandara says:

Hello Jordi,

After installing OTB, how would one go about linking it up with QGIS. Installing the plugin and so forth? Thank you for your excellent tutorial. Cheers

1. Jordi says:

Hi,

I don’t know the answer to this question. I don’t use OTB from QGIS myself. Sorry!