Python OpenCV - waitKey(0) does not respond? Python OpenCV - waitKey(0) does not respond? python python

Python OpenCV - waitKey(0) does not respond?


I found that it works if i press the key whilst the window is in focus. If the command line is in focus then nothing happens


Adding a cv2.waitKey(1) after you destroy the window should work in this case.

cv2.imshow('imgae',img)cv2.waitKey(0)cv2.destroyAllWindows()cv2.waitKey(1)


This code works for me from IDLE:

# -*- coding: utf-8 -*-# Objectif : découvrir le fonctionnement d'opencv-python# http://opencv-python-tutroals.readthedocs.org/en/latest/index.htmlimport numpy as npimport cv2# Load an color image in grayscaleimg = cv2.imread('Lena.tiff',0)WINDOW_NAME = 'Image de Lena'cv2.namedWindow(WINDOW_NAME, cv2.CV_WINDOW_AUTOSIZE)cv2.startWindowThread()# Display an imagecv2.imshow(WINDOW_NAME,img)cv2.waitKey(0) cv2.destroyAllWindows()

Hope this helps for future readers.