File size: 12,462 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 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1301,
"metadata": {},
"outputs": [],
"source": [
"# conda activate vision\n",
"# cd build\n",
"# cmake -DCMAKE_BUILD_TYPE=Release ..\n",
"# make\n",
"# ./FRICP ./data/bottle/tea_gt_filtered.ply ./data/bottle/tea_noisy_filtered.ply ./data/bottle/res/ 3\n",
"\n",
"\n",
"# 100_16 is the best thing. "
]
},
{
"cell_type": "code",
"execution_count": 1302,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"100_21\n"
]
}
],
"source": [
"import open3d as o3d\n",
"import numpy as np\n",
"\n",
"file_names = []\n",
"with open('filename.txt', 'r') as f:\n",
" for line in f:\n",
" file_names.append(line.strip())\n",
"filename = file_names[0]\n",
"print(filename)\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Modify initial file"
]
},
{
"cell_type": "code",
"execution_count": 1303,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"작업 완료!\n",
"'./initialized_result/initial_100_21.ply' 파일이 성공적으로 생성되었습니다.\n"
]
}
],
"source": [
"\n",
"output_filename = f'./initialized_result/initial_{filename}.ply'\n",
"\n",
"# 1. read file\n",
"\n",
"with open(f'./initialized_result/initial_{filename}.ply', 'r') as f:\n",
" lines = f.readlines()\n",
"\n",
"# 2. seperate data and header \n",
"header_lines = []\n",
"data_lines = []\n",
"is_header = True\n",
"\n",
"for line in lines:\n",
" if \"end_header\" in line:\n",
" is_header = False\n",
" continue\n",
" \n",
" if is_header:\n",
" header_lines.append(line)\n",
" \n",
" else: \n",
" parts = line.strip().split()\n",
" if len(parts) >= 3:\n",
" data_lines.append(f\"{parts[0]} {parts[1]} {parts[2]}\\n\")\n",
"\n",
"\n",
"# 3. modify header\n",
"# vertex\n",
"num_points = len(data_lines)\n",
"\n",
"# generate new header\n",
"\n",
"new_header = f\"\"\"ply\n",
"format ascii 1.0\n",
"element vertex {num_points}\n",
"property float x\n",
"property float y\n",
"property float z\n",
"element camera 1\n",
"property float view_px\n",
"property float view_py\n",
"property float view_pz\n",
"property float x_axisx\n",
"property float x_axisy\n",
"property float x_axisz\n",
"property float y_axisx\n",
"property float y_axisy\n",
"property float y_axisz\n",
"property float z_axisx\n",
"property float z_axisy\n",
"property float z_axisz\n",
"element phoxi_frame_params 1\n",
"property uint32 frame_width\n",
"property uint32 frame_height\n",
"property uint32 frame_index\n",
"property float frame_start_time\n",
"property float frame_duration\n",
"property float frame_computation_duration\n",
"property float frame_transfer_duration\n",
"property int32 total_scan_count\n",
"element camera_matrix 1\n",
"property float cm0\n",
"property float cm1\n",
"property float cm2\n",
"property float cm3\n",
"property float cm4\n",
"property float cm5\n",
"property float cm6\n",
"property float cm7\n",
"property float cm8\n",
"element distortion_matrix 1\n",
"property float dm0\n",
"property float dm1\n",
"property float dm2\n",
"property float dm3\n",
"property float dm4\n",
"property float dm5\n",
"property float dm6\n",
"property float dm7\n",
"property float dm8\n",
"property float dm9\n",
"property float dm10\n",
"property float dm11\n",
"property float dm12\n",
"property float dm13\n",
"element camera_resolution 1\n",
"property float width\n",
"property float height\n",
"element frame_binning 1\n",
"property float horizontal\n",
"property float vertical\n",
"end_header\n",
"\"\"\"\n",
"\n",
"#4. write 4file \n",
"\n",
"with open(output_filename,'w') as f:\n",
" f.write(new_header)\n",
"\n",
" for line in data_lines:\n",
" f.write(line)\n",
"\n",
"\n",
"print(\"\\n작업 완료!\")\n",
"print(f\"'{output_filename}' 파일이 성공적으로 생성되었습니다.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Source PCD"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 1304,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;33m[Open3D WARNING] Read PLY failed: unable to read file: ./initialized_result/initial_100_21.ply\u001b[0;m\n",
"Source shape: (6257, 3)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"RPly: Unexpected end of file\n",
"RPly: Error reading 'view_px' of 'camera' number 0\n"
]
}
],
"source": [
"\n",
"\n",
"\n",
"source_path = f\"./initialized_result/initial_{filename}.ply\"\n",
"\n",
"source_pcd = o3d.io.read_point_cloud(source_path)\n",
"\n",
"\n",
"\n",
"source_pcd_array = np.asarray(source_pcd.points)\n",
"print(\"Source shape:\", source_pcd_array.shape)\n",
"\n",
"coord_frame = o3d.geometry.TriangleMesh.create_coordinate_frame(size=50.0, origin=[0, 0, 0])\n",
"o3d.visualization.draw_geometries([source_pcd,coord_frame])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Target PCD"
]
},
{
"cell_type": "code",
"execution_count": 1305,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;33m[Open3D WARNING] Read PLY failed: unable to read file: gt_filtered.ply\u001b[0;m\n",
"Target shape: (50000, 3)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"RPly: Unexpected end of file\n",
"RPly: Error reading 'view_px' of 'camera' number 0\n"
]
}
],
"source": [
"target_path = f\"gt_filtered.ply\"\n",
"target_pcd = o3d.io.read_point_cloud(target_path)\n",
"\n",
"target_pcd_array = np.asarray(target_pcd.points)\n",
"print(\"Target shape:\", target_pcd_array.shape)\n",
"\n",
"o3d.visualization.draw_geometries([target_pcd, coord_frame])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Execute termianl"
]
},
{
"cell_type": "code",
"execution_count": 1306,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/home/cam/Fast-Robust-ICP/data/lighter\n",
"--- STDOUT (표준 출력) ---\n",
"명령어가 성공적으로 실행되었습니다.\n",
"source: 3x6257\n",
"target: 3x50000\n",
"scale = 573.158\n",
"begin registration...\n",
"Registration done!\n",
"\n"
]
}
],
"source": [
"# ./FRICP ./data/bottle_2/gt_filtered.ply ./data/bottle_2/result/noisy_filtered_100_1.ply ./data/bottle_2/res 3 execute\n",
"import os\n",
"print(os.getcwd())\n",
"\n",
"import subprocess\n",
"\n",
"cmd = [\n",
" '../../FRICP',\n",
" './gt_filtered.ply',\n",
" f'./initialized_result/initial_{filename}.ply',\n",
" './res',\n",
" '3'\n",
"]\n",
"\n",
"try:\n",
" result = subprocess.run(cmd, capture_output=True, text=True, check=True)\n",
"\n",
" print(\"--- STDOUT (표준 출력) ---\")\n",
" print(\"명령어가 성공적으로 실행되었습니다.\")\n",
" print(result.stdout)\n",
"\n",
"except FileNotFoundError:\n",
" print(\"--- 에러 발생! ---\")\n",
" print(f\"'{cmd[0]}' 파일을 찾을 수 없습니다.\")\n",
" print(\"경로가 올바른지, 파일이 그 위치에 존재하는지 확인해 주세요.\")\n",
"\n",
"except subprocess.CalledProcessError as e:\n",
" print(\"--- 에러 발생! ---\")\n",
" print(f\"명령어 실행 중 오류가 발생했습니다. (종료 코드: {e.returncode})\")\n",
" print(\"\\n--- STDERR (에러 원인) ---\")\n",
" print(e.stderr)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Change the path for result\n"
]
},
{
"cell_type": "code",
"execution_count": 1307,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Successfully moved and renamed 'resm3reg_pc.ply' to './result/final_result_100_21.ply'\n",
"Successfully moved and renamed 'resm3trans.txt' to './result/final_result_100_21.txt'\n"
]
}
],
"source": [
"import shutil\n",
"import os\n",
"\n",
"transformed_path = \"resm3reg_pc.ply\"\n",
"destination_path = f\"./result/final_result_{filename}.ply\"\n",
"transformed_path2 = \"resm3trans.txt\"\n",
"destination_path2 = f\"./result/final_result_{filename}.txt\"\n",
"\n",
"shutil.move(transformed_path, destination_path)\n",
"print(f\"Successfully moved and renamed '{transformed_path}' to '{destination_path}'\")\n",
"\n",
"\n",
"\n",
"shutil.move(transformed_path2, destination_path2)\n",
"print(f\"Successfully moved and renamed '{transformed_path2}' to '{destination_path2}'\")\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Transformed Source PCD"
]
},
{
"cell_type": "code",
"execution_count": 1308,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Transformed shape: (6257, 3)\n"
]
}
],
"source": [
"\n",
"transformed_pcd = o3d.io.read_point_cloud(destination_path)\n",
"\n",
"transformed_pcd_array = np.asarray(transformed_pcd.points)\n",
"print(\"Transformed shape:\", transformed_pcd_array.shape)\n",
"\n",
"o3d.visualization.draw_geometries([transformed_pcd, coord_frame])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Source (Original) + Target"
]
},
{
"cell_type": "code",
"execution_count": 1309,
"metadata": {},
"outputs": [],
"source": [
"source_pcd.paint_uniform_color([1, 0, 0])\n",
"target_pcd.paint_uniform_color([0, 1, 0])\n",
"\n",
"vis = o3d.visualization.Visualizer()\n",
"vis.create_window(window_name=\"Point Cloud Viewer\", width=1200, height=800, visible=True)\n",
"vis.add_geometry(source_pcd)\n",
"vis.add_geometry(target_pcd)\n",
"vis.add_geometry(coord_frame)\n",
"vis.run()\n",
"\n",
"\n",
"vis.destroy_window()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Transformed + Target"
]
},
{
"cell_type": "code",
"execution_count": 1310,
"metadata": {},
"outputs": [],
"source": [
"transformed_pcd.paint_uniform_color([1, 0, 0])\n",
"target_pcd.paint_uniform_color([0, 1, 0])\n",
"\n",
"vis = o3d.visualization.Visualizer()\n",
"vis.create_window(window_name=\"Point Cloud Viewer\", width=1200, height=800, visible=True)\n",
"vis.add_geometry(transformed_pcd)\n",
"vis.add_geometry(target_pcd)\n",
"vis.add_geometry(coord_frame)\n",
"vis.run()\n",
"vis.destroy_window()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|