cv2 imshow displaying black images sometimes
I am trying out cv2 on ubuntu 20.04, python 3.7. I have run the following script:
import cv2
img = cv2.imread('butterfly.jpg')
cv2.imshow('ImageWindow', img)
cv2.waitKey()
Sometimes I would get the lovely picture of the original butterfly image,
but sometimes I would get a small black window.
The behavior is a bit random, and I am not sure what is causing this issue. Any help is appreciated, thanks!
Add Index zero to
cv2.waitKey(0)
Edit: I tested it on raspberry pi using linux w/out index. Actually, I don't know If this
cv2.waitKey(0)
work on UBUNTUI haven't seen this before, you can try to run the following script under Windows, using IDE can help you see the cause of the error. Maybe it would be better if you read the image using absolute path.Like this:
Having the same trouble. It seems to display correct about 50% of the time. Using named windows doesn't seem to help. I know the image is being read correctly as it plots fine using matplotlib.
ETA: I went back a couple of revisions with the opencv library and it works fine now. I am using Kubuntu 20.04. Doesn't seem to be a widespread problem.
I am having the same problem, can you please guide me how you fixed that?
I'm having the exact same problem... my machine is Ubuntu 18.04.4, using python 3.6.9, opencv version 4.3.0