MCPcopy Create free account
hub / github.com/Ropedia/SpatialBench / _decode_depth

Function _decode_depth

benchmark/datasets/data_readers.py:89–138  ·  view source on GitHub ↗

Decode a depth map per depth_format; returns (depth, sky_mask_or_None).

(path, depth_format, meta)

Source from the content-addressed store, hash-verified

87
88
89def _decode_depth(path, depth_format, meta):
90 """Decode a depth map per depth_format; returns (depth, sky_mask_or_None)."""
91 if depth_format in ('uint16_png_div1000', 'uint16_png_div1000_rectified'):
92 raw = cv2.imread(path, cv2.IMREAD_ANYDEPTH)
93 return raw.astype(np.float32) / 1000.0, None
94
95 if depth_format == 'uint16_png_div100':
96 raw = cv2.imread(path, cv2.IMREAD_ANYDEPTH)
97 depth = raw.astype(np.float32) / 100.0
98 sky_mask = raw >= 65500
99 depth[sky_mask] = 0
100 return depth, sky_mask
101
102 if depth_format == 'uint16_png_div_655.35':
103 raw = cv2.imread(path, cv2.IMREAD_ANYDEPTH)
104 return raw.astype(np.float32) / 655.35, None
105
106 if depth_format == 'uint16_png_inverse_encoded':
107 # OmniWorld: depth = decode(raw/65535) * metric_scale; sky if raw > 65500
108 raw = cv2.imread(path, cv2.IMREAD_ANYDEPTH)
109 metric_scale = float(meta.get('metric_scale', 1.0))
110 depthmap = raw.astype(np.float32) / 65535.0
111 near_mask = depthmap < 0.0015
112 sky_mask = depthmap > (65500.0 / 65535.0)
113 near, far = 1.0, 1000.0
114 depthmap = depthmap / (far - depthmap * (far - near)) / 0.004
115 invalid = near_mask | sky_mask
116 depthmap[invalid] = 0
117 depthmap[~invalid] *= metric_scale
118 return depthmap, sky_mask
119
120 if depth_format == 'npy_float32_meters':
121 return np.load(path).astype(np.float32), None
122
123 if depth_format == 'exr_float32':
124 d = cv2.imread(path, cv2.IMREAD_ANYDEPTH | cv2.IMREAD_UNCHANGED)
125 return d.astype(np.float32), None
126
127 if depth_format.startswith('float32_binary'):
128 m = re.search(r'_(\d+)x(\d+)', depth_format)
129 if not m:
130 raise ValueError(f"Cannot parse size from depth_format: {depth_format}")
131 H, W = int(m.group(1)), int(m.group(2))
132 d = np.fromfile(path, dtype=np.float32).reshape(H, W)
133 return d, None
134
135 if depth_format == 'none':
136 return None, None
137
138 raise ValueError(f"Unknown depth_format: {depth_format}")
139
140
141def _load_pose(path):

Callers 2

read_sceneMethod · 0.85
_read_scene_with_metaMethod · 0.85

Calls 2

loadMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected