Forum

Author Topic: Unable to read exr depth data  (Read 3987 times)

vkam

  • Newbie
  • *
  • Posts: 28
    • View Profile
Unable to read exr depth data
« on: September 27, 2022, 11:18:20 PM »
Hello,

I am evaluating Metashape for its depth map generation capability.  I have the 30 day license, version 1.8.4

I tried reading the depth map exr data in <xyz>.files/0/0/depth_maps/data0/0.
I am using OpenCV version 4.5.5.

The imread command (with flags IMREAD_ANYCOLOR | IMREAD_ANYDEPTH | IMREAD_UNCHANGED) returns, but data is all zeros.

Please can someone help me get past this bump?  Would much appreciate it.

Thanks!

vkam

PolarNick

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: Unable to read exr depth data
« Reply #1 on: September 28, 2022, 01:16:40 PM »
Hi,

have you ensured that your OpenCV installation properly works with OpenEXR format? For example you can try to create floating-point image full of 1.5 values, save it to .exr file, read it back and check that all values are still 1.5

If you will find that OpenEXR doesn't work properly - maybe it is disabled (see this) and can be enabled with env. variable OPENCV_IO_ENABLE_OPENEXR=1

vkam

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Unable to read exr depth data
« Reply #2 on: September 28, 2022, 08:59:22 PM »
Hi PloarNick,

Yes I have that flag enbled.  Without that flag, OpenCV imread errors out with a message warning about that flag.

Thanks for alerting though - appreciate it.

Vkam

PolarNick

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: Unable to read exr depth data
« Reply #3 on: September 29, 2022, 09:51:02 PM »
I tried to open a depth map reconstructed in Metashape with OpenCV (4.6.0) and also got only zeros :(

I ensured that OpenCV was build with EXR support (this line is from OpenCV configure output - when you run cmake before building OpenCV):

Code: [Select]
OpenEXR:                     build (ver 2.3.0)
I will try later to re-build OpenCV with more fresh version of OpenEXR, maybe it will help.

PolarNick

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: Unable to read exr depth data
« Reply #4 on: September 30, 2022, 03:48:38 PM »
For me it seems like a bug in OpenCV, because the same exr file can be sucessfully opened in openexr-viewer, so I created a report

vkam

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Unable to read exr depth data
« Reply #5 on: October 11, 2022, 01:50:08 AM »
Hi PolarNick,

Thanks for filing the bug - indeed it looks like an OpenCV issue.  I was able to read the data from a simple OpenEXR app and memcpy the buffer to an OpenCV Mat.  The saved image can now be read by OpenCV.  Looking at the headers between the two exr files, the difference is in compression format and tiled (openexr) versus scanline (opencv) storage of data.

Cheers,

Vkam