我想使用python将pcd文件转换成stl文件,但是生成的stl文件精度太低。我诉求优化这个代码
我使用了open3d库将pcd转化成numpy格式,然后用stl库将numpy转化成STL,如下是我的代码:
```python
import open3d as o3d
import numpy as np
from scipy import spatial
from stl import mesh
def pcd2stl(path):
data_pcd = o3d.io.read_point_cloud(path)
data_xyz = np.nan_to_num( np.asarray(data_pcd.points) )
# print(xyz_load)
data_faces = spatial.ConvexHull(data_xyz).simplices
data_cube = mesh.Mesh(np.zeros(data_faces.shape[0], dtype=mesh.Mesh.dtype))
for i, f in enumerate(data_faces):
for j in range(3):
data_cube.vectors[i][j] = data_xyz[f[j], :]
data_cube.save('inbox_from_pointcloud.stl')
```