imshow fails when you pass an empty image, as pointed out by @101. In your case, this is most likely due to the fact that you ignore empty frames from cap.read() and call imshow even if cap.read returned an empty image.
To fix this, replace your while True loop with a while cap.isOpened() or check whether cap.isOpened() has been successful before reading frames.