Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Put this before imshow

if cv2.waitKey(1) & 0xFF == ord('q'):
    cv2.destroyAllWindows()

Then if you hit q on your keyboard while imshow window is active it will close.

Or you can close it with an arbitrary key

import cv2
import numpy as np

fresh_image = np.ones((480,640),np.uint8)

if cv2.waitKey(1):
    cv2.destroyAllWindows()

cv2.imshow('image',fresh_image)
cv2.waitKey(0)
cv2.destroyAllWindows()