I start the script from the terminal with Python 3.8.10 python3 myprog.py
.
I have two problems:
- When I run it as is, it does prints
-1
indefinitely, but when I presss
it never gets inside theif
. - If I comment out
print(key)
after thewaitKey(1)
the program just waits for an input. It allows me to enter many characters and I have to press Enter. But, after pressing Enter it just adds a new line and waits for input again.
What am I doing wrong? Why do I get this behaviour in those two cases?
import cv2
def main():
while True:
key = cv2.waitKey(1)
print(key)
if 's' == chr(key & 255):
print("--------------INSIDE IF --------------")
if __name__ == '__main__':
main()