Image is not displaying in Google Colab while using imshow()

前端 未结 5 1746
甜味超标
甜味超标 2020-12-09 11:48

I am working on a project which requires functions from OpenCV to plot images. I am trying to display image using the below code in Google Colab. But nothing shows up in the

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 12:05

    The cv2.imshow() and cv.imshow() functions from the opencv-python package are incompatible with Jupyter notebook; see https://github.com/jupyter/notebook/issues/3935.

    As a replacement, you can use the following function:

    from google.colab.patches import cv2_imshow
    

    For example, here we download and display a PNG image of the Colab logo:

    !curl -o logo.png https://colab.research.google.com/img/colab_favicon_256px.png
    import cv2
    img = cv2.imread('logo.png', cv2.IMREAD_UNCHANGED)
    cv2_imshow(img)
    

    Credits: Code Snippets in Google Colab

提交回复
热议问题