使用Python从二进制PNG生成STL模型时遇RuntimeError报错求助
问题求助:扫描电镜图像转3D STL时MeshLib代码报错RuntimeError: Bad expected access
我正在推进一个项目,目标是通过扫描电镜图像生成目标结构的3D STL文件。目前已经用自研的边缘检测代码得到了填充后的二进制图像,现在正尝试基于这个图像生成3D结构。参考代码时,持续在这一行报错:polyline2 = mr.distanceMapTo2DIsoPolyline(dm.value(), isoValue=127)
错误提示为:RuntimeError: Bad expected access。我没在网上找到相关原因,自己对Python也不算精通,恳请各位提供解决思路!
参考代码
import meshlib.mrmeshpy as mr # load image as Distance Map object: dm = mr.loadDistanceMapFromImage(mr.Path("your-image.png"), 0) # find boundary contour of the letter: polyline2 = mr.distanceMapTo2DIsoPolyline(dm.value(), isoValue=127) # triangulate the contour mesh = mr.triangulateContours(polyline2.contours2()) # extrude itself: mr.addBaseToPlanarMesh(mesh, zOffset=30) # export the result: mr.saveMesh(mesh, mr.Path("output-mesh.stl"))
已尝试的操作
- 重新配置代码依赖的MeshLib包
- 更新Visual Studio、Python及MeshLib版本
内容的提问来源于stack exchange,提问作者Davey Armstrong
相关产品推荐
相关产品推荐

