File size: 4,439 Bytes
5236ead |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
import open3d as o3d
import numpy as np
import json
import os
import subprocess
import shutil # shutil 임포트 추가
# 데이터셋 폴더와 JSON 파일 경로
folder = "./dataset"
json_path = "ply_files.json"
categories= ['100', '75', '50', '25', '0']
try:
with open(json_path, "r", encoding="utf-8") as f:
categorized_files = json.load(f)
except FileNotFoundError:
print(f"오류: '{json_path}' 파일을 찾을 수 없습니다. 먼저 파일 분류 코드를 실행해 주세요.")
exit()
print("=== 데이터 처리 시작 ===")
for category in categories:
print(f"\n--- [카테고리: {category} 처리 시작 ---")
filenames_in_category = categorized_files.get(category, [])
if not filenames_in_category:
print("처리할 파일이 없습니다.")
continue
for filename in filenames_in_category:
print(f"\n>>> 파일 처리 중: {filename}.ply")
# ... (이전 파일 수정 및 저장 코드는 그대로) ...
# In[23] 부분은 여기에 그대로 둡니다.
# ...
# ### Execute terminal
# ⭐️ 해결 방법 1: FRICP 실행 전 이전 결과 폴더 삭제
# 각 루프마다 깨끗한 상태에서 시작하도록 보장합니다.
if os.path.exists('./res'):
shutil.rmtree('./res')
print("이전 'res' 폴더를 삭제했습니다.")
source_path = f'./initialized_result/initial_{filename}.ply'
print(f"--- 로딩 시도 중인 파일: {source_path}")
if not os.path.exists(source_path):
print("!!!!!! 에러: 해당 경로에 파일이 존재하지 않습니다!")
continue # 다음 파일로 넘어감
cmd = [
'../../FRICP',
'./gt_filtered.ply',
f'./noisy_result/noisy_filtered_{filename}.ply',
'./res', # FRICP는 이 폴더에 결과를 저장합니다.
'3'
]
print(cmd)
try:
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
print("--- STDOUT (표준 출력) ---")
print("명령어가 성공적으로 실행되었습니다.")
print(result.stdout)
except FileNotFoundError:
print("--- 에러 발생! ---")
print(f"'{cmd[0]}' 파일을 찾을 수 없습니다.")
print("경로가 올바른지, 파일이 그 위치에 존재하는지 확인해 주세요.")
except subprocess.CalledProcessError as e:
print("--- 에러 발생! ---")
print(f"명령어 실행 중 오류가 발생했습니다. (종료 코드: {e.returncode})")
# STDOUT과 STDERR을 모두 출력
print("\n--- STDOUT (오류 발생 전 표준 출력) ---")
print(e.stdout)
print("\n--- STDERR (에러 원인) ---")
print(e.stderr)
continue # 오류 발생 시 다음 파일로 넘어갑니다.
# ### Change the path for result
# ⭐️ 해결 방법 2: 정확한 파일 경로 지정
# FRICP가 'res' 폴더 안에 결과를 생성하므로, 경로를 정확히 명시합니다.
transformed_path = "./resm3reg_pc.ply"
destination_path = f"./result/final_result_{filename}.ply"
transformed_path2 = "./resm3trans.txt"
destination_path2 = f"./result/final_result_{filename}.txt"
# 파일 이동 전, 파일이 실제로 존재하는지 확인하는 것이 더 안정적입니다.
if os.path.exists(transformed_path):
shutil.move(transformed_path, destination_path)
print(f"Successfully moved '{transformed_path}' to '{destination_path}'")
else:
print(f"오류: '{transformed_path}' 파일을 찾을 수 없어 이동하지 못했습니다.")
if os.path.exists(transformed_path2):
shutil.move(transformed_path2, destination_path2)
print(f"Successfully moved '{transformed_path2}' to '{destination_path2}'")
else:
print(f"오류: '{transformed_path2}' 파일을 찾을 수 없어 이동하지 못했습니다.")
# ... (이후 시각화 코드는 그대로) ...
# In[28], In[29], In[30] 부분은 여기에 그대로 둡니다.
# ...
print("\n\n=== 모든 데이터 처리 완료! ===") |