繁体   English   中英

在一个源代码中,我输入它并得到: UserWarning:Matplotlib 当前正在使用 agg,这是一个非 GUI 后端,所以无法显示图

[英]In a source code, I typed it in and got: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure

代码是

import numpy as np
import matplotlib.pyplot as plt
import sys

image = cv2.imread(sys.argv[1])


gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)


plt.imshow(gray, cmap="gray")
plt.show()


edges = cv2.Canny(gray, threshold1=30, threshold2=100)


plt.imshow(edges, cmap="gray")
plt.show()

当我按照此处链接的教程中的说明键入时,它不起作用并显示上面的消息。 https://www.thepythoncode.com/article/canny-edge-detection-opencv-python完整消息是

UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
  plt.show()

任何帮助,将不胜感激。 谢谢!

如果您在 linux 上,例如 ubuntu 需要从终端安装 thinker

sudo apt-get install python3-tk

在 Mac 上

xcode-select --install
brew uninstall python
brew install python --with-tcl-tk

尝试使用 pip 或 conda install tkinter 在终端中安装 tkinter

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM