JavaEar 专注于收集分享传播有价值的技术资料

6个回答

    最佳答案
  1. Google colab crashes if you try to display image using cv2.imshow() instead import from google.colab.patches import cv2_imshow() and display using cv2_imshow()

  2. 参考答案2
  3. Found one workaround. We can use %matplotlib inline in the code to use . Used as example here in In[28] - link

  4. 参考答案3
  5. 参考答案4
  6. 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

  7. 参考答案5
  8. Instead of using cv2.imshow() try this:

    1. Change the import to from google.colab.patches import cv2_imshow
    2. Replace cv2.imshow() to cv2_imshow()

    I tried it and it worked for me.

  9. 参考答案6
  10. while in colab I run a script containing cv2_imshow(image) it returns

    Traceback (most recent call last):
      File "detect_faces.py", line 63, in <module>
        cv2_imshow(image)
      File "/usr/local/lib/python3.6/dist-packages/google/colab/patches/__init__.py", line 29, in cv2_imshow
        display.display(PIL.Image.fromarray(a))
    AttributeError: module 'PIL' has no attribute 'Image'
    

    why this isn't working?

    edit: i just had to add

    From PIL import Image
    

    to the script. The cell run works but returns

    <PIL.Image.Image image mode=RGB size=500x499 at 0x7FF595F2C320>
    

    and no image. is there an inline for this?