Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: eastonmbio on April 07, 2021, 05:36:48 PM

Title: Mixing of network and non-network processes in the same script
Post by: eastonmbio on April 07, 2021, 05:36:48 PM
I'm looking to develop a script for network processing whereby tasks that are able to be done using network processing are mixed with those that do not fit in to the "tasks" classification.

For example, Photo alignment (network) then dense cloud generation (network), and dense cloud filtering based on point color (non-network), and so on. I'm unsure if I am able to do this. I think I would need to send the cleaning tasks to the network as queued jobs, but am unsure how I would go about this. If I was to simply insert code with the goal of point cloud cleaning, it would appear to run immediately, and execute on a point cloud that did not yet exist. The problem would persist I think, if I loaded several scripts into the batch processing window, to be executed one after the other.

The only solution I could think of is embedding any non-network tasks into a loop routine that checks whether the necessary point cloud exists before executing the code, waiting an arbitrary amount of time before running again?

An example of two sections of code I'd like to integrate is:

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

client=Metashape.NetworkClient()

network_tasks = list()

task = Metashape.Tasks.MatchPhotos()
task.network_distribute = True
task.downscale = 1
task.keypoint_limit = 40000
task.tiepoint_limit = 4000

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)

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,0))
network_tasks.append(n_task)

task = Metashape.Tasks.BuildDepthMaps()
task.downscale = 4
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)

task = Metashape.Tasks.BuildDenseCloud()
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)


client.connect('metashape-qmgr.aims.gov.au')
batch_id = client.createBatch(path[len(root):], network_tasks)
client.resumeBatch(batch_id)
print("Job Started...")


I would like to integrate this with:

Code: [Select]

dense_cloud = chunk.dense_cloud

dense_cloud.selectPointsByColor(color=[85,170,255], tolerance=35, channels='RGB')
dense_cloud.removeSelectedPoints()


I would like this to be followed by mesh building.

I have seen this question asked before, but no answers were given.

Thanks.