Reading .exr Files In Opencv
I have generated some depth maps using blender and have saved z-buffer values(32 bits) in OpenEXR format. Is there any way to access values from a .exr file (pixel by pixel depth i
Solution 1:
I might be a little late to the party but; Yes you can definitely use OpenCV for that.
cv2.imread(PATH_TO_EXR_FILE, cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH)
should get you what you need
Solution 2:
You can use OpenEXR package
pip --no-cache-dir install OpenEXR
If the above fails, install the OpenEXR dev library and then install the python package as above
sudo apt-get install libopenexr-dev
To read exr file
def read_depth_exr_file(filepath: Path):
exrfile = exr.InputFile(filepath.as_posix())
raw_bytes = exrfile.channel('B', Imath.PixelType(Imath.PixelType.FLOAT))
depth_vector = numpy.frombuffer(raw_bytes, dtype=numpy.float32)
height = exrfile.header()['displayWindow'].max.y + 1 - exrfile.header()['displayWindow'].min.y
width = exrfile.header()['displayWindow'].max.x + 1 - exrfile.header()['displayWindow'].min.x
depth_map = numpy.reshape(depth_vector, (height, width))
return depth_map
Post a Comment for "Reading .exr Files In Opencv"