How Can I set projection to numpy array input from Python API?


I am trying to use Segmentation app from Python API.
Input raster data is passed as numpy array, but I couldn’t find a way to give projection information to the app.

I know that I can generate geotiff with projection metadatas with rasterio, and give the file as app’s input.
But, since the input data is created from upstream process, I want to avoid the array to write on a disk as a file such as GeoTiff to reduce I/O overhead.

Configuration setup

Minimum setup which I tried so far:

import numpy as np
import otbApplication as otb

params = {
    'filter': 'meanshift',
    'mode': 'vector',
array = np.random.random(30000).reshape(100, 100, 3)
app = otb.Registry.CreateApplication('Segmentation')
app.SetVectorImageFromNumpyArray('in', array)

and raise following error.

RuntimeError                              Traceback (most recent call last)
Cell In[37], line 12
     10 app.SetVectorImageFromNumpyArray('in', array)
     11 app.SetParameters(params)
---> 12 app.Execute()
     13 # app_out = ExtractROI.GetVectorImageAsNumpyArray('out')
     14 # app_out

File ~/Documents/git/cellcounter/otb/lib/otb/python/, in Application.Execute(self)
   2444 def Execute(self):
-> 2445     return _otbApplication.Application_Execute(self)

RuntimeError: Exception thrown in otbApplication Application_Execute: ../Modules/Core/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx:152:
itk::ERROR: No OGR driver known to OTB to create and handle a DataSource named <>.

I found that I need to add output shapefile path for vector mode, otherwise use raster mode, as follows.

The issue was not related to projections but missing some required args.

params = {
    'filter': 'meanshift',
    'mode': 'vector',
    'mode.vector.out': 'out.shp',
params = {
    'filter': 'meanshift',
    'mode': 'raster',