Forum

Author Topic: Rendering model from camera viewpoints to get z-buffer/ depth map  (Read 1914 times)

elliebowler

  • Newbie
  • *
  • Posts: 8
    • View Profile
Hi

I was wondering if anyone could help - I'm a bit confused about different methods for exporting the depth maps. I need to get the depth value of the model rendered from the perspective of each camera in the dataset (i.e z in "real distance" rather than as a 0-255 greyscale image). I have tried directly exporting the depth maps as .exr files with this code (for example for the first camera)

Code: [Select]
chunk = Metashape.app.document.chunk
camera = chunk.cameras[0]
depth = chunk.depth_maps[camera].image()
depth.save(camera.label + ".exr")

However when i open this is in python the resulting array is not the same dimension as the image from the camera (it's (1500, 2000) rather than (3000, 4000)), so i'm not exactly sure what these depth maps show?

I have also tried using the renderDepth function as so
Code: [Select]
depth = chunk.model.renderDepth(camera.transform, camera.sensor.calibration)from the 3D model, and also
Code: [Select]
depth = chunk.dense_cloud.renderDepth(camera.transform, camera.sensor.calibration)from the dense cloud (which would be preferable as this means i don't have to generate the mesh)

When i do depth.save(camera.label + '.tif') though it seems like the images are blank, and i'm not able to open them in Python.

Just wondering if anyone could help with clarifying what i need to get the real-world depth values for every camera? Ideally straight from the existing depth maps or dense cloud, to avoid extra processing making the mesh. Sorry i think there are several posts already answering this but i wasn't able to understand finally which method i needed!

Thanks in advance!

 

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14890
    • View Profile
Re: Rendering model from camera viewpoints to get z-buffer/ depth map
« Reply #1 on: February 15, 2021, 10:16:35 PM »
Hello elliebowler,

If you need to save the depth maps that are stored in the project (in chunk contents of the Workspace pane), you can use the attached script.
Best regards,
Alexey Pasumansky,
Agisoft LLC

elliebowler

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Rendering model from camera viewpoints to get z-buffer/ depth map
« Reply #2 on: February 17, 2021, 12:57:21 AM »
Thanks very much for your help Alexey, this works perfectly for exporting the depth maps stored in the project.

I was wondering if you could explain what the difference is between the project depth maps and the images you get from using the dense_cloud.renderDepth() or model.renderDepth() functions. I can see visually that they are different results (attached screen shot), and the depth maps have half the dimensions - (1500, 2000) compared to (3000, 4000). I am trying to use the depth values to get the z-values in order to project detections from the 2d camera images onto the 3d model, and i'm not sure which maps i need to use for this.

Sorry if this is a very obvious question i'm very new to working with these kinds of datasets.
Thanks for your help already


Paulo

  • Hero Member
  • *****
  • Posts: 1339
    • View Profile
Re: Rendering model from camera viewpoints to get z-buffer/ depth map
« Reply #3 on: February 17, 2021, 02:19:20 AM »
Hi Elliebowler,

the depth maps are downscaled according to the quality used in their generation as follows:

Depth Maps Quality   Downscale
"Ultra"                                     1
"High"                                      2
"Medium"                              4
"Low"                                       8
"Lowest"                              16

So in your case, you probably generated depth maps with high quality, thus downscale of 2 in image size (from 4000x3000 to 2000x1500). To gnerate a 1 to 1 depth you would need to use Utra High quality....
« Last Edit: February 18, 2021, 07:43:41 AM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

elliebowler

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Rendering model from camera viewpoints to get z-buffer/ depth map
« Reply #4 on: February 17, 2021, 02:10:15 PM »
Ah I see - thanks so much for your explanation!