Agisoft Metashape
Agisoft Metashape => Python and Java API => Topic started by: 2door on February 11, 2017, 03:51:47 AM
-
Hello everyone.
I am trying to load masks for a model such that I have my images in project/jpg/someimage_001.jpg and my masks in project/masks/someimage_001_mask.jpg. I looked at the API and found the importMasks function. I know that they can be loaded based on a naming convention but I can't quite get my head around it. Any help would be appreciated.
ImageDirectory = path + "/jpg/"
MasksDirectory = path + "/masks/"
images = []
for photo in os.listdir (ImageDirectory):
if ("jpg" in photo.lower()) or ("jpeg" in photo.lower()):
images.append(photo)
chunk.addPhotos(images)
for mask in os.listdir (MasksDirectory):
if ("jpg" in mask.lower()) or ("jpeg" in photo2.lower()):
chunk.importMasks(path=mask,source=PhotoScan.MaskSourceBackground,operation=PhotoScan.MaskOperationDifference,tolerance=10,cameras=chunk.cameras)
EDIT:
I found the API difference and edited my OP. How do you pass a file naming template in the path parameter? Also does the optional camera parameter work. The above code is what I presently have and it doesn't throw an error. Does the template act as a link between each image and corresponding mask or is it just to iterate through images.
Thanks,
-
I'm having similiar issues here - 1.3.2. I'm trying to apply masks with identical filenames, just located in a folder called "mask".
maskPath = "C:\Temp\IMAGES\1Agisoft\mask\{filename}.jpg"
chunk.importMasks(path = maskPath, source=PhotoScan.MaskSourceBackground, operation=PhotoScan.MaskOperationDifference, tolerance=20)
It works in the gui with template "{filename}.jpg" after I pick the right /mask folder. Thoughts?