如何在google Colab中显示图像?

2024-06-16 14:37:42 发布

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

当我使用

cv2.imshow(img)

colab抛出一个DisabledFunctionErrorhttps://github.com/jupyter/notebook/issues/3935)。 使用cv2_imshow(img)我得到另一个错误,AttributeError: 'NoneType' object has no attribute 'clip')

我怎样才能解决这个问题


Tags: httpsgithubcomimgobject错误jupytercv2
2条回答

在Google Colab中使用cv2.imshow(img)返回以下输出:

DisabledFunctionError: cv2.imshow() is disabled in Colab, because it causes Jupyter sessions
to crash; see https://github.com/jupyter/notebook/issues/3935.
As a substitution, consider using
  from google.colab.patches import cv2_imshow

因此,您可以简单地使用:

from google.colab.patches import cv2_imshow
import matplotlib.pyplot as plt

img = "yourImage.png"
img = cv2.imread(img) # reads image
plt.imshow(img)

试试这个:

from google.colab.patches import cv2_imshow
cv2_imshow(img)

相关问题 更多 >