{ "cells": [ { "cell_type": "markdown", "id": "c97d9003", "metadata": {}, "source": [ "## PCD file transformation" ] }, { "cell_type": "code", "execution_count": 555, "id": "57266b06", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0_19\n", "\u001b[1;33m[Open3D WARNING] Read PLY failed: unable to read file: ./gt_filtered.ply\u001b[0;m\n", "PLY 파일이 PCD 파일로 성공적으로 변환되었습니다.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "RPly: Unexpected end of file\n", "RPly: Error reading 'view_px' of 'camera' number 0\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", "\n", "# PLY 파일 읽기\n", "pcd = o3d.io.read_point_cloud(\"./gt_filtered.ply\")\n", "\n", "# PCD 파일로 저장 (바이너리 형식)\n", "o3d.io.write_point_cloud(\"./initialize_pcdfile/gt_filtered.pcd\", pcd)\n", "\n", "# 만약 ASCII 형식으로 저장하고 싶다면:\n", "# o3d.io.write_point_cloud(\"output_ascii.pcd\", pcd, write_ascii=True)\n", "\n", "print(\"PLY 파일이 PCD 파일로 성공적으로 변환되었습니다.\")" ] }, { "cell_type": "code", "execution_count": 556, "id": "8b0bc642", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;33m[Open3D WARNING] Read PLY failed: unable to read file: ./noisy_result/noisy_filtered_0_19.ply\u001b[0;m\n", "PLY 파일이 PCD 파일로 성공적으로 변환되었습니다.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "RPly: Unexpected end of file\n", "RPly: Error reading 'view_px' of 'camera' number 0\n" ] } ], "source": [ "# PLY 파일 읽기\n", "pcd = o3d.io.read_point_cloud(f\"./noisy_result/noisy_filtered_{filename}.ply\")\n", "\n", "# PCD 파일로 저장 (바이너리 형식)\n", "o3d.io.write_point_cloud(f\"./initialize_pcdfile/first_{filename}.pcd\", pcd)\n", "\n", "# 만약 ASCII 형식으로 저장하고 싶다면:\n", "# o3d.io.write_point_cloud(\"output_ascii.pcd\", pcd, write_ascii=True)\n", "\n", "print(\"PLY 파일이 PCD 파일로 성공적으로 변환되었습니다.\")" ] }, { "cell_type": "markdown", "id": "fcdc0f5e", "metadata": {}, "source": [ "## Execute initial Guess" ] }, { "cell_type": "code", "execution_count": 557, "id": "5d191e44", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/cam/Fast-Robust-ICP/data/spray\n", "--- STDOUT (표준 출력) ---\n", "명령어가 성공적으로 실행되었습니다.\n", "Loaded source point cloud: (15645, 3)\n", "Loaded target point cloud: (50000, 3)\n", "Resolution: 1.0\n", "Yaw Augmentation Angle: None\n", "============== Time ==============\n", "Voxelization: 0.00235012 sec\n", "Extraction : 0.0616061 sec\n", "Pruning : 0.0188817 sec\n", "Matching : 0.0533112 sec\n", "Solving : 4.1555e-05 sec\n", "----------------------------------\n", "\u001b[1;32mTotal : 0.136191 sec\u001b[0m\n", "====== # of correspondences ======\n", "# initial pairs : 381\n", "# pruned pairs : 16\n", "----------------------------------\n", "\u001b[1;36m# rot inliers : 4\n", "# trans inliers : 0\u001b[0m\n", "==================================\n", "\u001b[1;33m=> Registration might have failed :(\u001b[0m\n", "\n", "<_kiss_matcher.RegistrationSolution object at 0x7d672758f230>\n", "ply complete.\n", "Visualization complete.\n", "\n" ] } ], "source": [ "import os\n", "print(os.getcwd())\n", "\n", "import subprocess\n", "\n", "cmd = [\n", " 'python3',\n", " '../../../KISS-Matcher/python/examples/run_kiss_matcher.py',\n", " '--src_path',\n", " f'./initialize_pcdfile/first_{filename}.pcd',\n", " '--tgt_path',\n", " './initialize_pcdfile/gt_filtered.pcd',\n", " '--resolution',\n", " '1'\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", "id": "0128f9e3", "metadata": {}, "source": [ "## Saving initialized data\n" ] }, { "cell_type": "code", "execution_count": 558, "id": "63441612", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Successfully moved and renamed 'output.ply' to './initialized_result/initial_0_19.ply'\n" ] } ], "source": [ "import shutil\n", "import os\n", "\n", "transformed_path = \"output.ply\"\n", "destination_path = f\"./initialized_result/initial_{filename}.ply\"\n", "\n", "\n", "shutil.move(transformed_path, destination_path)\n", "print(f\"Successfully moved and renamed '{transformed_path}' to '{destination_path}'\")\n", "\n" ] } ], "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": 5 }