Skip to content

Instantly share code, notes, and snippets.

@LimHyungTae
Created March 13, 2025 17:14
Show Gist options
  • Save LimHyungTae/8a126e329f4a54c0d6e2c990e165076c to your computer and use it in GitHub Desktop.
Save LimHyungTae/8a126e329f4a54c0d6e2c990e165076c to your computer and use it in GitHub Desktop.
Visualization using Open3D
import open3d as o3d
import os
import time
# PCD 파일이 저장된 폴더 경로
pcd_folder = "./"
# PCD 파일 목록 가져오기
pcd_files = sorted([f for f in os.listdir(pcd_folder) if f.endswith(".pcd")])
# 유효한 인덱스 찾기
valid_indices = sorted(set(f.split("_")[0] for f in pcd_files))
if not valid_indices:
print("No valid PCD files found.")
exit()
print(f"Valid indices found: {valid_indices}")
# 하나씩 시각화
for index_str in valid_indices:
try:
# 파일 불러오기
tgt_pcd = o3d.io.read_point_cloud(os.path.join(pcd_folder, f"{index_str}_tgt.pcd"))
warped_est_pcd = o3d.io.read_point_cloud(os.path.join(pcd_folder, f"{index_str}_warped_est.pcd"))
warped_gt_pcd = o3d.io.read_point_cloud(os.path.join(pcd_folder, f"{index_str}_warped_gt.pcd"))
# 색상 설정
tgt_pcd.paint_uniform_color([0, 1, 0]) # 초록 - 원본 타겟
warped_est_pcd.paint_uniform_color([0, 0, 1]) # 파랑 - 추정된 변환 결과
warped_gt_pcd.paint_uniform_color([1, 1, 0]) # 노랑 - GT 변환 결과
# 시각화
print(f"Showing frame {index_str}. Press 'n' to continue.")
# Open3D 시각화 실행
def callback(vis):
vis.close() # 창을 안전하게 닫고 다음 프레임으로 이동
return False # 콜백이 종료되었음을 나타냄
o3d.visualization.draw_geometries_with_key_callbacks(
[tgt_pcd, warped_est_pcd, warped_gt_pcd],
{ord("N"): callback},
window_name=f"Frame {index_str}",
width=800, height=600,
)
except Exception as e:
print(f"Error loading frame {index_str}: {e}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment