I'm very new to opencv, and I've been trying to get user input to exit out of all my open windows and escape the while loop. I've tried a bunch of different conditions, and checked that my Mac is giving keyboard permissions to python, but for some reason the waitKey function doesn't seem to be registering when I input anything into the keyboard. Any suggestions on what I should do ?
while True:
screenshot = py.screenshot()
screenshot = np.array(screenshot)
screenshot = cv.cvtColor(screenshot, cv.COLOR_BGR2RGB)
cv.imshow('Computer Vision', screenshot)
if cv.waitKey(1) == ord('q'):
print("shit")
cv.destroyAllWindows()
break
Try cv2.waitKey(1) & 0xFF == ord('q'): as 0xFF can be necessary on certain OSs.
You may also try inspecting the values of cv.waitKey(1) and ord('q') to see how they differ.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With