【问题标题】:How do i show an image in google Colab?如何在谷歌 Colab 中显示图像?
【发布时间】:2020-12-09 20:28:32
【问题描述】:

当我使用时

cv2.imshow(img)

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

我该如何解决这个问题?

【问题讨论】:

    标签: python opencv google-colaboratory


    【解决方案1】:

    在 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)
    

    【讨论】:

      【解决方案2】:

      试试这个:

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

      【讨论】:

        猜你喜欢
        • 2020-03-19
        • 2021-03-25
        • 2020-03-24
        • 1970-01-01
        • 2016-02-11
        • 1970-01-01
        • 2022-01-20
        • 2021-01-18
        • 1970-01-01
        相关资源
        最近更新 更多