我计划用Python为raspberrypi编写一个程序,以导入3D STL图像。
为此,我在谷歌上搜索并得到了一个名为"numpy-stl“的Python库,它适合我的需求。我是按照website的说明安装的
sudo pip install numpy-stl然后尝试运行示例中给定的Code。
from stl import mesh
# Using an existing stl file:
mesh = mesh.Mesh.from_file('some_file.stl')
# Or creating a new mesh:
VERTICE_COUNT = 100
data = numpy.zeros(VERTICE_COUNT, dtype=Mesh.dtype)
mesh = mesh.Mesh(data, remove_empty_areas=False)
# The mesh normals (calculated automatically)
mesh.normals
# The mesh vectors
mesh.v0, mesh.v1, mesh.v2
# Accessing individual points (concatenation of v0, v1 and v2 in triplets)
mesh.points[0] == mesh.v0[0]
mesh.points[1] == mesh.v1[0]
mesh.points[2] == mesh.v2[0]
mesh.points[3] == mesh.v0[1]
mesh.save('new_stl_file.stl')但现在我面临以下错误:
Traceback (most recent call last):
File "/home/pi/checkstl.py", line 1, in <module>
from stl import stl
File "/usr/local/lib/python2.7/dist-packages/stl/__init__.py", line 2, in <module>
import stl.ascii
ImportError: No module named ascii 有人能指导我如何解决这个错误吗?谢谢
发布于 2015-08-11 00:40:01
发布于 2019-10-23 21:25:28
顺便说一句,你可以用meshio (我写的)做同样的事情,只是它适用于所有网格格式。
pip install meshioimport meshio
mesh = meshio.read("input.stl") # or .off, .vtk, .ply, ...
# mesh.points, mesh.cells, ...https://stackoverflow.com/questions/29661823
复制相似问题