Forum

Author Topic: DepthMap setImage not working  (Read 1919 times)

FabianN

  • Newbie
  • *
  • Posts: 15
    • View Profile
DepthMap setImage not working
« on: April 11, 2022, 11:33:06 AM »
Hello everyone,

I try to moddify depth maps for all cameras in the chunk. My principle workflow for a given 'camera' is:

Code: [Select]
ddata = numpy array of depth values in local CS as float32
DM = Metashape.Image.fromstring(ddata.tostring(), ddata.shape[1], ddata.shape[0], ' ', 'F32')
chunk.depth_maps[camera].setImage(DM)

There is no error when running the lines above but if I reload the depth map, the original depth map is still present.

Any ideas?
Thank you!

PolarNick

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: DepthMap setImage not working
« Reply #1 on: April 13, 2022, 06:05:12 PM »
Hi, removing depth map and then setting it worked for me:

Code: [Select]
ddata = numpy array of depth values in local CS as float32
DM = Metashape.Image.fromstring(ddata.tostring(), ddata.shape[1], ddata.shape[0], ' ', 'F32')
depth_map = chunk.depth_maps[camera]
depth_map.setImage(DM)
del chunk.depth_maps[camera]
chunk.depth_maps[camera] = depth_map

P.S. also please note that setImage has a level argument which is equal to zero by default, but there can be multiple levels (typically three), so maybe it is better to create a fresh one:

Code: [Select]
ddata = numpy array of depth values in local CS as float32
DM = Metashape.Image.fromstring(ddata.tostring(), ddata.shape[1], ddata.shape[0], ' ', 'F32')
depth_map = Metashape.DepthMap()
depth_map.setCalibration(chunk.depth_maps[camera].getCalibration())
depth_map.setImage(DM)
del chunk.depth_maps[camera]
chunk.depth_maps[camera] = depth_map

FabianN

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: DepthMap setImage not working
« Reply #2 on: April 20, 2022, 12:18:15 PM »
Yes this works, thank you!
Do you know why the image data cannot be replaced directly? There is no hint in the API manual why this should not work.

Thanks again and regards

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: DepthMap setImage not working
« Reply #3 on: April 20, 2022, 01:57:51 PM »
Hello Fabian,

It is likely a bug, we are already checking, why the initial solution doesn't work as expected.
Best regards,
Alexey Pasumansky,
Agisoft LLC

FabianN

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: DepthMap setImage not working
« Reply #4 on: April 21, 2022, 11:28:43 PM »
Hi Alexey,

Thank you for looking into the issue.
One other effect: After the depth maps were moddified (and the project saved), the original depth maps still show up when overlaying them in the GUI.

I hope you find and fix the bug.

Thanks for your efforts and best regards!