Agisoft Metashape
Agisoft Metashape => Python and Java API => Topic started by: Mettigel on June 28, 2022, 01:43:58 PM
-
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.
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
-
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].
-
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?
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
-
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.