Ubuntu 16.04: waitKey(0) freezes screen in Spyder with OpenCV
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?