Python 3.7.8  OpenCV 3.4.2
For example, this image of Lena.
Normally, display the image with the following code and press the appropriate key to close the window. However, when I press the close button, the window closes but the python process remains running.
open.py
import cv2
img = cv2.imread("lena.jpg ")
#Display image
cv2.imshow("img", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
It's basically the same as Other method, but with a little shorter code and everything as before. Originality is also compatible with the key input of.
python
import cv2
img = cv2.imread("lena.jpg ")
while(1):
cv2.imshow('img', img)
key = cv2.waitKey(100) & 0xff
if key != 255 or cv2.getWindowProperty('img', cv2.WND_PROP_AUTOSIZE) == -1:
cv2.destroyAllWindows()
exit()
I hope it helps those who are in trouble with the same thing.
Recommended Posts