Hi!
I am making a script for Agisoft Metashape Professional that should align all chunks against the selected chunk. Short background is that we had some problem with the scale not being correct when using align chunks in a batch process, but we could get correct result if align chunks was done manually one by one against the reference chunk, so that is why only one chunk is processed at a time in the script below.
I have read the documentation pdf and there was some ambiguity in the documentation for alignChunks,
chunks (list of int) – List of chunks to be aligned.
reference (int) – Chunk to be used as a reference.
I assume type int is supposed to represent the indices of the chunks, I also tried to use
Chunk.key - Chunk identifier. - Type int without any success.
I came up with the following code:
import Metashape
doc = Metashape.app.document
reference_chunk = doc.chunk
chunks = doc.chunks
# Find index for reference chunk
reference_chunk_index = -1
for i in range(len(chunks)):
if reference_chunk.key == chunks[i].key:
reference_chunk_index = i
for i in range(len(chunks)):
if reference_chunk_index == i:
continue
chunk = chunks[i]
print("Aligning " + chunk.label + " against " + reference_chunk.label + "...")
chunks_to_process = [i]
doc.alignChunks(chunks_to_process, reference_chunk_index)
When I execute the script in Metashape with the project loaded, I get the following error:
AlignChunks: method = Point based, fix scale = 0, accuracy = High, preselection = none, keypoint limit = 40000, apply masks = 0, filter tie points = 0
Finished processing in 0.002 sec (exit code 0)
Traceback (most recent call last):
File "C:/Users/User/AppData/Local/Agisoft/Metashape Pro/scripts/align_chunks.py", line 37, in <module>
doc.alignChunks(chunks_to_process, reference_chunk_index)
Exception: Operation not applicable
Error: Operation not applicable
Any help or suggestion would be appreciated!