瓶plt.imshow公司当[NSGraphicsContext currentContext]为ni时,绘制图像没有意义

2024-04-26 11:07:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我的阈值图像,然后我想显示图像使用plt.imshow公司. 你知道吗

ret, threshold = cv2.threshold(gray, 100, 255, cv2.THRESH_BINARY)
plt.imshow(threshold)
plt.show()

但是我得到了错误

> It does not make sense to draw an image when [NSGraphicsContext
> `currentContext] is nil.  This is a programming error. Break on void
> _NSWarnForDrawingImageWithNoCurrentContext(void) to debug.  This will be logged only once.  This may break in the future.`

Tags: to图像thresholdis公司plt阈值this
1条回答
网友
1楼 · 发布于 2024-04-26 11:07:15

My question is, in the last line of code, since s1 and s2 are being concat with a space, doesn't this also create new objects?

是的,它创建了第10个字符串

请注意,这段代码本身只需要创建5个字符串——如果您在同一个JVM中多次运行它,每次调用它时它都会创建5个新字符串。字符串文本不会在每次代码运行时创建新字符串。(例如,每次"spring "都会重复使用相同的字符串对象。)

您给出的代码中有10个字符串:

  • 5个字:“春”、“夏”、“秋”、“冬”和“
  • 5个串联结果:s1 + "summer"s1.concat("fall ")s1 + winter(带复合赋值)和s1 + " " + s2

正如我刚才所评论的,代码中出现的字符串文本并不总是包含一个单独的字符串。例如,考虑:

String x = "Foo" + "Bar";

您可能认为这涉及三个字符串对象——一个用于每个文本,一个用于连接。事实上,它只涉及一个,因为编译器在编译时执行串联,所以代码有效:

String x = "FooBar";

相关问题 更多 >