Ubuntu 16.04: waitKey(0) freezes screen in Spyder with OpenCV

asked 2018-09-14 08:58:11 -0500

I am using openCV in Spyder. I tried to display an image using the following code:

import cv2

img = cv2.imread('text.png')

cv2.imshow('Image',img)

cv2.waitKey(0)

When I run this in Windows 10, it works perfectly. The image window closes on key press. But when I run this in Ubuntu 16.04, the image window opens but freezes if I press any key or click the close button. Then, few seconds later, it says 'Window not responding' and I have to force quit.

I've seen multiple different posts about this on StackOverflow and github with different solutions but none of them seem to work. I really want this to work in Ubuntu.

What do I do?

edit retag flag offensive close merge delete