OTB & Windows OS

From OTBWiki
Jump to: navigation, search

This is the old HowTo for Windows with MSVC. This page is out-dated and need some updates. Please refer to OTB development on Windows page


IMPORTANT NOTICE: Beginners, if you want develop into or using the OTB library, we highly recommend you to do it on Linux

Building the OTB library and applications on Windows is currently quite challenging. You should manage correctly all the dependencies of OTB and install them on your platform. You should take care of

  • the version of the library,
  • building them in release mode as much as possible.
  • building them with a compiler which is Microsoft Visual Studio 9 (2008) or 10 (2010). Currently MVSC 11 and MSVC 12 are not supported (cf. MANTIS-OTB-691 and cf. MANTIS-OTB-820)

However

  • if you want use Monteverdi, we provide a standalone installer (downloaded from here).
  • if you want only use the OTB-Applications, we provide through OSgeo4W a binary package (some explanations can be found here). Please choose the 32 bit installer of OSGeo4W.

Supported Windows OS version

Status of OTB and the different version of Windows:

  • Win XP SP3: yes and nightly tested
  • Win Vista: unknown status (should be the same that Win Seven)
  • Win Seven: yes and nightly tested
  • Win 8: unknown status (JIRA-OTB-449). Moreover blocked by the fact that OTB can be built with Microsoft Visual Studio Compiler 11 (MANTIS-OTB-691) which is the only version of MSVC available on Windows 8 for the moment.

If you want develop into OTB, we highly recommend you to do it with Linux platform.

Currently it is not possible to build OTB in Debug when using the dependencies provided by OSGeo4W. If you want to build OTB in Debug for Windows, you will need to build & install manually each dependency needed by OTB (hard work...). You should use the same compiler for all the dependencies, as much as possible.

OSGeo4W is 32bit only for now (Update: a new 64 bit installer is available, we will test it), so you cannot rely on OSGeo4W dependencies to build OTB in 64bit. Again, if you need to do this, you shall have all the dependencies in 64 bit mode.

This page is dedicated to people who want to install OTB on Windows to do their own developments based on it.

Install the latest release of OTB for Windows

No OTB standalone installer are provided on Windows for the library. Only binaries for the applications are provided. You must build the library from source and install it.

Build OTB under Windows to install the library and use it into your developments is currently more challenging than under Linux OS. Therefore we advice to the beginners to go under Linux. For example, OTB packages are provided for Ubuntu and OpenSuse. With these, you can easily test and discover OTB functionalities. Please go to section 2.1.3 of the SoftwareGuide.

We will describe here how to install the library with the main functionalities in Release and ReleaseWithDebugInfo mode.

Preliminary Steps

To build OTB library under Windows the followings conditions are mandatory:

  • have a Windows version supported: XP SP3 or Seven (these two versions are currently tested)
  • have a supported MSVC compiler : Microsoft Visual Studio C++ 2010 (Express or Complete version)

You need also to install the following tool to configure and generate the Visual Studio solution of OTB (OTB.sln):

  • CMake: version >= 2.8.6 (the latest binary for windows is here)

To manage correctly and easily the dependencies of OTB under Windows we strongly recommend to install OSGeo4W tool (32 bit). This software will provide you with all the necessary dependencies in 32 bit mode. Please follow these steps:

  1. Download the 32 bit setup installer
  2. Run the setup installer with Admin Rights
  3. Select Advanced Install
  4. Select Install from Internet
  5. Keep as much as possible the default values about root directory and other parameters. You must have the write access to this root directory.
  6. In the next screen, select a local package directory (idem you must have the write access to this directory)
  7. Select your Internet connection settings
  8. Select the default download site
  9. Select the following packages:
    • msvcrt
    • gdal
    • curl
    • expat
    • libjpeg
    • ossim
    • opencv
    • liblas-devel
    • qt4-devel
    • swig
    • python
    • fftw-devel
    • libtiff
    • zlib-devel
    • libpng-devel
    • libpng-devel-vc
  10. Run the installation process
  11. Accept all the dependencies required by the selected packages
  12. Wait the downloading and the installation of the packages

Create a directory, where you have write access, to store your work (for example at C:\path\to\MyOTBDir). Organize your repository as it :

  • MyOTBDir\src
  • MyOTBDir\build
  • MyOTBDir\install

Retrieve the latest release of OTB: currently 3.20 (you can find the latest source here) and unzip it into the previous source directory.


Configure / Build / Install OTB

  • Create an OTB.bat file into your MyOTBDir and copy paste the following lines:
@echo off

call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat"

set /A ARGS_COUNT=0    
for %%A in (%*) do set /A ARGS_COUNT+=1  
if %ARGS_COUNT% NEQ 3 (goto :Usage)

if NOT DEFINED OSGEO4W_ROOT (goto :NoOSGEO4W)
	
set src_dir=%1
set build_dir=%2
set otb_install_dir=%3
set current_dir=%CD%

set LANG=C
set ITK_AUTOLOAD_PATH=
set PYTHONPATH=
set PATH=%OSGEO4W_ROOT%\apps\swigwin\;%PATH%

cd %build_dir%

