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

Function _load_waymo

visualize_benchmark_web.py:1125–1189  ·  view source on GitHub ↗

Load Waymo Open Dataset scene data. Layout (scene_dir = {data_root}/{scene_name}): {XXXXX}_1.jpg — RGB 512×341 {XXXXX}_1.exr — float32 depth (meters, LiDAR) {XXXXX}_1.npz — cam2world (4×4), intrinsics (3×3) depth_mask/*.png — binary mask (optional) sky_ma

(scene_dir: Path, frame_indices: list, z_far: float, use_depth_mask: bool = True)

Source from the content-addressed store, hash-verified

1123
1124
1125def _load_waymo(scene_dir: Path, frame_indices: list, z_far: float, use_depth_mask: bool = True):
1126 """Load Waymo Open Dataset scene data.
1127
1128 Layout (scene_dir = {data_root}/{scene_name}):
1129 {XXXXX}_1.jpg — RGB 512×341
1130 {XXXXX}_1.exr — float32 depth (meters, LiDAR)
1131 {XXXXX}_1.npz — cam2world (4×4), intrinsics (3×3)
1132 depth_mask/*.png — binary mask (optional)
1133 sky_mask/*.png — binary sky mask (optional)
1134 """
1135 rgb_paths = sorted(scene_dir.glob("*.jpg"))
1136 depth_paths = sorted(scene_dir.glob("*.exr"))
1137 anno_paths = sorted(scene_dir.glob("*.npz"))
1138 depth_mask_dir = scene_dir / "depth_mask"
1139 depth_mask_paths = sorted(depth_mask_dir.glob("*.png")) if depth_mask_dir.is_dir() else []
1140 sky_mask_dir = scene_dir / "sky_mask"
1141 sky_mask_paths = sorted(sky_mask_dir.glob("*.png")) if sky_mask_dir.is_dir() else []
1142
1143 # 从第一帧加载内参 (共享)
1144 anno0 = np.load(str(anno_paths[0]))
1145 K = anno0['intrinsics'].astype(np.float32)
1146
1147 images, depths, extrinsics = [], [], []
1148 for idx in frame_indices:
1149 if idx >= len(rgb_paths) or idx >= len(depth_paths) or idx >= len(anno_paths):
1150 continue
1151
1152 # RGB
1153 img = cv2.imread(str(rgb_paths[idx]))
1154 if img is not None:
1155 img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
1156 else:
1157 img = np.zeros((341, 512, 3), dtype=np.uint8)
1158
1159 # Depth: float32 EXR, 已为米制 (IMREAD_ANYDEPTH 保留原始 float32)
1160 d = cv2.imread(str(depth_paths[idx]), cv2.IMREAD_ANYDEPTH)
1161 if d is not None:
1162 depth = d.astype(np.float32)
1163 depth[~np.isfinite(depth)] = 0
1164 # 飞点过滤
1165 if use_depth_mask and depth_mask_paths and idx < len(depth_mask_paths):
1166 mask = cv2.imread(str(depth_mask_paths[idx]), cv2.IMREAD_UNCHANGED)
1167 if mask is not None:
1168 depth[mask == 0] = 0
1169 # Sky mask
1170 if use_depth_mask and sky_mask_paths and idx < len(sky_mask_paths):
1171 sky = cv2.imread(str(sky_mask_paths[idx]), cv2.IMREAD_UNCHANGED)
1172 if sky is not None:
1173 depth[sky > 0] = 0
1174 depth[depth > z_far] = 0
1175 else:
1176 depth = np.zeros((341, 512), dtype=np.float32)
1177
1178 # Pose: cam2world (4×4), 取 (3×4)
1179 anno = np.load(str(anno_paths[idx]))
1180 pose = anno['cam2world'].astype(np.float32)[:3, :]
1181
1182 images.append(img)

Callers

nothing calls this directly

Calls 1

loadMethod · 0.80

Tested by

no test coverage detected