Forum

Author Topic: Can not export depth maps  (Read 6484 times)

tinco

  • Newbie
  • *
  • Posts: 8
    • View Profile
Can not export depth maps
« on: May 16, 2019, 04:50:07 PM »
Hi,

I found this snippet on this forum to export depth maps as .exr files:

Code: [Select]
Traceback (most recent call last):
  File "./process_dataset.py", line 107, in <module>
    run_new_project(doc)
  File "./process_dataset.py", line 89, in run_new_project
    if camera in chunk.depth_maps.keys():

And I inserted into my experimentation script like so:

Code: [Select]
def run_new_project(doc):
  photo_files = glob.glob(source_dir + "/*.JPG")
  chunk = doc.addChunk()
  chunk.addPhotos(photo_files)
  chunk.matchPhotos(progress=progress("matchPhotos"), accuracy=Metashape.HighestAccuracy, generic_preselection=True, reference_preselection=False)
  chunk.alignCameras(progress=progress("alignCameras"))
  chunk.optimizeCameras(progress=progress("optimizeCameras"))
  chunk.buildDepthMaps(quality=Metashape.HighQuality, max_neighbors=50, progress=progress("buildDepthMaps"))
  chunk.buildTiledModel(source=Metashape.DepthMapsData, reuse_depth=True, face_count=16000, progress=progress("buildTiledModel")) #, tile_size=1024)
  chunk.exportTiledModel(target_dir + '/scene.zip', Metashape.TiledModelFormatCesium, progress=progress("exportTiledModel"))

  for camera in chunk.cameras:
    if camera in chunk.depth_maps.keys():
        depth = chunk.depth_maps[camera].image()
        depth.save(target_dir + '/' + camera.label + ".exr")
  doc.save()

Metashape.app.gpu_mask = 2 ** (len(Metashape.app.enumGPUDevices())) - 1
doc = Metashape.app.document

doc_path = target_dir + "/project.psx"
exists = os.path.isfile(doc_path)

doc.save(doc_path)
run_new_project(doc)

The exporting of the model works fine, but the exporting of the depth maps fails with this error:

Code: [Select]
Traceback (most recent call last):
  File "./process_dataset.py", line 107, in <module>
    run_new_project(doc)
  File "./process_dataset.py", line 89, in run_new_project
    if camera in chunk.depth_maps.keys():
Exception: Null depth maps

Has it not calculated the depth maps? Is it using the depth maps generated in the depth maps step for building the tiled model?

Thanks :)

Tinco

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15177
    • View Profile
Re: Can not export depth maps
« Reply #1 on: May 16, 2019, 06:33:20 PM »
Hello Tinco,

If you open the project, are you able to see the Depth Maps in the chunk contents?

Also specify the version that you are using? I think in the latest Metashape Pro release version you need to use keep_depth=True argument in buildTiledModel() and remove reuse_depth argument.
Best regards,
Alexey Pasumansky,
Agisoft LLC

tinco

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Can not export depth maps
« Reply #2 on: May 17, 2019, 03:45:02 PM »
Thanks Alexey!

I am running 1.5.2. I'll start a job now with keep_depth instead of reuse_depth. Note that I think that means the Python documentation is out of date then, because it still says reuse_depth in the docs for buildTiledModel.

I think it has not saved the depth_maps at all with the reuse_depth setting, if I open the project this is my output:

Code: [Select]
>>> doc.open(doc_path,ignore_lock=True)
LoadProject: path = project.psx
loaded project in 1.49855 sec
>>> doc.chunks
[<Chunk 'Chunk 1'>]
>>> doc.chunks[0]
<Chunk 'Chunk 1'>
>>> doc.chunks[0].depth_maps
{}

I'll try moving the saving depth part to right after the depth map generation as well. Could it be the buildTiledModel step throws them away?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15177
    • View Profile
Re: Can not export depth maps
« Reply #3 on: May 17, 2019, 03:55:29 PM »
Hello Tinco,

Maybe I was wrong and those changes have been implemented to API already after 1.5.2 release.
Best regards,
Alexey Pasumansky,
Agisoft LLC

tinco

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Can not export depth maps
« Reply #4 on: May 17, 2019, 06:41:11 PM »
Does it throw away the depth maps after buildTiledModel?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15177
    • View Profile
Re: Can not export depth maps
« Reply #5 on: May 17, 2019, 07:17:22 PM »
Hello Tinco,

Looks like in 1.5.2 (7838) the buildTiledModel task is not actually re-using the available depth and is rebuilding the depth maps set with the default quality.

But if you are running the tiled model reconstruction via Tasks class, the depth is kept:
Code: [Select]
task = Metashape.Tasks.BuildTiledModel()
task.source=  Metashape.DataSource.DepthMapsData
tasks.store_depth = True
tasks.apply(chunk)
While running via "chunk.buildTiledModel()" would discard the depth maps after reconstruction.
« Last Edit: May 17, 2019, 07:30:23 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

tinco

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Can not export depth maps
« Reply #6 on: May 17, 2019, 07:59:30 PM »
Ah thanks Alexey, that explains a lot. So at the moment we're calculating the depth maps twice, and it's not even using the high quality depth maps for constructing the final model.

Is there a way we can get a tiled model based on high quality depth maps? It is important for our use case that they be as accurate as possible. Would it be better for example to make the dense point cloud based on the depth maps and then make the tiled model based on that?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15177
    • View Profile
Re: Can not export depth maps
« Reply #7 on: May 17, 2019, 09:21:13 PM »
Hello Tinco,

I can send you pre-release of the version 1.5.3, when it would be stable enough, where the issue is fixed.
Best regards,
Alexey Pasumansky,
Agisoft LLC

tinco

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Can not export depth maps
« Reply #8 on: May 18, 2019, 03:48:06 PM »
Thanks that would be appreciated :) Though it would also be fine if there is a different route to building the high quality tiled model. Maybe I could just build a model, and then run the Cesium model tiler on that? https://cesium.com/docs/on-premise/tilers/models/

edit: oh nvm, I need an on-premise cesium license for that..
« Last Edit: May 18, 2019, 03:50:08 PM by tinco »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15177
    • View Profile
Re: Can not export depth maps
« Reply #9 on: May 20, 2019, 10:49:41 AM »
Hello Tinco,

You can build the mesh model from the depth maps (as a solid model) and then generate the tiled model using Mesh as a source (instead of depth maps).
Best regards,
Alexey Pasumansky,
Agisoft LLC

tinco

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Can not export depth maps
« Reply #10 on: May 21, 2019, 09:42:24 PM »
The buildModel step is crashing with RuntimeError: Index overflow, but if I google that it looks like it's a problem with dense cloud points, but I'm not using dense cloud..

Code: [Select]
2019-05-21 12:44:49.085103 :  buildModel 2.5
Traceback (most recent call last):
  File "./process_dataset.py", line 155, in <module>
    run_existing_project(doc)
  File "./process_dataset.py", line 50, in run_existing_project
    chunk.buildModel(source=Metashape.DepthMapsData, keep_depth=True, face_count=Metashape.HighFaceCount, progress=progress("buildModel"))
RuntimeError: Index overflow