cmake 	%src_dir% ^
	-G "Visual Studio 10" ^
	-DBUILD_EXAMPLES:BOOL=ON ^
	-DOTB_WRAP_QT:BOOL=ON ^
	-DOTB_WRAP_PYTHON:BOOL=ON ^
	-DPYTHON_LIBRARY:FILEPATH="%OSGEO4W_ROOT%/apps/Python27/libs/python27.lib" ^
	-DPYTHON_INCLUDE_DIR:PATH="%OSGEO4W_ROOT%/apps/Python27/include" ^
	-DPYTHON_EXECUTABLE:FILEPATH="%OSGEO4W_ROOT%/bin/python.exe" ^
        -DOTB_USE_OPENCV:BOOL=ON ^
        -DCMAKE_INSTALL_PREFIX:PATH=%otb_install_dir% ^
        -DCMAKE_CONFIGURATION_TYPES:STRING=Release;RelWithDebInfo

cmake --build . --target INSTALL --config Release

cd %current_dir%

goto :END

:Usage
echo You need to provide 3 arguments to the script: 
echo   1. path to the source directory
echo   2. path to the build directory (an empty directory)
echo   3. path to the installation directory (an empty directory)
GOTO :END

:NoOSGEO4W
echo You need to run this script from an OSGeo4W shell
GOTO :END

:END
  • into a OSGEo4W shell, run the OTB.bat with the right arguments: full path to the OTB src directory, full path to the OTB build directory, full path to the place where install OTB.
  • Take a break, you made it: OTB is installed in your install directory (should be C:\path\to\MyOTBDir\install).
  • If you want test: into an OSGeo4W shell, go to the bin directory of install directory and run otbViewer. With this small executable you can now visualize your image.
  • If you want build OTB in RelWithDebInfo config, into the OSGeo4W shell, open the OTB.sln and select this configuration from the configuration selector and build the solution.

Build your first application based on the OTB library

Create a directory (with write access) where to store your work (for example at C:\path\to\MyFirstCode). Organize your repository as it :

  • MyFirstCode\src
  • MyFirstCode\build

Follow the following steps:

  • Create a CMakeLists.txt into the src repository with the following lines:
project(MyFirstProcessing)

cmake_minimum_required(VERSION 2.8)

find_package(OTB REQUIRED)
include(${OTB_USE_FILE})

add_executable(MyFirstProcessing MyFirstProcessing.cxx )

target_link_libraries(MyFirstProcessing OTBCommon OTBIO )
  • Create a MyFirstProcessing.cxx into the src repository with the following lines:
#include "otbImage.h"
#include "otbVectorImage.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
#include "otbMultiToMonoChannelExtractROI.h"

int main(int argc, char* argv[])
{
  if (argc < 3)
  {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << "  inputImageFile  outputImageFile" << std::endl;
    return EXIT_FAILURE;
  }

  typedef unsigned short PixelType;
  typedef otb::Image <PixelType, 2> ImageType;
  typedef otb::VectorImage <PixelType, 2> VectorImageType;
  typedef otb::MultiToMonoChannelExtractROI <PixelType, PixelType> FilterType;
  typedef otb::ImageFileReader<VectorImageType> ReaderType;
  typedef otb::ImageFileWriter<ImageType> WriterType;

  FilterType::Pointer filter = FilterType::New();
  ReaderType::Pointer reader = ReaderType::New();
  WriterType::Pointer writer = WriterType::New();

  reader->SetFileName(argv[1]);
  filter->SetInput(reader->GetOutput());
  writer->SetFileName(argv[2]);
  writer->SetInput(filter->GetOutput());

  return EXIT_SUCCESS;
}
  • create a file named BuildMyFirstProcessing.bat into the MyFirstCode directory with the following lines:
@echo off

set /A ARGS_COUNT=0    
for %%A in (%*) do set /A ARGS_COUNT+=1  
if %ARGS_COUNT% NEQ 3 (goto :Usage)

if NOT DEFINED OSGEO4W_ROOT (goto :NoOSGEO4W)
	
set src_dir=%1
set build_dir=%2
set otb_install_dir=%3 
set current_dir=%CD%

cd %build_dir%

cmake %src_dir% ^
      -DCMAKE_INCLUDE_PATH:PATH="%OSGEO4W_ROOT%\include" ^
      -DCMAKE_LIBRARY_PATH:PATH="%OSGEO4W_ROOT%\lib" ^
      -DOTB_DIR:PATH=%otb_install_dir% ^
      -DCMAKE_CONFIGURATION_TYPES:STRING=Release

cmake --build . --target INSTALL --config Release

cd %current_dir%

goto :END

:Usage
echo You need to provide 3 arguments to the script: 
echo   1. path to the source directory
echo   2. path to the build directory
echo   3. path to the installation directory 
GOTO :END

:NoOSGEO4W
echo You need to run this script from an OSGeo4W shell
GOTO :END

:END
  • into a OSGEo4W shell, run the configure.bat with the right arguments: full path to your src directory, full path to your build directory, full path to the place where find OTBConfig.cmake file (should be C:\path\to\MyOTBDir\install\lib\otb).
  • into the OSGeo4W shell, open the MyFirstProcessing.sln
  • build the solution
  • into the OSGeo4W shell, go to the bin\Release directory and run MyFirstProcessing.exe. You can try for example with the otb_logo.tif file which can be found into the OTB source.