MCPcopy Create free account
hub / github.com/cdcseacave/openMVS / load_depth_exr

Function load_depth_exr

scripts/python/ImportDMAPs.py:38–63  ·  view source on GitHub ↗

Load depth data from an EXR file. Note: This will use the first channel in the EXR file. Args: exr_path (str): Path to the EXR file. Returns: numpy.ndarray: Depth data as a NumPy array.

(exr_path)

Source from the content-addressed store, hash-verified

36
37
38def load_depth_exr(exr_path):
39 """
40 Load depth data from an EXR file.
41 Note: This will use the first channel in the EXR file.
42 Args:
43 exr_path (str): Path to the EXR file.
44 Returns:
45 numpy.ndarray: Depth data as a NumPy array.
46 """
47 import Imath
48 import OpenEXR
49
50 try:
51 exr_file = OpenEXR.InputFile(exr_path)
52 header = exr_file.header()
53 channels = header['channels'].keys()
54 dw = header["dataWindow"]
55 size = (dw.max.x - dw.min.x + 1, dw.max.y - dw.min.y + 1)
56 pt = Imath.PixelType(Imath.PixelType.FLOAT)
57 depth_str = exr_file.channel(list(channels)[0], pt)
58 depth_map = np.frombuffer(depth_str, dtype=np.float32).reshape((size[1], size[0]))
59 depth_map = np.nan_to_num(depth_map, nan=0.0, posinf=0.0, neginf=0.0)
60 return depth_map
61 except Exception as e:
62 print(f"Error loading EXR file {exr_path}: {e}")
63 return None
64
65
66def scale_depth_map(scene, image_idx, depth_map, verbose=False):

Callers 1

import_dmapsFunction · 0.85

Calls 1

printFunction · 0.85

Tested by

no test coverage detected