The video window freezes or won't close
- Python
- OpenCV
Why it happens
cv2.waitKey(1)isn't in the loop.- The terminal, not the video window, has the keyboard.
How to fix it
- Put
if cv2.waitKey(1) & 0xFF == ord('q'): breakin the loop. - Click on the video window, then press q.
- End with
cap.release()andcv2.destroyAllWindows(). - Stuck? Press Ctrl+C in the terminal.
It worked if: q closes the window.
Related errors
Tutorials where it can happen
From the official documentation. From OpenCV's documentation of waitKey. Sources: OpenCV: highgui.
Didn't help? Search another error or ask us.

