import sys import cv2 as cv def handle_keyboard(delay_amt=1): '''Used with cv.imshow('title', image) to wait for keyboard press ''' while True: k = cv.waitKey(delay_amt) & 0xFF if k == 27 or k == ord('q'): # ESC cv.destroyAllWindows() sys.exit() elif k != 255: # any key to continue break