import os import shutil from pathlib import Path import subprocess # 给定场景路径 scene_path = Path("/data/SamVGGT/datasets/processed_scannet_eval/scene0707_00") scene_id = scene_path.name # 创建目标目录 gt_seg_dir = scene_path / "gt_seg" gt_pose_dir = scene_path / "gt_cam" gt_depth_dir = scene_path / "gt_depth" gt_seg_dir.mkdir(exist_ok=True) gt_pose_dir.mkdir(exist_ok=True) gt_depth_dir.mkdir(exist_ok=True) # 遍历 images 文件夹下的所有 jpg 图片 image_dir = scene_path / "images" image_files = [f for f in image_dir.iterdir() if f.suffix == ".jpg"] target_image_files = [f"{int(f.stem)}.png" for f in image_files] script_path = 'datasets/processed_scannet/convert_scannet_label_image.py' input_dir = f'datasets/processed_scannet/scans_test/{scene_id}/label-filt' output_dir = f'datasets/processed_scannet_eval//{scene_id}/gt_seg' label_map_file = '/data/SamVGGT/datasets/processed_scannet/scannetv2-labels.combined.tsv' # 确保输出目录存在 os.makedirs(output_dir, exist_ok=True) cmd = [ 'python', script_path, '--input_file', input_dir, '--label_map_file', label_map_file, '--output_file', output_dir, '--target_images' ] + target_image_files print(f'Running: {" ".join(cmd)}') subprocess.run(cmd, check=True) for img_path in image_files: prefix = img_path.stem # 例如 frame_000000 # 原始语义路径 semantic_base = Path("/data/SamVGGT/datasets/processed_scannet/scans_test") / scene_id / "label-filt" lable_file = semantic_base / f"{int(prefix)}.png" # 深度图路径 depth_file = Path("/data/SamVGGT/datasets/processed_scannet/scans_test") / scene_id / "depth" / f"{prefix}.png" if depth_file.exists(): shutil.copy2(str(depth_file), gt_depth_dir / depth_file.name) else: print(f"[缺失] {depth_file}") # pose路径 pose_file = Path("/data/SamVGGT/datasets/processed_scannet/scans_test") / scene_id / "cam" / f"{prefix}.npz" if pose_file.exists(): shutil.copy2(str(pose_file), gt_pose_dir / pose_file.name) else: print(f"[缺失] {pose_file}") print(f"Completed scene_id: {scene_id}")