File size: 6,060 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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
#!/usr/bin/env python
# coding: utf-8
# In[21]:
# conda activate vision
# cd build
# cmake -DCMAKE_BUILD_TYPE=Release ..
# make
# ./FRICP ./data/bottle/tea_gt_filtered.ply ./data/bottle/tea_noisy_filtered.ply ./data/bottle/res/ 3
# 100_16 is the best thing.
# In[22]:
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)
# # Modify initial file
# In[23]:
output_filename = f'./initialized_result/initial_{filename}.ply'
# 1. read file
with open(f'./initialized_result/initial_{filename}.ply', 'r') as f:
lines = f.readlines()
# 2. seperate data and header
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")
# 3. modify header
# vertex
num_points = len(data_lines)
# generate new header
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
"""
#4. write 4file
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 PCD
# In[ ]:
# In[24]:
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])
# In[ ]:
# ### Target PCD
# In[25]:
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])
# ## Execute termianl
# In[26]:
# ./FRICP ./data/bottle_2/gt_filtered.ply ./data/bottle_2/result/noisy_filtered_100_1.ply ./data/bottle_2/res 3 execute
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)
# ### Change the path for result
#
# In[27]:
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 Source PCD
# In[28]:
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 (Original) + Target
# In[29]:
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 + Target
# In[30]:
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()
|