Download scripts/fix_colmap_format.py from KCBtheone/SplatAtlas: direct link, hf CLI and curl.
- Browser
- Download file 2.52 kB
-
https://huggingface.co/KCBtheone/SplatAtlas/resolve/main/scripts/fix_colmap_format.py
- Command line
-
hf download hf://KCBtheone/SplatAtlas/scripts/fix_colmap_format.py
-
curl -L -o fix_colmap_format.py https://huggingface.co/KCBtheone/SplatAtlas/resolve/main/scripts/fix_colmap_format.py
2.52 kB
| import sys | |
| import os | |
| # 动态将 taming-3dgs 路径加入,利用其内置的 colmap_loader | |
| sys.path.append("/root/autodl-tmp/taming-3dgs") | |
| try: | |
| from scene.colmap_loader import read_extrinsics_binary, read_intrinsics_binary, qvec2rotmat | |
| from scene.colmap_loader import read_points3D_binary | |
| except ImportError: | |
| print("❌ 找不到 taming-3dgs 路径,请确认目录存在。") | |
| sys.exit(1) | |
| def convert(): | |
| base_path = "/root/autodl-tmp/dataset/synthetic_nerf/Synthetic_NeRF/Lego/sparse/0" | |
| print(f"🔄 正在手动解析二进制并生成文本文件: {base_path}") | |
| # 1. 处理相机的内参 (Intrinsics) | |
| try: | |
| intrinsics = read_intrinsics_binary(os.path.join(base_path, "cameras.bin")) | |
| with open(os.path.join(base_path, "cameras.txt"), "w") as f: | |
| for i in intrinsics: | |
| # 格式: CAMERA_ID MODEL WIDTH HEIGHT PARAMS[] | |
| params = " ".join([str(p) for p in intrinsics[i].params]) | |
| f.write(f"{i} {intrinsics[i].model} {intrinsics[i].width} {intrinsics[i].height} {params}\n") | |
| print(" - cameras.txt 生成成功") | |
| except Exception as e: print(f" - cameras 转换失败: {e}") | |
| # 2. 处理外参和图像 (Extrinsics/Images) | |
| try: | |
| extrinsics = read_extrinsics_binary(os.path.join(base_path, "images.bin")) | |
| with open(os.path.join(base_path, "images.txt"), "w") as f: | |
| for i in extrinsics: | |
| e = extrinsics[i] | |
| q = " ".join([str(x) for x in e.qvec]) | |
| t = " ".join([str(x) for x in e.tvec]) | |
| # 第一行: IMAGE_ID QW QX QY QZ TX TY TZ CAMERA_ID NAME | |
| f.write(f"{i} {q} {t} {e.camera_id} {e.name}\n") | |
| # 第二行: POINTS2D (Blender 数据通常是空的或占位符) | |
| f.write("\n") | |
| print(" - images.txt 生成成功") | |
| except Exception as e: print(f" - images 转换失败: {e}") | |
| # 3. 处理点云 (Points3D) | |
| try: | |
| pts3d = read_points3D_binary(os.path.join(base_path, "points3D.bin")) | |
| with open(os.path.join(base_path, "points3D.txt"), "w") as f: | |
| for i in pts3d: | |
| p = pts3d[i] | |
| xyz = " ".join([str(x) for x in p.xyz]) | |
| rgb = " ".join([str(x) for x in p.rgb]) | |
| f.write(f"{i} {xyz} {rgb} {p.error} 0\n") | |
| print(" - points3D.txt 生成成功") | |
| except Exception as e: print(f" - points3D 转换失败: {e}") | |
| if __name__ == "__main__": | |
| convert() | |