Forum

Author Topic: batch network processing  (Read 7696 times)

jgillan

  • Newbie
  • *
  • Posts: 12
    • View Profile
batch network processing
« on: September 28, 2019, 03:23:32 AM »
Hello All,

I'm having a difficult time getting network processing to run with headless python. I can get it to work for a single command (e.g., MatchPhotos).

path = "\\1a_u6\\Metashape_Project.psx"

### match photos
task = Metashape.Tasks.MatchPhotos()
task.downscale = Metashape.Accuracy.MediumAccuracy
task.keypoint_limit = 50000
task.tiepoint_limit = 0
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))

client = Metashape.NetworkClient()
client.connect('10.1.2.234')
batch_id = client.createBatch(path, [n_task])
client.resumeBatch(batch_id)

doc.save()



But am unable to execute multiple commands (e.g., MatchPhotos + AlignCameras) using Alexey's code:


path = "/1a_u6/Metashape_Project.psx"
root = "/xdisk/jgillan"

network_tasks = list()

### match photos
task = Metashape.Tasks.MatchPhotos()
task.downscale = Metashape.Accuracy.MediumAccuracy
task.keypoint_limit = 50000
task.tiepoint_limit = 0
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 = 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)
network_tasks.append(n_task)

client = Metashape.NetworkClient()
client.connect('10.1.2.234')
batch_id = client.createBatch(path[len(root):], network_tasks)
client.resumeBatch(batch_id)

doc.save()


The 'client.createBatch' line appears to be the problem. I've tried writing that line of code a hundred different ways and tried changing the formatting of the path and root a hundred different ways. It always throws the error 'value is a not a tuple'.

I'm using Linux version 1.5.5.9097
Python 3.7

Please help. :'(


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15691
    • View Profile
Re: batch network processing
« Reply #1 on: September 28, 2019, 02:30:31 PM »
Hello jgillan,

Does it help, if you use the same path definition in the second code, as in the first example?

The path passed to createBatch should correspond to the relative path from the root to the project file.
Best regards,
Alexey Pasumansky,
Agisoft LLC

jgillan

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: batch network processing
« Reply #2 on: September 28, 2019, 08:06:53 PM »
Unfortunately, results are exactly the same using:

path = "\\1a_u6\\Metashape_Project.psx"
root = "\\xdisk\\jgillan"

Here is the entire code below. See anything suspicious in there? What has me perplexed is that I can run a single task but not multiple using your list () method.

#This python script (python3) uses Agisoft Metashape to generate point clouds and orthomosaics from a set of overlapping drone images. It runs in headless mode, meaning the user never has to open the Metashape GUI.
##This script should be deployed from the linux terminal.
##Type the following two lines of code into the terminal. The first path (on the 2nd line) is the location of this python file. The second path is the location of drone images.

##cd /mnt/DATA/DOWNLOADS/SOFTWARE/METASHAPE/metashape-pro
##metashape.sh -r "/xdisk/jgillan/metashape-script.py" "/xdisk/jgillan/1a_u6"

import os
import Metashape, sys


##this line is pointing to the path of drone photos that you specified in the Command Prompt code
path_photos = sys.argv[1]

# set new working directory to be in working folder set in command line
os.chdir(path_photos)

##Define: PhotoScan Project File
MetashapeProjectFile = ".\\Metashape_Project.psx"
##get main app objects
doc = Metashape.Document()
doc.save(MetashapeProjectFile)

app = Metashape.Application()

## create chunk
chunk = doc.addChunk()

## loading images
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
    if ("jpg" or "jpeg" or "JPG" or "JPEG") in photo.lower():
        photo_list.append(path_photos + "/" + photo)
chunk.addPhotos(photo_list)

##This loads the accuracy of the camera position at time of exposure (stored in the image exif). If you don't do this, Agisoft will assume 10 m accuracy. The accuracy of the RTK drone images is generally 1-2 cm.
chunk.loadReferenceExif(load_rotation=True, load_accuracy=True)

##SAVE PROJECT
doc.save()


path = "\\Metashape_Project.psx"
root = "\\xdisk\\jgillan"

network_tasks = list()

### match photos
task = Metashape.Tasks.MatchPhotos()
task.downscale = Metashape.Accuracy.MediumAccuracy
task.keypoint_limit = 50000
task.tiepoint_limit = 0
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 = 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)
network_tasks.append(n_task)

client = Metashape.NetworkClient()
client.connect('10.1.2.234')
batch_id = client.createBatch(path[len(root):], network_tasks)
client.resumeBatch(batch_id)

doc.save()

geponce

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: batch network processing
« Reply #3 on: October 01, 2019, 10:08:27 PM »

Missing parameter...

The problem is in the AlignCameras() section, one parameter is missing in the task frame append method, with the missing chunk index.

Change this:
n_task.frames.append(chunk.key) 

to this...
n_task.frames.append((chunk.key, 0)) 

...and the 'TypeError : value is not a tuple' will be gone.

G