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

Function _load_vkitti

visualize_benchmark_web.py:975–1032  ·  view source on GitHub ↗

Load Virtual KITTI 2 scene data. Layout (scene_dir = {data_root}/{scene}/{sub_scene}/Camera_0): {XXXXX}_rgb.jpg — RGB 1242×375 {XXXXX}_depth.png — uint16, /100 -> meters, sky=65535 {XXXXX}_cam.npz — camera_pose (4×4 w2c), camera_intrinsics (3×3) depth_mask/*

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

Source from the content-addressed store, hash-verified

973
974
975def _load_vkitti(scene_dir: Path, frame_indices: list, z_far: float, use_depth_mask: bool = True):
976 """Load Virtual KITTI 2 scene data.
977
978 Layout (scene_dir = {data_root}/{scene}/{sub_scene}/Camera_0):
979 {XXXXX}_rgb.jpg — RGB 1242×375
980 {XXXXX}_depth.png — uint16, /100 -> meters, sky=65535
981 {XXXXX}_cam.npz — camera_pose (4×4 w2c), camera_intrinsics (3×3)
982 depth_mask/*.png — binary mask (optional)
983 """
984 rgb_paths = sorted(scene_dir.glob("*_rgb.jpg"))
985 depth_paths = sorted(scene_dir.glob("*_depth.png"))
986 cam_paths = sorted(scene_dir.glob("*_cam.npz"))
987 depth_mask_dir = scene_dir / "depth_mask"
988 depth_mask_paths = sorted(depth_mask_dir.glob("*.png")) if depth_mask_dir.is_dir() else []
989
990 # 从第一帧加载内参 (共享)
991 cam0 = np.load(str(cam_paths[0]))
992 K = cam0['camera_intrinsics'].astype(np.float32)
993
994 images, depths, extrinsics = [], [], []
995 for idx in frame_indices:
996 if idx >= len(rgb_paths) or idx >= len(depth_paths) or idx >= len(cam_paths):
997 continue
998
999 # RGB
1000 img = cv2.imread(str(rgb_paths[idx]))
1001 if img is not None:
1002 img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
1003 else:
1004 img = np.zeros((375, 1242, 3), dtype=np.uint8)
1005
1006 # Depth: uint16 / 100.0 -> meters
1007 d_raw = cv2.imread(str(depth_paths[idx]), cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH)
1008 if d_raw is not None:
1009 depth = d_raw.astype(np.float32) / 100.0
1010 depth[~np.isfinite(depth)] = 0
1011 # 飞点过滤
1012 if use_depth_mask and depth_mask_paths and idx < len(depth_mask_paths):
1013 mask = cv2.imread(str(depth_mask_paths[idx]), cv2.IMREAD_UNCHANGED)
1014 if mask is not None:
1015 depth[mask == 0] = 0
1016 depth[depth >= 655.0] = 0
1017 depth[depth > z_far] = 0
1018 else:
1019 depth = np.zeros((375, 1242), dtype=np.float32)
1020
1021 # Pose: camera_pose 已是 c2w (4×4), 直接取 (3×4)
1022 cam_data = np.load(str(cam_paths[idx]))
1023 pose = cam_data['camera_pose'].astype(np.float32)[:3, :]
1024
1025 images.append(img)
1026 depths.append(depth)
1027 extrinsics.append(pose)
1028
1029 return {
1030 "images": images, "depths": depths,
1031 "extrinsics": extrinsics, "K": K,
1032 }

Callers

nothing calls this directly

Calls 1

loadMethod · 0.80

Tested by

no test coverage detected