isl-org / Open3D

Open3D: A Modern Library for 3D Data Processing
http://www.open3d.org
Other
11.45k stars 2.31k forks source link

Converting from an .stl file to .ply or .pcd file #867

Closed coolinfan20 closed 5 years ago

coolinfan20 commented 5 years ago

Hi,

How would I convert an STL file to a point cloud file (either .pcd or .ply file)? I have tried reading the STL file as a mesh file and then using the following code to try to convert it to a point cloud, but this does not work.

Using the python package numpy-stl, I did the following to read the mesh: your_mesh = mesh.Mesh.from_file("/../../Open3D/examples/Python/Basic/Dog.stl")

and then your source code: pcd = PointCloud() pcd.points = Vector3dVector(your_mesh) write_point_cloud("../../TestData/test_dog.ply", pcd) pcd_load = read_point_cloud("../../TestData/test_dog.ply") draw_geometries([pcd_load])

but it isn't able to execute the draw_geometries function. Is there another way to import and convert an stl file into a pcd or ply file?

Thanks!

mzahirulj commented 5 years ago

Hi, you can install openmesh Framwork to solved your Problem.

import openmesh as om

mesh = om.TriMesh() om.read_mesh(mesh, source_file.stl) om.write_mesh(mesh, output_file.ply)

oseh commented 4 years ago

Hey does anyone know how to convert a .ply to .pcd

tanayag commented 4 years ago

I tried this and it worked, if you want to convert triangular mesh to point cloud

import open3d as o3d

mesh = o3d.io.read_triangle_mesh("file.stl")
pointcloud = mesh.sample_points_poisson_disk(100000)

# you can plot and check
o3d.visualization.draw_geometries([mesh])
o3d.visualization.draw_geometries([pointcloud])