如何理解cv2.waitKey(1)和0xff == ord(‘q‘)

  • 摘录一

cv2.waitKey(1)返回当前按下的键的字符代码,如果未按下任何键,则返回-1。 & 0xFF是二进制AND操作,以确保仅保留键的单字节(ASCII)表示,对于某些操作系统, cv2.waitKey(1)将返回不是单字节的代码。 ord(‘q’)始终返回ord(‘q’)的ASCII表示形式,为113(十六进制为0x71)。因此,如果在评估cv2.waitKey(1)时用户按下q键,将确定以下内容:

cv2.waitKey(1) & 0xFF == cv2.ord('q')
0xXX71 & 0xFF == 0x71
0x71 == 0x71
True
  • 摘录二
    不使用 ord() 和 0xFF :
def display_facial_prediction_results(image):
  # Display image with bounding rectangles
  # and title in a window. The window
  # automatically fits to the image size.
  cv2.imshow('Facial Prediction', image)

  while (True):
    # Displays the window infinitely
    key = cv2.waitKey(0)

    # Shuts down the display window and terminates
    # the Python process when a specific key is
    # pressed on the window.
    # 27 is the esc key
    # 113 is the letter 'q'
    if key == 27 or key == 113:
        break
  cv2.destroyAllWindows()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值