Hank Helmers
Hank Helmers

Reputation: 43

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

Upvotes: 3

Views: 1102

Answers (1)

mhudnell
mhudnell

Reputation: 131

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.

Upvotes: 1

Related Questions