Forum

Author Topic: Python Scripts for Network Processing  (Read 3852 times)

smhese

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • jenacopterlabs
Python Scripts for Network Processing
« on: April 09, 2019, 01:52:38 PM »
Dear all,

we are setting up a cluster for network processing large UAV (mostly POI and Nadir) datasets in a cluster of Dell linux workstations. I can hardly find any code snippets for a python script that starts the processing on the job coordination server. I have three Nodes and one coordination server running already and sending jobs from the GUI is no problem but processing from a python routine would be much more efficient. Is there anywhere a FAQ available? the Python Metashape Manual is hardly showing the full "task" syntax here. Needed is the full processing from Alignment, Matching, DepthMaps, Dense Cloud, DSM , Ortho and las export.

This snippet seams to be a start:

import Metashape
client = Metashape.NetworkClient()
chunk = Metashape.app.document.chunk
task1 = Metashape.NetworkTask()
task1.name = ‚MatchPhotos‘
task1.chunks.append(chunk.key)
task1.downscale = 2
task1.params[‚keypoint_limit‘] = 40000
client = Metashape.NetworkClient()
path = „project.psx“
client.connect(‚XXX.XX.XX.XX‘)
batch_id = client.createBatch(path, [task1])
client.resumeBatch(batch_id)

Any ideas are welcome.  Kind regards! Sören


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14817
    • View Profile
Re: Python Scripts for Network Processing
« Reply #1 on: April 09, 2019, 03:21:20 PM »
Hello Sören,

I think some examples have been already published earlier, but anyway, below is a small example that exploits Metashape.Tasks sub-classes for more convenient operation:

Code: [Select]

import Metashape


path = Metashape.app.getOpenFileName("Specify path to the PSX document:")
root = Metashape.app.getExistingDirectory("Specify network root path:")

doc = Metashape.Document()
doc.open(path)
chunk = doc.chunk

network_tasks = list()


### match photos
task = Metashape.Tasks.MatchPhotos()
task.downscale = Metashape.Accuracy.HighAccuracy
task.keypoint_limit = 40000
task.tiepoint_limit = 4000
task.preselection_generic = True
task.preselection_reference = True
task.network_distribute = True

n_task = Metashape.NetworkTask()
n_task.name = task.name
n_task.params = task.encode()
n_task.frames.append((chunk.key, 0))
network_tasks.append(n_task)

###align cameras
task = Metashape.Tasks.AlignCameras()
task.adaptive_fitting = False
task.network_distribute = True

n_task = Metashape.NetworkTask()
n_task.name = task.name
n_task.params = task.encode()
n_task.frames.append(chunk.key)
network_tasks.append(n_task)

### depth maps
task = Metashape.Tasks.BuildDepthMaps()
task.downscale = Metashape.Quality.MediumQuality
task.filter_mode = Metashape.FilterMode.MildFiltering
task.network_distribute = True

n_task = Metashape.NetworkTask()
n_task.name = task.name
n_task.params = task.encode()
n_task.frames.append((chunk.key, 0))
network_tasks.append(n_task)

### dense cloud
task = Metashape.Tasks.BuildDenseCloud()
task.point_colors = True
task.network_distribute = True

n_task = Metashape.NetworkTask()
n_task.name = task.name
n_task.params = task.encode()
n_task.frames.append((chunk.key, 0))
network_tasks.append(n_task)

### DEM
task = Metashape.Tasks.BuildDem()
task.source_data = Metashape.DataSource.DenseCloudData
task.interpolation = Metashape.Interpolation.Extrapolated
task.projection = chunk.crs
task.network_distribute = True

n_task = Metashape.NetworkTask()
n_task.name = task.name
n_task.params = task.encode()
n_task.frames.append((chunk.key, 0))
network_tasks.append(n_task)


### Orthomosaic
task = Metashape.Tasks.BuildOrthomosaic()
task.ortho_surface = Metashape.DataSource.ElevationData
task.resolution = 0.05
task.projection = chunk.crs
task.blending_mode = Metashape.BlendingMode.MosaicBlending
task.network_distribute = True

n_task = Metashape.NetworkTask()
n_task.name = task.name
n_task.params = task.encode()
n_task.frames.append((chunk.key, 0))
network_tasks.append(n_task)

#### export
task = Metashape.Tasks.ExportPoints()
task.data_source = Metashape.DataSource.DenseCloudData
task.format = Metashape.PointsFormat.PointsFormatLAS
task.export_colors = True
task.coordinates = chunk.crs
task.path = "\\export\\point_cloud.las"

n_task = Metashape.NetworkTask()
n_task.name = task.name
n_task.params = task.encode()
n_task.frames.append((chunk.key, 0))
network_tasks.append(n_task)


### running processing:

client = Metashape.NetworkClient()
client.connect("192.168.0.2") #server ip
batch_id = client.createBatch(path[len(root):], network_tasks)
client.resumeBatch(batch_id)

Hope there are no typos, but general idea is shown anyway.
« Last Edit: April 20, 2019, 07:41:57 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

smhese

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • jenacopterlabs
Re: Python Scripts for Network Processing
« Reply #2 on: April 12, 2019, 09:08:02 AM »
excellent Alexey! thats really helpful!