I\'m trying understand what 0xFF does under the hood in the following code snippet:
if cv2.waitKey(0) & 0xFF == ord(\'q\'):
break
A
In this code,
if cv2.waitKey(0) & 0xFF == ord('q'):
break
The waitKey(0) function returns -1 when no input is made whatsoever. As soon the event occurs i.e. a Button is pressed it returns a 32-bit integer.
The 0xFF in this scenario is representing binary 11111111 a 8 bit binary, since we only require 8 bits to represent a character we AND waitKey(0) to 0xFF. As a result, an integer is obtained below 255.
ord(char) returns the ASCII value of the character which would be again maximum 255.
Hence by comparing the integer to the ord(char) value, we can check for a key pressed event and break the loop.