Forum

Author Topic: Adding Depth Maps Without Reprocssing  (Read 2188 times)

KBL

  • Newbie
  • *
  • Posts: 31
    • View Profile
Adding Depth Maps Without Reprocssing
« on: December 10, 2020, 11:04:16 AM »
I'm trying to process depth maps for a subset of the images in my project. The following code identifies the positions of each image without a depth map successfully. However, when I run buildDepthMaps, processing finishes instantly ("Finished processing in 0 sec (exit code 1)") when reuse depth maps is set to false, or alternatively reprocesses from scratch when reuse depth maps is set to true.

Is there a way to reprocess depth maps for only those photos that do not have depth maps, or am I setting a value incorrectly in my script?

Code: [Select]
import Metashape

chunk = Metashape.app.document.chunk

# Get a list of the integer positions of each camera without a depth map

# Get all photo paths
allPhotos = []
for camera in chunk.cameras:
    allPhotos.append(camera.photo.path)

# Get photo paths without depth maps
photosWithDepthMaps = []
for key in chunk.depth_maps.keys():
    photosWithDepthMaps.append(key.photo.path)
 
# Get the integer positions of all photos
# not in the list of photo depth maps
photosWithoutDepthMaps = []
i = -1
for photo in allPhotos:
    i += 1
    if photo in photosWithDepthMaps: continue
    photosWithoutDepthMaps.append(i)

# Process those photos
chunk.buildDepthMaps(
    downscale = 2,
    filter_mode = Metashape.FilterMode.MildFiltering,
    cameras = photosWithoutDepthMaps,
    reuse_depth = False)

Paulo

  • Hero Member
  • *****
  • Posts: 1324
    • View Profile
Re: Adding Depth Maps Without Reprocssing
« Reply #1 on: December 10, 2020, 01:30:24 PM »
Hi KBL,

I think following code should do the trick:
Code: [Select]
photosWithoutDepthMaps = []
for camera in chunk.cameras:
    if camera in chunk.depth_maps.keys():
        continue
    photosWithoutDepthMaps.append(camera.key)
chunk.buildDepthMaps(
    downscale = 2,
    filter_mode = Metashape.FilterMode.MildFiltering,
    cameras = photosWithoutDepthMaps,
    reuse_depth = False)

Unfortunately, this process will create the new depth maps for photosWithoutDepthMaps while eliminating the already existing ones... Maybe Agisoft support can help on this ...
« Last Edit: December 10, 2020, 03:02:16 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

KBL

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Adding Depth Maps Without Reprocssing
« Reply #2 on: December 10, 2020, 10:58:22 PM »
Much appreciated Paulo, unfortunately regenerating all the depth maps is what I'm trying to avoid. In fact, I believe you can entirely ignore the cameras parameter if you don't mind regenerating depth maps for all images. Hopefully Agisoft can lend their advice too!