key = cv2.waitKey(30) & 0xff
waitKey(30) 中的数字代表等待按键输入之前的无效时间,单位为毫秒,这里没有设置案件
cv2.waitKey(1) 与 0xFF(1111 1111)相与是因为cv2.waitKey(1) 的返回值不止8位,但是只有后8位实际有效,为避免产干扰,通过 ‘与’ 操作将其余位置0
import cv2
cameraCapture = cv2.VideoCapture(0)
cv2.namedWindow('Test camera')
success, frame = cameraCapture.read()
while success:
if cv2.waitKey(1) == 27:
break
cv2.imshow('Test camera', frame)
success, frame = cameraCapture.read()
cameraCapture.release()
VideoCapture(0) 开发默认摄像头,如果你有多个摄像头可以试试除0之外的其他参数。
nameWindow(‘Test camera’) 其实是创建一个名字叫”Test camera“的窗口。
waitKey(1) 读取用户键盘输入参数1,是等待时间单位毫秒milliseconds。
imshow(‘Test camera’, frame) 将frame中的数据,显示到名字为”Test camera“ 的窗口上。
success, img = camera.read() # 返回boolsuccess
opencv-python边缘填充函数cv2.copyMakeBorder使用及效果展示
https://blog.csdn.net/weixin_35732969/article/details/83714492
CV2,按目录保存,请看FACEDetect
cv2.imwrite('./isRLC' + '/' + 'RLC'+ str(cont) + '.jpg', face)
opencv读取图像格式是bgr,需要转换为rgb格式;
cv2.cvtColor(inputs, cv2.COLOR_BGR2RGB).astype(np.float32)