From ec78bb2dd2f6e982571616ed0bb1e75176739770 Mon Sep 17 00:00:00 2001 From: HiraiKyo Date: Mon, 19 Aug 2024 08:19:33 +0900 Subject: [PATCH] =?UTF-8?q?=E5=87=BA=E5=8A=9B=E5=85=88arg=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ply_processor_basics/stl/stl2ply.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ply_processor_basics/stl/stl2ply.py b/ply_processor_basics/stl/stl2ply.py index 0f9e0cc..92f764e 100644 --- a/ply_processor_basics/stl/stl2ply.py +++ b/ply_processor_basics/stl/stl2ply.py @@ -1,5 +1,6 @@ #!/usr/bin/env /usr/bin/python3 +import os from typing import List import numpy as np @@ -7,8 +8,20 @@ def stl2ply( - name: str, cam_dir: List[float] = [-100.0, -100, 100], sample_points: int = 1000000, voxel_size: float = 1.0 + name: str, + cam_dir: List[float] = [-100.0, -100, 100], + sample_points: int = 1000000, + voxel_size: float = 1.0, + outdir="out", ): + """ + Convert a .stl file to a .ply file, output at `out` directory + :param name: name of the .stl file + :param cam_dir: camera direction + :param sample_points: number of points to sample + :param voxel_size: size of the voxel + :return: None + """ mesh = o3d.io.read_triangle_mesh(name + ".stl") mesh.compute_vertex_normals() pcd = mesh.sample_points_uniformly(number_of_points=sample_points) @@ -22,4 +35,5 @@ def stl2ply( pcd = pcdd.select_by_index(pt_map) - o3d.io.write_point_cloud(name + ".ply", pcd) + os.makedirs(outdir, exist_ok=True) + o3d.io.write_point_cloud(f"{outdir}/{name}.ply", pcd)