python - 如何在谷歌 Colab 中显示图像?
问题描述
当我使用
cv2.imshow(img)
colab 抛出一个DisabledFunctionError
(https://github.com/jupyter/notebook/issues/3935)。使用 cv2_imshow(img) 我得到另一个错误,AttributeError: 'NoneType' object has no attribute 'clip')
.
我该如何解决这个问题?
解决方案
在 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)
推荐阅读
- python - Selenium Python 无法提取 [object Text] 它应该是一个元素
- javascript - 将日期转换为 M j, Y?在 Javascript 中
- vue.js - 我想要做的是使用单个打印按钮从多台打印机同时打印表单的不同打印输出
- regex - 带有组名并包含标签的正则表达式 XML
- sql - 基于字符串模式检索父记录的 Oracle SQL 查询
- cryptography - 密码学:关于流密码的问题
- python - 如何为循环的特定部分添加延迟
- javascript - 将组件作为 React setState 值传递时有问题吗?
- python - sqlite3 向表中添加行不添加任何错误
- c# - 如何提高选项卡式页面 xamarin 表单中的加载性能