Skip to content
Snippets Groups Projects
Commit 31574fde authored by Rashad Kanavath's avatar Rashad Kanavath
Browse files

Merge remote-tracking branch 'origin/enhance_python_wrapping' into develop

parents 9369ccf6 63465524
Branches
Tags
No related merge requests found
# - Find Numpy
# Find the native numpy includes
#
# NUMPY_FOUND - True if Numpy headers are found.
# NUMPY_INCLUDE_DIR - where to find numpy/arrayobject.h, etc.
EXEC_PROGRAM ("${PYTHON_EXECUTABLE}"
ARGS "-c 'import numpy; print numpy.get_include()'"
OUTPUT_VARIABLE NUMPY_INCLUDE_DIR
RETURN_VALUE NUMPY_NOT_FOUND)
if( NUMPY_INCLUDE_DIR MATCHES "Traceback" )
# Did not successfully include numpy
set( NUMPY_INCLUDE_DIR )
else()
set( NUMPY_INCLUDE_DIR ${NUMPY_INCLUDE_DIR} CACHE STRING "Numpy include path." )
endif()
include( FindPackageHandleStandardArgs )
FIND_PACKAGE_HANDLE_STANDARD_ARGS( Numpy DEFAULT_MSG NUMPY_INCLUDE_DIR )
mark_as_advanced( NUMPY_INCLUDE_DIR )
if(NUMPY_FOUND)
set(NUMPY_INCLUDE_DIRS ${NUMPY_INCLUDE_DIR})
else()
set(NUMPY_INCLUDE_DIRS)
endif()
......@@ -25,6 +25,7 @@ if ( OTB_WRAP_PYTHON )
check_PIC_flag ( Python )
find_package ( PythonLibs REQUIRED )
find_package ( PythonInterp REQUIRED )
find_package ( Numpy )
endif()
#
......
......@@ -24,6 +24,9 @@ if ( OTB_WRAP_PYTHON )
# Run swig
set(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_GLOBAL_FLAGS})
if(NUMPY_FOUND)
list(APPEND CMAKE_SWIG_FLAGS "-DOTB_SWIGNUMPY=1")
endif()
set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR})
set(SWIG_MODULE_otbApplication_EXTRA_DEPS
${CMAKE_CURRENT_SOURCE_DIR}/Python.i
......@@ -42,7 +45,7 @@ if ( OTB_WRAP_PYTHON )
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/CMake/PythonCompile.py otbApplication.py
DEPENDS _otbApplication
)
otb_module_target_label( _otbApplication )
install( TARGETS _otbApplication
......@@ -80,7 +83,7 @@ if ( OTB_WRAP_JAVA )
# Add target for org.otb.Application.jar
add_custom_target(org_otb_Application_jar ALL DEPENDS org.otb.application.jar)
otb_module_target_label( org_otb_Application_jar )
# Add custom command and target to compile the generated files and put them in a jar file
......@@ -106,4 +109,3 @@ if ( OTB_WRAP_JAVA )
COMPONENT RuntimeLibraries )
endif()
This diff is collapsed.
This diff is collapsed.
......@@ -6,13 +6,16 @@
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
Copyright:
Centre National d'Etudes Spatiales,
CS Systemes d'information.
See OTBCopyright.txt, CSCopyright.txt for details.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbWrapperSWIGIncludes_h
......@@ -27,5 +30,7 @@ typedef otb::Wrapper::Application::Pointer Application_Pointer;
typedef otb::Wrapper::ApplicationRegistry Registry;
typedef otb::Wrapper::AddProcessToWatchEvent AddProcessToWatchEvent;
typedef otb::Wrapper::DocExampleStructure DocExampleStructure;
typedef otb::Wrapper::Parameter Parameter;
typedef otb::Wrapper::OutputImageParameter OutputImageParameter;
typedef otb::Wrapper::InputImageParameter InputImageParameter;
#endif
......@@ -72,3 +72,14 @@ add_test( NAME pyTvBandMathInXML
${TEMP}/pyTvBandMathInXML.tif
)
add_test( NAME pyTvNumpyIO
COMMAND ${TEST_DRIVER} Execute
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PythonNumpyTest.py
${OTB_DATA_ROOT}/Examples/ROI_QB_MUL_1_SVN_CLASS_MULTI.png
${TEMP}/pyTvNumpyIO_SmoothingOut.png )
add_test( NAME pyTvNewStyleParameters
COMMAND ${TEST_DRIVER} Execute
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PythonNewStyleParametersTest.py
${OTB_DATA_ROOT}/Input/poupees.tif
${TEMP}/pyTvNewStyleParametersTest.tif )
# -*- coding: utf-8 -*-
# Authors: Rashad Kanavath <rashad.kanavath@c-s.fr>
# Julien Malik <julien.malik@c-s.fr>
#
# Copyright: (c) CS Systemes d'information. All rights reserved
#
# Example on the use of otb "pythonization"
#
from sys import argv
import otbApplication as otb
def cm_assert(a,b):
print "debug print before assert check: '%s'== '%s'" %(a, b)
assert a == b
app = otb.Registry.CreateApplication('OrthoRectification')
#test GetParameterTypeAsString() method in python.
print app.GetParameterTypeAsString(otb.ParameterType_InputImage)
print app.GetParameterTypeAsString(otb.ParameterType_String)
print app.GetParameterTypeAsString(otb.ParameterType_Empty)
# one test for each parameter type (string, float, int, ...)
# # parameter group io.in
# 1 - input image parameter set
app.IO.IN = argv[1]
cm_assert(app.GetParameterString('io.in'), argv[1])
# 2 - input image parameter get
cm_assert(app.IO.IN, argv[1])
# # parameter group io.in
# 3 - output image parameter set
app.IO.OUT = argv[2]
cm_assert(app.GetParameterString('io.out'), argv[2])
# 4 - output image parameter get
cm_assert(app.IO.OUT, argv[2])
# 5 - choice with sub parameters set
app.MAP = 'lambert2'
cm_assert(app.GetParameterString('map'), 'lambert2')
# 5.1 - choice with sub parameters get
app.SetParameterString('map', 'wgs')
cm_assert('wgs', app.MAP)
# 5.2 - choice with sub parameters set
app.MAP = 'lambert93'
cm_assert('lambert93', app.GetParameterString('map'))
# 5.3 - choice with sub parameters set
app.SetParameterString('map', 'epsg')
cm_assert(app.MAP, 'epsg')
# 6 - int type 2nd level sub parameters of choice parameter set
app.MAP.EPSG.CODE = 32768
cm_assert(32768, app.GetParameterInt('map.epsg.code'))
# 7 - another choice with sub parameters set
app.MAP = 'utm'
cm_assert('utm', app.GetParameterString('map'))
# 8 - int type sub parameters of choice parameter set
app.MAP.UTM.ZONE = 47
cm_assert(47,app.GetParameterInt('map.utm.zone'))
# 9 - int type sub parameters of choice parameter get
app.SetParameterInt('map.utm.zone', 31)
cm_assert(app.MAP.UTM.ZONE, 31)
# 10 - bool type sub parameters of choice parameter get
app.DisableParameter('map.utm.northhem')
cm_assert(app.MAP.UTM.NORTHHEM, False)
# 11 - bool type sub parameters of choice parameter set
app.MAP.UTM.NORTHHEM = True
cm_assert(True, app.IsParameterEnabled('map.utm.northhem') )
#12 - simple choice parameter set
app.OUTPUTS.MODE = 'auto'
cm_assert('auto', app.GetParameterString('outputs.mode'))
#13 - simple choice parameter get
app.SetParameterString('outputs.mode', 'orthofit')
cm_assert(app.OUTPUTS.MODE, 'orthofit')
#14 - inputxml parameter set
app.INXML = 'input.xml'
cm_assert(app.GetParameterString('inxml'), 'input.xml')
#15 - outputxml parameter get
app.SetParameterString('outxml', 'output.xml')
cm_assert("output.xml", app.OUTXML)
#16 - parameter float get
app.SetParameterFloat('elev.default', 5.0)
cm_assert(5.0, app.ELEV.DEFAULT)
#17 -parameter float set
app.ELEV.DEFAULT = -2.5
cm_assert(app.GetParameterFloat('elev.default'), -2.5)
#18 - parameter ram get
app.SetParameterString('opt.ram', '256')
cm_assert(256, app.OPT.RAM)
#19 - parameter ram set
app.OPT.RAM = '512'
cm_assert(app.GetParameterInt('opt.ram'), 512)
#20 - parameter bool set
app.OUTPUTS.ISOTROPIC = True
cm_assert(app.IsParameterEnabled('outputs.isotropic'), True)
#21 - parameter bool get
app.DisableParameter('outputs.isotropic')
cm_assert(False, app.OUTPUTS.ISOTROPIC)
#Do not execute. we need LARGEINPUT. so we tried a small application
#app.Execute()
app = None
app = otb.Registry.CreateApplication('Smoothing')
app.IN = argv[1]
app.TYPE='anidif'
app.OUT = argv[2]
app.ExecuteAndWriteOutput()
# -*- coding: utf-8 -*-
# Author: Rashad Kanavath <rashad.kanavath@c-s.fr>
#
# Copyright: (c) CS Systemes d'information. All rights reserved
#
# Example on testing numpy
#
import sys
import os
#from scipy import misc
import numpy as np
import otbApplication
#from PIL import Image as PILImage
inFile = sys.argv[1]
outFile = sys.argv[2]
# pilimage = PILImage.open(inFile)
# npimage = np.asarray(pilimage)
# print npimage.dtype
ExtractROI = otbApplication.Registry.CreateApplication("ExtractROI")
ExtractROI.SetParameterString("in", inFile)
ExtractROI.SetParameterInt("startx", 10)
ExtractROI.SetParameterInt("starty", 10)
ExtractROI.SetParameterInt("sizex", 250)
ExtractROI.SetParameterInt("sizey", 250)
#Bug or Design ?.
#Anyway below two is needed only for ExtractROI application
ExtractROI.SetParameterUserValue("sizex", True)
ExtractROI.SetParameterUserValue("sizey", True)
ExtractROI.Execute()
ExtractROIOut = ExtractROI.GetVectorImageAsNumpyArray("out", 'float')
#write RGB image to file via python
#misc.imsave('ExtractROIOut.jpg', ExtractROIOut)
Rescale = otbApplication.Registry.CreateApplication("Rescale")
#take numpy array from ExtractROI and feed into Rescale
Rescale.SetVectorImageFromNumpyArray("in", ExtractROIOut)
Rescale.SetParameterFloat("outmin", 50, True)
Rescale.SetParameterFloat("outmax", 100, True)
Rescale.Execute()
RescaleOut = Rescale.GetVectorImageAsNumpyArray("out", 'float')
#misc.imsave('RescaleOut.jpg', RescaleOut)
Convert = otbApplication.Registry.CreateApplication("Convert")
#take numpy output from Rescale application and feed into Convert
Convert.SetVectorImageFromNumpyArray("in", RescaleOut)
Convert.SetParameterString("out", "ConvertOut.png")
Convert.ExecuteAndWriteOutput()
ConvertOut = Convert.GetVectorImageAsNumpyArray("out", 'float')
Smoothing = otbApplication.Registry.CreateApplication("Smoothing")
#take numpy output from Convert application and feed into Smoothing
Smoothing.SetVectorImageFromNumpyArray("in", ConvertOut)
Smoothing.SetParameterString("type", 'anidif')
Smoothing.SetParameterString("out", outFile)
Smoothing.ExecuteAndWriteOutput()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment