Forum

Author Topic: Metashape.Document.alignChunks - Error: Operation not applicable  (Read 5130 times)

undercover

  • Newbie
  • *
  • Posts: 2
    • View Profile
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:

Code: [Select]
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:

Code: [Select]
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!

undercover

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Metashape.Document.alignChunks - Error: Operation not applicable
« Reply #1 on: August 13, 2020, 10:51:05 AM »
How is "Metashape.Document.alignChunks" supposed to be used? I wonder if I use it the correct way, it is hard to tell from the documentation what the parameters chunks and reference are? I would assume they are indices? I attached a screenshot that shows the documentation for Metashape.Document.alignChunks. Any ideas why I get "Error: Operation not applicable" with my code? I can also provide my sample code if it would be to any help.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15465
    • View Profile
Re: Metashape.Document.alignChunks - Error: Operation not applicable
« Reply #2 on: December 03, 2020, 02:55:36 PM »
Hello undercover,

alignChunks and mergeChunks operations take the list of chunk.key elements (and not chunk indices in the active project), when the "list of int" should be passed. For the reference chunk in the chunk alignment operation you should also use .key of the related chunk.
Best regards,
Alexey Pasumansky,
Agisoft LLC