You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 17:25:36