Load SpatialVID scene data. Layout: images/000001.jpg ... — RGB images (1-indexed) depth/{ann_idx:06d}.png — inverse depth (uint16) indexes.txt — annotation_idx -> video_frame_idx poses.npy — (N, 7) [tx, ty, tz, qx, qy, qz, qw]
(scene_dir: Path, frame_indices: list, z_far: float, use_depth_mask: bool = True)
| 856 | |
| 857 | |
| 858 | def _load_spatialvid(scene_dir: Path, frame_indices: list, z_far: float, use_depth_mask: bool = True): |
| 859 | """Load SpatialVID scene data. |
| 860 | |
| 861 | Layout: |
| 862 | images/000001.jpg ... — RGB images (1-indexed) |
| 863 | depth/{ann_idx:06d}.png — inverse depth (uint16) |
| 864 | indexes.txt — annotation_idx -> video_frame_idx |
| 865 | poses.npy — (N, 7) [tx, ty, tz, qx, qy, qz, qw] w2c |
| 866 | intrinsics.npy — (N, 4) [fx, fy, cx, cy] normalized |
| 867 | depth_mask/{ann_idx:06d}.png — flying point mask (optional) |
| 868 | sky_mask/{ann_idx:06d}.png — sky mask (optional) |
| 869 | """ |
| 870 | from scipy.spatial.transform import Rotation as R |
| 871 | |
| 872 | # Parse indexes.txt |
| 873 | ann_to_video = {} |
| 874 | idx_path = scene_dir / "indexes.txt" |
| 875 | if idx_path.exists(): |
| 876 | for line in idx_path.read_text().strip().split('\n'): |
| 877 | line = line.strip() |
| 878 | if not line or line.startswith('#'): |
| 879 | continue |
| 880 | parts = line.split() |
| 881 | if len(parts) >= 2: |
| 882 | ann_to_video[int(parts[0])] = int(parts[1]) |
| 883 | |
| 884 | # Load poses (N, 7): w2c -> c2w |
| 885 | all_poses = np.load(str(scene_dir / "poses.npy")).astype(np.float64) |
| 886 | N = len(all_poses) |
| 887 | quat_xyzw = all_poses[:, 3:7] |
| 888 | rotations = R.from_quat(quat_xyzw).as_matrix() |
| 889 | translations = all_poses[:, :3] |
| 890 | |
| 891 | w2c = np.repeat(np.eye(4, dtype=np.float64)[None], N, axis=0) |
| 892 | w2c[:, :3, :3] = rotations |
| 893 | w2c[:, :3, 3] = translations |
| 894 | c2w = np.linalg.inv(w2c) |
| 895 | all_c2w = c2w[:, :3, :].astype(np.float32) |
| 896 | |
| 897 | # Load intrinsics (N, 4): normalized -> pixel |
| 898 | all_intrin = np.load(str(scene_dir / "intrinsics.npy")).astype(np.float32) |
| 899 | |
| 900 | # Get image size from first image |
| 901 | img_dir = scene_dir / "images" |
| 902 | sample_imgs = sorted(img_dir.glob("*.jpg")) |
| 903 | if not sample_imgs: |
| 904 | sample_imgs = sorted(img_dir.glob("*.png")) |
| 905 | first_img = cv2.imread(str(sample_imgs[0])) |
| 906 | img_H, img_W = first_img.shape[:2] |
| 907 | |
| 908 | # Build shared K from first frame |
| 909 | fx_n, fy_n, cx_n, cy_n = all_intrin[0] |
| 910 | K = np.array([ |
| 911 | [fx_n * img_W, 0, cx_n * img_W], |
| 912 | [0, fy_n * img_H, cy_n * img_H], |
| 913 | [0, 0, 1], |
| 914 | ], dtype=np.float32) |
| 915 |