Forum

Author Topic: Align Photos Step  (Read 4612 times)

AnnieOwl

  • Newbie
  • *
  • Posts: 4
    • View Profile
Align Photos Step
« on: February 10, 2020, 08:13:04 PM »
Hello everyone.
I have a python script that creates new Agisoft project with a bunch of network processign tasks (MatchPhotos, AlignCameras, BuildDepthMaps, BuildModel) to build a 3D model from a set of images, and then sends this tasks to Agisoft server to process them. On some datasets Align Photos step (MatchPhotos and AlignCameras tasks) fails to match a lot of photos (almost half of the photos from data set). However, when i launch created project and manualy start Align Photos step through GUI with the same parameters as i set in script, all of the photos are matched.

Did anyone encountered such a problem? What am I missing? Is the GUI Align Photos step has some functionality other than MatchPhotos and AlignCameras? How can i change my script, so it works the same as GUI Align Photos.

The screenshot of Align Photos step settings in GUI is in attached files.

And here is my python script that starts processing:
Code: [Select]
import os
import glob
import argparse
import json
import Metashape


parser = argparse.ArgumentParser()
parser.add_argument("--config")

args = parser.parse_args()

if args.config is None:
  exit(1)

with open(args.config, 'r') as f:
  config = json.load(f)

root = '/data'
img_dir = root + "/" + config['agisoft']['img_dir']
out_dir = root + "/" + config['agisoft']['out_dir']
proj_path = root + "/" + config['agisoft']['proj_name']

doc = Metashape.app.document

image_files = []
for r, d, f in os.walk(img_dir):
  for file in f:
    lowerFile = file.lower()
    if '.jpg' in lowerFile:
      image_files.append( os.path.join(r, file) )

chunk = doc.addChunk()
chunk.addPhotos(paths=image_files,strip_extensions=False)

doc.save(proj_path)

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 = False
task.reset_matches = 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.reset_alignment = 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)

### build depth maps
task = Metashape.Tasks.BuildDepthMaps()
task.downscale = Metashape.Quality.HighQuality
task.filter_mode = Metashape.MildFiltering
task.reuse_depth = 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)

### build model
task = Metashape.Tasks.BuildModel()
task.surface_type = Metashape.Arbitrary
task.interpolation = Metashape.EnabledInterpolation
task.face_count = Metashape.HighFaceCount
task.source_data = Metashape.DataSource.DepthMapsData
task.vertex_colors = True
task.volumetric_masks = False

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)

### build UV
task = Metashape.Tasks.BuildUV()
task.mapping_mode = Metashape.GenericMapping
task.texture_count = 1

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)

### build texture
task = Metashape.Tasks.BuildTexture()
task.blending_mode = Metashape.MosaicBlending
task.texture_size = 2048
task.fill_holes = True
task.ghosting_filter = 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 model
modeldir_path = out_dir + "/model"
if not os.path.exists(modeldir_path): os.mkdir(modeldir_path)

task = Metashape.Tasks.ExportModel()
task.path = modeldir_path + "/model.obj"
task.format = Metashape.ModelFormat.ModelFormatOBJ
task.texture_format = Metashape.ImageFormat.ImageFormatJPEG
task.export_colors = False
task.export_texture = True
task.export_uv = 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)

### start network processing
client = Metashape.NetworkClient()
client.connect(config['agisoft']['ip'], config['agisoft']['port'])
batch_id = client.createBatch(proj_path, network_tasks)
client.resumeBatch(batch_id)

tasks_list = client.batchStatus(batch_id)['tasks']
step_number = 0
steps_count = len(tasks_list)
ctask = tasks_list[step_number]
« Last Edit: February 10, 2020, 08:14:44 PM by AnnieOwl »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15276
    • View Profile
Re: Align Photos Step
« Reply #1 on: February 11, 2020, 09:17:07 PM »
Hello Andrey,

Looks to be rarely reproducible bug of the version 1.5. Via support ticket we have sent the tweak that should solve the problem in the older version (the processing performance, however, will be affected).
The tweak should be created on the side of the machine which submits the job to the network.

You can check if the tweak is applied on the client's side by printing out the output of the following line:
Code: [Select]
Metashape.app.settings.value(tweak_name)Where tweak name is a string, for example "main/some_name".
Best regards,
Alexey Pasumansky,
Agisoft LLC