Reputation: 111
Without the cv2.waitkey() method the cv2.imshow() displays black window. Why does the rendering does not happen properly without the wait?
cap = cv2.VideoCapture(video_path)
while cap.isOpened():
ret,frame = cap.read()
cv2.imshow('window-name',frame)
# without the following cv2.waitkey(1) statement the cv2.imshow() displays a blank window
if cv2.waitKey(1) & 0xFF == ord('q'): # wait for 1 millisecond
break
continue
Upvotes: 9
Views: 13407
Reputation: 2337
From the documentation of cv2.imshow()
, the NOTE section mentions that the window is displayed for the amount of time indicated by the argument in cv2.waitKey()
. An argument of 0
indicates wait forever, so the image will be displayed forever unless you handle the keypress.
Controlling the duration for which the window needs to displayed is a useful aspect while debugging, displaying intermediate images, etc.
From the documentation of cv2.waitKey()
, the NOTE section mentions that 'This function is the only method in HighGUI that can fetch and handle events, so it needs to be called periodically for normal event processing unless HighGUI is used within an environment that takes care of event processing.'
You can notice that without the cv2.waitKey()
, if you hover over the window that is displayed, the 'busy' cursor with the rolling wheel is displayed, indicating that the window is busy.
Upvotes: 14