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

Function _load_eth3d

visualize_benchmark_web.py:1253–1342  ·  view source on GitHub ↗

Load ETH3D multi-view stereo data. 深度为 float32 二进制文件 (单位: 米, 无效值: inf),pose 为 COLMAP w2c 需转 c2w。 每帧可能有不同 camera_id,使用第一帧的内参作为共享 K (可视化用途)。

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

Source from the content-addressed store, hash-verified

1251
1252
1253def _load_eth3d(scene_dir: Path, frame_indices: list, z_far: float):
1254 """Load ETH3D multi-view stereo data.
1255
1256 深度为 float32 二进制文件 (单位: 米, 无效值: inf),pose 为 COLMAP w2c 需转 c2w。
1257 每帧可能有不同 camera_id,使用第一帧的内参作为共享 K (可视化用途)。
1258 """
1259 import re
1260
1261 def _quat_to_R(qw, qx, qy, qz):
1262 q = np.array([qw, qx, qy, qz], dtype=np.float64)
1263 q /= np.linalg.norm(q)
1264 qw, qx, qy, qz = q
1265 return np.array([
1266 [1-2*(qy*qy+qz*qz), 2*(qx*qy-qz*qw), 2*(qx*qz+qy*qw)],
1267 [2*(qx*qy+qz*qw), 1-2*(qx*qx+qz*qz), 2*(qy*qz-qx*qw)],
1268 [2*(qx*qz-qy*qw), 2*(qy*qz+qx*qw), 1-2*(qx*qx+qy*qy)]
1269 ], dtype=np.float64)
1270
1271 def _dsc_num(name):
1272 m = re.search(r'DSC_(\d+)', name)
1273 return int(m.group(1)) if m else 0
1274
1275 # Parse cameras.txt
1276 K_dict = {}
1277 with open(scene_dir / "dslr_calibration_jpg" / "cameras.txt") as f:
1278 for line in f:
1279 line = line.strip()
1280 if not line or line.startswith('#'):
1281 continue
1282 parts = line.split()
1283 cam_id = int(parts[0])
1284 fx, fy, cx, cy = map(float, parts[4:8])
1285 K_dict[cam_id] = np.array([[fx,0,cx],[0,fy,cy],[0,0,1]], dtype=np.float32)
1286
1287 # Parse images.txt -> sorted frames
1288 frames = []
1289 with open(scene_dir / "dslr_calibration_jpg" / "images.txt") as f:
1290 lines = [l.strip() for l in f if l.strip() and not l.strip().startswith('#')]
1291 for i in range(0, len(lines), 2):
1292 parts = lines[i].split()
1293 qw, qx, qy, qz = map(float, parts[1:5])
1294 tx, ty, tz = map(float, parts[5:8])
1295 cam_id = int(parts[8])
1296 name = parts[9]
1297 R = _quat_to_R(qw, qx, qy, qz)
1298 T_cw = np.eye(4, dtype=np.float64)
1299 T_cw[:3,:3] = R; T_cw[:3,3] = [tx, ty, tz]
1300 T_wc = np.linalg.inv(T_cw)
1301 c2w = T_wc[:3,:].astype(np.float32)
1302 K = K_dict.get(cam_id, np.eye(3, dtype=np.float32))
1303 frames.append((name, c2w, K))
1304 frames.sort(key=lambda x: _dsc_num(x[0]))
1305
1306 # 使用第一帧内参作为共享 K (可视化用)
1307 K = frames[0][2] if frames else np.eye(3, dtype=np.float32)
1308
1309 rgb_dir = scene_dir / "images" / "dslr_images"
1310 depth_dir = scene_dir / "ground_truth_depth" / "dslr_images"

Callers

nothing calls this directly

Calls 3

_quat_to_RFunction · 0.85
_dsc_numFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected