我无法理解以下代码片段-
if cv2.waitKey(0) & 0xFF == ord('q'):
break
在这段代码中——
1 import numpy as np
2 import cv2
3
4 cap = cv2.VideoCapture(0)
5
6 while(True):
7 # Capture frame-by-frame
8 ret, frame = cap.read()
9
10 # Our operations on the frame come here
11 gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
12
13 # Display the resulting frame
14 cv2.imshow('frame',gray)
15 if cv2.waitKey(1) & 0xFF == ord('q'):
16 break
17
18 # When everything done, release the capture
19 cap.release()
20 cv2.destroyAllWindows()
ord('q') 和 0xFF 是什么意思?这里是如何使用的?
最佳答案
ord('q')
返回 q cv2.waitkey(1)
返回与按下的键对应的 32 位整数 & 0xFF
是一个位掩码,它将左 24 位设置为零,因为 ord()
返回一个介于 0 和 255 之间的值,因为您的键盘只有有限的字符集 关于python - ord ('q' ) 和 0xFF 的用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53357877/