CV2 imshow environment error

My code is below. I am getting error for cv2.imshow. But matplotlib works fine and displays the image perfectly.

cv2.imshow not working at all.

Traceback (most recent call last):
at block 1, line 5
error: OpenCV(4.5.1) /tmp/pip-req-build-jhawztrk/opencv/modules/highgui/src/window.cpp:651: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function ‘cvShowImage’

import cv2
import matplotlib.pyplot as plt
image = cv2.imread("image1.png")

cv2.imshow("test", image)
cv2.waitKey(0)
cv2.destroyAllWindows()

plt.axis(False)
plt.imshow(image)
plt.show()

Hello @abhivachan,

All window-related cv2 stuff as well as waitKey doesn’t work in Datalore because Datalore works on the remote server in headless mode, without any windows

To display cv2 image you can use cv2_image function from Colabtools

1 Like