Reputation: 1080
I followed a tutorial, and tried to make the program quit when I press q
, but that doesn't work, it quits no matter which key I press, that's the code:
twi = cv2.imread('large.png')
cv2.namedWindow('image', cv2.WINDOW_NORMAL)
cv2.imshow('image', twi)
key = cv2.waitKey(0)
if key == ord('q'):
cv2.destroyAllWindows()
And I've tried to add &0xFF
:
key = cv2.waitKey(0)&0xFF
Still not working, what is wrong with it? Can I fix it?
=============Update============
I added print(key)
to that, when pressing q
, variable key
is 113
, and ord('q')
is 113
either, can't understand why it doesn't work...
=============Solved=============
(Seems that I forget how if
works...)
Upvotes: 1
Views: 3803
Reputation: 4603
Continuously calling cv2.waitKey(0)
when it doesn't return the key value for the q
key might work:
while cv2.waitKey(0) != ord('q'):
pass
cv2.destroyAllWindows()
Upvotes: 6