Home>

The program that reads the image and displays it gives the following error message:
I would like to know where to improve.

↓ Reference page
http://labs.eecs.tottori-u.ac.jp/sd/Member/oyamada/OpenCV/html/py_tutorials/py_gui/py_image_display/py_image_display.html

·Error message
-------------------------------------------------- -------------------------
DisabledFunctionError Traceback (most recent call last)
<ipython-input-4-74a16ad73a7b>in<module>()
---->1 cv2.imshow ('image', img)
      2 cv2.waitKey (0)
      3 cv2.destroyAllWindows ()
/usr/local/lib/python3.6/dist-packages/google/colab/_import_hooks/_cv2.py in wrapped (* args, ** kwargs)
     50 def wrapped (* args, ** kwargs):
     51 if not os.environ.get (env_var, False):
--->52 raise DisabledFunctionError (message, name or func.__name__)
     53 return func (* args, ** kwargs)
     54
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
Corresponding source code
import numpy as np
import cv2
#Load an color image in grayscale
img = cv2.imread ('messi5.jpg', 0)
cv2.imshow ('image', img)
cv2.waitKey (0)
cv2.destroyAllWindows ()
  • Answer # 1

    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


    When I see this message,
    "Cv2.imshow () crashes Jupyter, so I can't use it. See http ~."
    Therefore, this function cannot be used in Jupyter. However,
    "Instead, consider using one of the following:
    from google.colab.patches import cv2_imshow "
    It says, so why not try it exactly as it is?

    Or run it directly instead of Jpyter.

  • Answer # 2

    It's not written in the question, but is it okay to use Google Colab?

    It's all written in the error message.

    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

    If you can't read English, copy and paste it like DeepL or Google Translate.