Forum

Author Topic: Using "generateMasks" to import masks only for a selection of cameras  (Read 760 times)

Mettigel

  • Newbie
  • *
  • Posts: 4
    • View Profile
Hi,

How do I import masks in form of a .jpg file and assign them to the corresponding cameras without getting an error and interrupting my script.
Only a few of my cameras need to be masked and I would like to make the script find them and create a list containing the cameras I have masks for.

Code: [Select]
    chunk.generateMasks(path=f"{input_path}{os.path.sep}masks{os.path.sep}"+"{filename}.jpg",
                        masking_mode=Metashape.MaskingMode.MaskingModeFile,
                        cameras=chunk.cameras)

Thank you very much in advance

Mettigel

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13917
    • View Profile
Hello Mettigel,

Aren't masks generated for those few cameras, as required, despite the warning messages for other cameras?

Though, you may need to modify cameras=chunk.cameras to cameras=[c.key for c in chunk.cameras if c.type == Metashape.Camera.Type.Regular].
Best regards,
Alexey Pasumansky,
Agisoft LLC

Mettigel

  • Newbie
  • *
  • Posts: 4
    • View Profile
Thank you for your reply, Alexey.
Yes, the masks are assigned to the right cameras despite the error message. I am trying to automate my workflow and the error message stops the script from continuing. Is there a way to suppress the message box popping up?

Quote
Though, you may need to modify cameras=chunk.cameras to cameras=[c.key for c in chunk.cameras if c.type == Metashape.Camera.Type.Regular]

What does this do?

Mettigel

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13917
    • View Profile
Hello Mettigel,

cameras=[c.key for c in chunk.cameras if c.type == Metashape.Camera.Type.Regular] - provides the list of int, as required for cameras argument, unique id of each camera in the chunk, excluding animation cameras, if any.

As for the original issue, I think, you can use try/except concept to avoid the script being terminated by "RuntimeError: Can't open file" message related to missing mask images. Note that in case of corrupted mask file the exception will be different: "RuntimeError: Can't load image".

Another possible solution is to get the list of mask files in the source folder, then form the list of cameras to be used in generateMasks.
Best regards,
Alexey Pasumansky,
Agisoft LLC