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

Function _load_scannetpp

visualize_benchmark_web.py:1405–1498  ·  view source on GitHub ↗

Load ScanNet++ iPhone subset (indoor real, static). Layout: merge_dslr_iphone/ colmap/sparse_render_rgb/ (COLMAP binary, DSLR + iPhone) images/iphone/frame_XXXXXX.jpg render_depth/frame_XXXXXX.png (uint16, /1000 -> meters) Only iPhone frames a

(scene_dir: Path, frame_indices: list, z_far: float)

Source from the content-addressed store, hash-verified

1403
1404
1405def _load_scannetpp(scene_dir: Path, frame_indices: list, z_far: float):
1406 """Load ScanNet++ iPhone subset (indoor real, static).
1407
1408 Layout:
1409 merge_dslr_iphone/
1410 colmap/sparse_render_rgb/ (COLMAP binary, DSLR + iPhone)
1411 images/iphone/frame_XXXXXX.jpg
1412 render_depth/frame_XXXXXX.png (uint16, /1000 -> meters)
1413
1414 Only iPhone frames are used. RGB is undistorted to rectified space so it
1415 aligns with the rendered depth and rectified intrinsics.
1416 """
1417 import pycolmap
1418
1419 merged = scene_dir / "merge_dslr_iphone"
1420 colmap_path = merged / "colmap" / "sparse_render_rgb"
1421 image_dir = merged / "images"
1422 depth_dir = merged / "render_depth"
1423
1424 rec = pycolmap.Reconstruction(str(colmap_path))
1425
1426 # 收集 iPhone 帧 (按 name 排序与 build_scannetpp_index 保持一致)
1427 frames = []
1428 for im in rec.images.values():
1429 if "iphone" not in im.name:
1430 continue
1431 frames.append((im.name, im, rec.cameras[im.camera_id]))
1432 frames.sort(key=lambda x: x[0])
1433
1434 # 共享 rectified K (首帧相机参数)
1435 first_cam = frames[0][2]
1436 params = np.asarray(first_cam.params, dtype=np.float64)
1437 fx, fy, cx, cy = params[:4]
1438 dist = np.zeros(5, dtype=np.float32)
1439 if first_cam.model_name == "OPENCV" and len(params) >= 8:
1440 dist[:4] = params[4:8]
1441 K_raw = np.array([
1442 [fx, 0, cx - 0.5],
1443 [0, fy, cy - 0.5],
1444 [0, 0, 1.0 ],
1445 ], dtype=np.float32)
1446 W, H = first_cam.width, first_cam.height
1447 K_rect, _ = cv2.getOptimalNewCameraMatrix(K_raw, dist, (W, H), 1, (W, H))
1448 K_rect = np.asarray(K_rect, dtype=np.float32)
1449
1450 images, depths, extrinsics = [], [], []
1451 for idx in frame_indices:
1452 if idx >= len(frames):
1453 continue
1454 name, im, cam = frames[idx]
1455
1456 # Per-frame K (都是 iphone 相机, 一般一致)
1457 p_params = np.asarray(cam.params, dtype=np.float64)
1458 p_dist = np.zeros(5, dtype=np.float32)
1459 if cam.model_name == "OPENCV" and len(p_params) >= 8:
1460 p_dist[:4] = p_params[4:8]
1461 p_K_raw = np.array([
1462 [p_params[0], 0, p_params[2] - 0.5],

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected