{ "cells": [ { "cell_type": "code", "execution_count": 1634, "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": 1635, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "100_7\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": 1636, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "작업 완료!\n", "'./initialized_result/initial_100_7.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": [ "### Source PCD" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 1637, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1;33m[Open3D WARNING] Read PLY failed: unable to read file: ./initialized_result/initial_100_7.ply\u001b[0;m\n", "Source shape: (12943, 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": 1638, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "RPly: Unexpected end of file\n", "RPly: Error reading 'view_px' of 'camera' number 0\n" ] }, { "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" ] } ], "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": 1639, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/cam/Fast-Robust-ICP/data/lightbulb\n", "--- STDOUT (표준 출력) ---\n", "명령어가 성공적으로 실행되었습니다.\n", "source: 3x12943\n", "target: 3x50000\n", "scale = 597.405\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": 1640, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Successfully moved and renamed 'resm3reg_pc.ply' to './result/final_result_100_7.ply'\n", "Successfully moved and renamed 'resm3trans.txt' to './result/final_result_100_7.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": 1641, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Transformed shape: (12943, 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": 1642, "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": 1643, "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 }