The role of cv2 waitKey

In the process of using python's openCV, if you use directly

cv2.imshow('img', img)

Then the image will not be displayed, it will flash back and then disappear. We need to let the image wait for a while before disappearing, so we use waitKey, a good partner of imshow. The parameter behind the coat Key is used to set how many milliseconds the image stays. You can use code like this

        cv2.imshow("video", frame)
        c = cv2.waitKey(50)

This will display for 50ms and then disappear.

Then we sometimes see the following two codes

 if cv2.waitKey(1000) & 0xFF == ord(‘q’)

#或者

 cv2.imshow("video", frame)
 c = cv2.waitKey(50)
 if c == 113:
     break

The latter is that this opencv will accept the return value and then return, if it needs to be terminated or what operation can be done like this

I don't quite understand the former, here is a reference to a high collection answer on CSDN.

cv2.waitKey(1000) means to accept the return value of a keyboard within 1000ms

0xff is obviously a hexadecimal number

ord('q') returns the binary code of q

In fact, it means that if the returned number is the binary code of q, it will be True and then go to the next step, so why use 11111111 to merge with the number? That’s because the returned number is sometimes greater than 255. At this time, the sum can guarantee that it is within 255, and the program will not report an error. If it is, then the sum with 0xff will definitely be within 0-255, don’t worry about it.

My understanding is this

Guess you like

Origin blog.csdn.net/Aaron9489/article/details/130161911