'DisabledFunctionError: cv2.imshow() is disabled in Colab, because it causes Jupyter sessionsto crash

**DisabledFunctionError: cv2.imshow() is disabled in Colab, because it causes Jupyter sessions to crash; se **


import cv2
from google.colab.patches import cv2_imshow

image = cv2.imread("/content/runnnn.jfif")
lane_image = np.copy(image)
gray = cv2.cvtColor(lane_image, cv2.COLOR_RGB2GRAY)

cv2.imshow("result",gray)

cv2.waitKey(0)


Solution 1:[1]

Replace cv2.imshow("result",gray) with this:

cv2_imshow(gray)

You imported cv2_imshow correctly, you now just need to call the method.

Solution 2:[2]

cv2.imshow() is disabled in colab. So, you can import this replacement function which addresses this problem.

from google.colab.patches import cv2_imshow

and use cv2_imshow() instead of cv2.imshow() where needed.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DapperDuck
Solution 2 Usama