MCPcopy Create free account
hub / github.com/Robbyant/lingbot-depth / load_depth_map

Function load_depth_map

example.py:57–84  ·  view source on GitHub ↗

Load depth map from PNG file (16-bit) and convert to meters. Args: depth_path (str): Path to depth image scale (float): Scale factor to convert to meters - 1000.0 for millimeters - 1.0 for meters Returns: np.ndarray: Depth map in meters

(depth_path, scale=1000.0)

Source from the content-addressed store, hash-verified

55
56
57def load_depth_map(depth_path, scale=1000.0):
58 """
59 Load depth map from PNG file (16-bit) and convert to meters.
60
61 Args:
62 depth_path (str): Path to depth image
63 scale (float): Scale factor to convert to meters
64 - 1000.0 for millimeters
65 - 1.0 for meters
66
67 Returns:
68 np.ndarray: Depth map in meters (H, W), float32
69 """
70 if not Path(depth_path).exists():
71 raise FileNotFoundError(f"Depth map not found: {depth_path}")
72
73 # Read depth map as 16-bit
74 depth_map = cv2.imread(depth_path, cv2.IMREAD_UNCHANGED)
75 if depth_map is None:
76 raise ValueError(f"Failed to read depth map: {depth_path}")
77
78 # Convert to meters
79 depth_map = depth_map.astype(np.float32) / scale
80
81 # Replace invalid values with 0
82 depth_map = np.nan_to_num(depth_map, nan=0.0, posinf=0.0, neginf=0.0)
83
84 return depth_map
85
86def load_intrinsics(intrinsics_path, width, height):
87 """

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected