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

Function _load_omniworld

visualize_benchmark_web.py:739–855  ·  view source on GitHub ↗

Load OmniWorld-Game data (metric depth, metric poses). scene_dir 实际上是 data_root/scene_id,scene_path = "scene_id/split_N"。 深度和位姿均乘以 metric_scale 转为米制。

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

Source from the content-addressed store, hash-verified

737
738
739def _load_omniworld(scene_dir: Path, scene_path: str, frame_indices: list, z_far: float, use_depth_mask: bool = True):
740 """Load OmniWorld-Game data (metric depth, metric poses).
741
742 scene_dir 实际上是 data_root/scene_id,scene_path = "scene_id/split_N"。
743 深度和位姿均乘以 metric_scale 转为米制。
744 """
745 import csv as _csv
746 import json as _json
747 from scipy.spatial.transform import Rotation as _R
748
749 parts = scene_path.split('/')
750 scene_id = parts[0]
751 split_idx = int(parts[1].replace('split_', ''))
752
753 # 加载 metric_scale
754 csv_path = scene_dir.parent / "omniworld_game_metadata.csv"
755 metric_scale = 1.0
756 if csv_path.exists():
757 with open(str(csv_path), 'r', encoding='utf-8', newline='') as f:
758 reader = _csv.DictReader(f)
759 for row in reader:
760 if row["UID"] == scene_id:
761 metric_scale = float(row["Metric Scale"])
762 break
763
764 # scene_dir 已经是 data_root / scene_id
765 with open(str(scene_dir / "split_info.json"), 'r') as f:
766 split_info = _json.load(f)
767 global_indices = split_info["split"][split_idx]
768
769 # 加载相机参数
770 cam_file = scene_dir / "camera" / f"split_{split_idx}.json"
771 with open(str(cam_file), 'r') as f:
772 cam = _json.load(f)
773
774 # 内参 (取均值 focal)
775 focal_mean = float(np.mean(cam["focals"]))
776 K = np.array([
777 [focal_mean, 0, cam["cx"]],
778 [0, focal_mean, cam["cy"]],
779 [0, 0, 1],
780 ], dtype=np.float32)
781
782 # 外参 w2c -> c2w, c2w 平移 × metric_scale
783 quat_wxyz = np.array(cam["quats"], dtype=np.float64)
784 trans = np.array(cam["trans"], dtype=np.float64)
785 norms = np.linalg.norm(quat_wxyz, axis=1, keepdims=True)
786 norms = np.maximum(norms, 1e-8)
787 quat_wxyz = quat_wxyz / norms
788 quat_xyzw = np.concatenate([quat_wxyz[:, 1:], quat_wxyz[:, :1]], axis=1)
789 rotations = _R.from_quat(quat_xyzw).as_matrix()
790
791 S = len(cam["quats"])
792 w2c = np.repeat(np.eye(4, dtype=np.float64)[None], S, axis=0)
793 w2c[:, :3, :3] = rotations
794 w2c[:, :3, 3] = trans
795 c2w = np.linalg.inv(w2c)
796 c2w[:, :3, 3] *= metric_scale

Callers

nothing calls this directly

Calls 1

loadMethod · 0.80

Tested by

no test coverage detected