python - 如何将 matplotlib 注释操作嵌入到函数中?
问题描述
使用 matplotlib,您可以与绘制的图像进行交互,例如用于注释。然后,您会在交互后获得一些您通常喜欢保存的数据。我想将所有这些都合并到一个函数中,但我不知道该怎么做。光谱模块说明了我的问题,但我之前遇到过这个问题。
这是一些代码:
import spectral as spy
class Annotator:
def __init__(self, filename):
self.filename = filename
self.classes = list(zip(range(5), ['unknown','background','tape','healthy','infected']))
def img(self):
img=spy.open_image(self.filename)
return img
def viewer(self):
img = self.img()
print(self.classes)
viewer = spy.imshow(img)
annotation = viewer.classes
return annotation
如果我调用 Annotator An=Annotator(some data file)
,然后调用查看器并注释
results = An.viewer
然后 python 立即解析到最后,并给出一个空的非类型对象作为结果。我希望代码中断,以便我可以获取注释并将其保存在同一个函数调用中。
所以我的问题是,我该怎么做?
解决方案
推荐阅读
- azure - 具有一个字符串和一个字符串列表的相似性 API
- python - 删除后嵌套列表不更新
- android - 如何使用 ADB 和 UiAutomator 从模拟器中提取用户界面 XML
- python-3.x - 如何防止 GCP 中的 http python 请求中的对等方重置连接
- excel - 使用 CountIf 循环文本然后移动到下一列
- c# - 如何通过方法调用使游戏对象相对于自身移动一些固定单位
- c# - 如果文件存在于公共静态字符串中,我该如何使用?错误:并非所有代码都返回值
- jenkins - Jenkins email-ext:如何在我的 jelly 脚本输出中包含 html 文件的内容?
- java - 使用 Peaks 代码 Java 时遇到问题。程序编译运行后没有任何返回,请问是什么问题?
- php - 如何在循环中将会话变量更改为特定变量