Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python opencv waitKey(1) not responding to input on Mac

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
like image 353
Hank Helmers Avatar asked Aug 15 '26 20:08

Hank Helmers


1 Answers

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.

like image 192
mhudnell Avatar answered Aug 18 '26 10:08

mhudnell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!