Forum

Author Topic: Adding masks  (Read 6238 times)

Troger

  • Newbie
  • *
  • Posts: 2
    • View Profile
Adding masks
« on: August 28, 2015, 12:53:02 AM »
So we have a turntable rig with 5 camera in fixed positions. We shoot background mask shots and name them A-E. Then we shoot the object at 10 degree increments and name the files incrementally from 1-36. So we end up with a folder containing 180 images and a subfolder with 5 masks. I've got a script that I've pieced together from various other posts I've seen in here, but I can't figure out how to apply masks to the correct set of cameras. Currently it applies every mask to every camera as opposed to just applying that "A" mask to the 1-36 "A" shots... and the "B" mask to the 1-36 "B" shots.

Am I over thinking this?

Example file name:
PF_SchoolBlocks2_A-1.jpg
PF_SchoolBlocks2_A-2.jpg
PF_SchoolBlocks2_A-3.jpg
...
PF_SchoolBlocks2_B-1.jpg
PF_SchoolBlocks2_B-2.jpg
PF_SchoolBlocks2_B-3.jpg
...
_masks/PF_SchoolBlocks2_A-MASK.jpg
_masks/PF_SchoolBlocks2_B-MASK.jpg
...

Code: [Select]
global doc
doc = PhotoScan.app.document

app = QtGui.QApplication.instance()
parent = app.activeWindow()

#prompting for path to photos
path_photos = PhotoScan.app.getExistingDirectory("Specify input photo folder:")
path_masks = path_photos + '/_masks/'
#path_export = PhotoScan.app.getExistingDirectory("Specify EXPORT folder:")
path_export = path_photos

#processing parameters
tolerance = 50
accuracy = PhotoScan.Accuracy.HighAccuracy  #align photos accuracy
preselection = PhotoScan.Preselection.NoPreselection
keypoints = 40000 #align photos key point limit
tiepoints = 1000 #align photos tie point limit
source = PhotoScan.PointsSource.DensePoints #build mesh source
surface = PhotoScan.SurfaceType.Arbitrary #build mesh surface type
quality = PhotoScan.Quality.HighQuality #build dense cloud quality
filtering = PhotoScan.FilterMode.AggressiveFiltering #depth filtering
interpolation = PhotoScan.Interpolation.EnabledInterpolation #build mesh interpolation
#face_num = PhotoScan.FaceCount.HighFaceCount #build mesh polygon count
face_num = 200000 #build mesh polygon count
dec_face_num = 120000 #build FPO? polygon count
mapping = PhotoScan.MappingMode.GenericMapping #build texture mapping
atlas_size = 4096
blending = PhotoScan.BlendingMode.MosaicBlending #blending mode
color_corr = False


print("Script started")

#creating new chunk
doc.addChunk()
chunk = doc.chunks[-1]
chunk.label = os.path.basename( path_photos )

#loading images
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
if ("jpg" or "jpeg" or "JPG" or "JPEG") in photo.lower():
photo_list.append(path_photos + "/" + photo)
chunk.addPhotos(photo_list)



backgrounds = os.listdir(path_masks)
for file in backgrounds:
if ("jpg" or "jpeg" or "JPG" or "JPEG") in file.lower():
chunk.importMasks(path = path_masks + file, method='background', tolerance=tolerance)

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Adding masks
« Reply #1 on: August 28, 2015, 09:36:13 AM »
Hello Troger,

the following line should be changed
Code: [Select]
if ("jpg" or "jpeg" or "JPG" or "JPEG") in photo.lower():to
Code: [Select]
if ("jpg" in photo.lower()) or ("jpeg" in photo.lower()):and the same for file.lower()

Let me know if it helps.
Best regards,
Alexey Pasumansky,
Agisoft LLC

stephan

  • Full Member
  • ***
  • Posts: 129
    • View Profile
Re: Adding masks
« Reply #2 on: September 21, 2015, 02:48:47 PM »
Same problem here, I've been trying to use the importMasks command to load a series of images to be used as masks but each image is applied to each image in the chunk and I can't figure out how to match up images as pairs only based on file name.

Is it possible I'm not using the "cameras" attribute correctly?

Code: [Select]
#loading backgrounds
backgrounds_list = os.listdir(path_masks)
for background in backgrounds_list:
if ("jpg" in background.lower()) or ("jpeg" in background.lower()) or ("JPEG" in background.lower()) or ("JPG" in background.lower()):
chunk.importMasks(path = path_masks + "\\" + background, method='background', tolerance=tolerance, cameras=['0'])

print("stop here to check masking")

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Adding masks
« Reply #3 on: September 21, 2015, 04:21:24 PM »
Hello stephan,

for cameras argument you need to pass the list of camera instances to be used for the background masking.
Best regards,
Alexey Pasumansky,
Agisoft LLC

stephan

  • Full Member
  • ***
  • Posts: 129
    • View Profile
Re: Adding masks
« Reply #4 on: September 21, 2015, 05:53:27 PM »
Hi Alexey,

Thanks but that's where I can't figure it out. No matter whether I pass a list or a single entity name to the "cameras" argument I always get all of the "mask" files applied to each camera in the chunk. I'm going to spend some more time on this ans try to figure it out as I think I must be missing something simple...

Cheers!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Adding masks
« Reply #5 on: September 21, 2015, 06:26:59 PM »
Hello stephan,

In your script there's only one loop - for the background images, and the camera list remain the same, so you'll get the final mask applied to the selected cameras as a result of the script.

How camera labels are related to the background file names? Probably, you can implement a short function that finds the camera by the label and then pass the proper camera (according to the background file) to the importMasks() function?
Best regards,
Alexey Pasumansky,
Agisoft LLC

stephan

  • Full Member
  • ***
  • Posts: 129
    • View Profile
Re: Adding masks
« Reply #6 on: September 24, 2015, 01:12:48 AM »
Thanks for your help!
I've been trying to get it to work with the code below and it looks like the conditions are all verified as the "print" function is applied and the listed file names are displayed, but now no masks are applied to any cameras. Is it possible that I'm not passing the list in the right format to "cameras="?

Code: [Select]
for background in backgrounds_list:
if ("jpg" in background.lower()) or ("jpeg" in background.lower()) or ("JPEG" in background.lower()) or ("JPG" in background.lower()):
for file in os.listdir(path_photos):
list1 = list()
list1.append (file)
print (list1[0])
if list1[0] == background.lower():
chunk.importMasks(path = path_masks + "\\" + background, method='background', tolerance=tolerance, cameras=list1)
del list1[0]