Forum

Author Topic: Process cloud project through Python  (Read 1642 times)

DocPopi

  • Newbie
  • *
  • Posts: 28
    • View Profile
Process cloud project through Python
« on: August 17, 2022, 03:39:07 PM »
Hello again  :D

I have another problem concerning the processing of a project on the Cloud. Here is my script:

Code: [Select]
import Metashape
from os import path, listdir


def import_images(chunk):
    img_folder = path.join(My, Path, Joined)
    img_list = listdir(img_folder)
   
    for i in img_list:
        new_path = path.join(img_folder, i)
        print(new_path)
        chunk.addPhotos([new_path])

def build_task_list(tasks):
    '''Match photos'''
    task = Metashape.Tasks.MatchPhotos()
    task.downscale = 0
    task.keypoint_limit = 40000
    task.tiepoint_limit = 4000
    task.generic_preselection = True
    task.reference_preselection = True

    # '''Compile the match photos task'''
    # n_task = Metashape.NetworkTask()
    # n_task.name = task.name
    # n_task.params = task.encode()
    # n_task.frames.append((chunk.key, 0))
    # tasks.append(n_task)

    tasks.append(task)


    return tasks


def main():

    output_path = path.join(Another, Path, Joined)
    tasks = []
    doc = Metashape.Document()
    doc.save(output_path)
    chunk = doc.addChunk()
    import_images(chunk)
    tasks = build_task_list(tasks)
    doc.save()

 
    client = Metashape.CloudClient()
    client.username = **********
    client.password = ************

    client.processProject(doc,tasks)



main()


The problem is that once the code gets to the "client.processProject' part, I get an error saying that a "Task object is expected".

I found another post on this forum with a similar problem (https://www.agisoft.com/forum/index.php?topic=13259.msg58833#msg58833) but there was no answer. I also tried to follow https://www.agisoft.com/forum/index.php?topic=10734.0, but here I get an error saying that the Method is not allowed. Of course, I have also been combing the user reference manual, but I haven't found anything that could help me further.

Thank you in advance for your help :) 

Popi

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14840
    • View Profile
Re: Process cloud project through Python
« Reply #1 on: August 17, 2022, 04:13:05 PM »
Hello Popi,

Actually, you need to pass the list of NetworkTask objects to client.processProject.

Easy way to transform Task to NetworkTask is shown in lines 110-115 of the following script example:
https://github.com/agisoft-llc/metashape-scripts/blob/master/src/samples/network_processing.py
Best regards,
Alexey Pasumansky,
Agisoft LLC

DocPopi

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Process cloud project through Python
« Reply #2 on: August 17, 2022, 04:45:47 PM »
Hi Alexey,

Thank you for your answer. I tried but I now have the "Method not allowed (405) " error. Here is what I wrote:

Code: [Select]
def build_task_list(tasks, doc, chunk):
    '''Match photos'''
    network_tasks = []
    task = Metashape.Tasks.MatchPhotos()
    task.downscale = 0
    task.keypoint_limit = 40000
    task.tiepoint_limit = 4000
    task.generic_preselection = True
    task.reference_preselection = True
    tasks.append(task)

    for t in tasks:
        if t.target == Metashape.Tasks.DocumentTarget:
            network_tasks.append(t.toNetworkTask(doc))
        else:
            network_tasks.append(t.toNetworkTask(chunk))

    return network_tasks


def main():

    output_path = path.join(My, Super, Path)

    tasks = []
    doc = Metashape.Document()
    doc.save(output_path)
    chunk = doc.addChunk()
    import_images(chunk)
    network_tasks = build_task_list(tasks, doc, chunk)
    doc.save()

     # Go retrieve the projects on the cloud
    client = Metashape.CloudClient()
    client.username = ****************
    client.password = ********************
   
    client.processProject(doc,network_tasks)



main()

But now the error says
"Exception : Error transferring https://api.agisoft.com:8086/v1.4/projects//processes - server replied: Method Not Allowed (status code: 405)".

What did I do wrong? I admit I'm not sure to understand the code you sent me, so maybe I didn't adapt it enough to my case.

Thank you again,

Popi

DocPopi

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Process cloud project through Python
« Reply #3 on: August 22, 2022, 04:39:48 PM »
Sorry, I'm taking the liberty of upping this topic, because I still couldn't find the solution ^^

Best regards,

Popi

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14840
    • View Profile
Re: Process cloud project through Python
« Reply #4 on: August 23, 2022, 01:46:53 PM »
Hello Popi,

What Metashape version and build number you are using? I have tried to replicate the issue using your code, but it successfully starts the processing in the Cloud.
Best regards,
Alexey Pasumansky,
Agisoft LLC

DocPopi

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Process cloud project through Python
« Reply #5 on: August 23, 2022, 04:28:10 PM »
Hello Alexey,

Thank you for your answer. I'm using Metashape Professional 1.8.4, build 14671(64bit).

Am I using the right version?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14840
    • View Profile
Re: Process cloud project through Python
« Reply #6 on: August 23, 2022, 07:23:12 PM »
Hello Popi,

You should upload the project to the cloud first: client.uploadProject(doc) and then call client.processProject()
Best regards,
Alexey Pasumansky,
Agisoft LLC

DocPopi

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Process cloud project through Python
« Reply #7 on: August 24, 2022, 11:06:33 AM »
Hey Alexey,

God I feel stupid, I had actually commented that line, but it was there all the time :) It works now, thank you so much!

Best,

Popi