|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import open3d as o3d |
|
|
import numpy as np |
|
|
|
|
|
file_names = [] |
|
|
with open('filename.txt', 'r') as f: |
|
|
for line in f: |
|
|
file_names.append(line.strip()) |
|
|
filename = file_names[0] |
|
|
print(filename) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output_filename = f'./initialized_result/initial_{filename}.ply' |
|
|
|
|
|
|
|
|
|
|
|
with open(f'./initialized_result/initial_{filename}.ply', 'r') as f: |
|
|
lines = f.readlines() |
|
|
|
|
|
|
|
|
header_lines = [] |
|
|
data_lines = [] |
|
|
is_header = True |
|
|
|
|
|
for line in lines: |
|
|
if "end_header" in line: |
|
|
is_header = False |
|
|
continue |
|
|
|
|
|
if is_header: |
|
|
header_lines.append(line) |
|
|
|
|
|
else: |
|
|
parts = line.strip().split() |
|
|
if len(parts) >= 3: |
|
|
data_lines.append(f"{parts[0]} {parts[1]} {parts[2]}\n") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
num_points = len(data_lines) |
|
|
|
|
|
|
|
|
|
|
|
new_header = f"""ply |
|
|
format ascii 1.0 |
|
|
element vertex {num_points} |
|
|
property float x |
|
|
property float y |
|
|
property float z |
|
|
element camera 1 |
|
|
property float view_px |
|
|
property float view_py |
|
|
property float view_pz |
|
|
property float x_axisx |
|
|
property float x_axisy |
|
|
property float x_axisz |
|
|
property float y_axisx |
|
|
property float y_axisy |
|
|
property float y_axisz |
|
|
property float z_axisx |
|
|
property float z_axisy |
|
|
property float z_axisz |
|
|
element phoxi_frame_params 1 |
|
|
property uint32 frame_width |
|
|
property uint32 frame_height |
|
|
property uint32 frame_index |
|
|
property float frame_start_time |
|
|
property float frame_duration |
|
|
property float frame_computation_duration |
|
|
property float frame_transfer_duration |
|
|
property int32 total_scan_count |
|
|
element camera_matrix 1 |
|
|
property float cm0 |
|
|
property float cm1 |
|
|
property float cm2 |
|
|
property float cm3 |
|
|
property float cm4 |
|
|
property float cm5 |
|
|
property float cm6 |
|
|
property float cm7 |
|
|
property float cm8 |
|
|
element distortion_matrix 1 |
|
|
property float dm0 |
|
|
property float dm1 |
|
|
property float dm2 |
|
|
property float dm3 |
|
|
property float dm4 |
|
|
property float dm5 |
|
|
property float dm6 |
|
|
property float dm7 |
|
|
property float dm8 |
|
|
property float dm9 |
|
|
property float dm10 |
|
|
property float dm11 |
|
|
property float dm12 |
|
|
property float dm13 |
|
|
element camera_resolution 1 |
|
|
property float width |
|
|
property float height |
|
|
element frame_binning 1 |
|
|
property float horizontal |
|
|
property float vertical |
|
|
end_header |
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
with open(output_filename,'w') as f: |
|
|
f.write(new_header) |
|
|
|
|
|
for line in data_lines: |
|
|
f.write(line) |
|
|
|
|
|
|
|
|
print("\n작업 완료!") |
|
|
print(f"'{output_filename}' 파일이 성공적으로 생성되었습니다.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
source_path = f"./initialized_result/initial_{filename}.ply" |
|
|
|
|
|
source_pcd = o3d.io.read_point_cloud(source_path) |
|
|
|
|
|
|
|
|
|
|
|
source_pcd_array = np.asarray(source_pcd.points) |
|
|
print("Source shape:", source_pcd_array.shape) |
|
|
|
|
|
coord_frame = o3d.geometry.TriangleMesh.create_coordinate_frame(size=50.0, origin=[0, 0, 0]) |
|
|
o3d.visualization.draw_geometries([source_pcd,coord_frame]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
target_path = f"gt_filtered.ply" |
|
|
target_pcd = o3d.io.read_point_cloud(target_path) |
|
|
|
|
|
target_pcd_array = np.asarray(target_pcd.points) |
|
|
print("Target shape:", target_pcd_array.shape) |
|
|
|
|
|
o3d.visualization.draw_geometries([target_pcd, coord_frame]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import os |
|
|
print(os.getcwd()) |
|
|
|
|
|
import subprocess |
|
|
|
|
|
cmd = [ |
|
|
'../../FRICP', |
|
|
'./gt_filtered.ply', |
|
|
f'./initialized_result/initial_{filename}.ply', |
|
|
'./res', |
|
|
'3' |
|
|
] |
|
|
|
|
|
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})") |
|
|
print("\n--- STDERR (에러 원인) ---") |
|
|
print(e.stderr) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import shutil |
|
|
import os |
|
|
|
|
|
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" |
|
|
|
|
|
shutil.move(transformed_path, destination_path) |
|
|
print(f"Successfully moved and renamed '{transformed_path}' to '{destination_path}'") |
|
|
|
|
|
|
|
|
|
|
|
shutil.move(transformed_path2, destination_path2) |
|
|
print(f"Successfully moved and renamed '{transformed_path2}' to '{destination_path2}'") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
transformed_pcd = o3d.io.read_point_cloud(destination_path) |
|
|
|
|
|
transformed_pcd_array = np.asarray(transformed_pcd.points) |
|
|
print("Transformed shape:", transformed_pcd_array.shape) |
|
|
|
|
|
o3d.visualization.draw_geometries([transformed_pcd, coord_frame]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
source_pcd.paint_uniform_color([1, 0, 0]) |
|
|
target_pcd.paint_uniform_color([0, 1, 0]) |
|
|
|
|
|
vis = o3d.visualization.Visualizer() |
|
|
vis.create_window(window_name="Point Cloud Viewer", width=1200, height=800, visible=True) |
|
|
vis.add_geometry(source_pcd) |
|
|
vis.add_geometry(target_pcd) |
|
|
vis.add_geometry(coord_frame) |
|
|
vis.run() |
|
|
|
|
|
|
|
|
vis.destroy_window() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
transformed_pcd.paint_uniform_color([1, 0, 0]) |
|
|
target_pcd.paint_uniform_color([0, 1, 0]) |
|
|
|
|
|
vis = o3d.visualization.Visualizer() |
|
|
vis.create_window(window_name="Point Cloud Viewer", width=1200, height=800, visible=True) |
|
|
vis.add_geometry(transformed_pcd) |
|
|
vis.add_geometry(target_pcd) |
|
|
vis.add_geometry(coord_frame) |
|
|
vis.run() |
|
|
vis.destroy_window() |
|
|
|
|
|
|