import cv2
video = cv2.VideoCapture(0)
while True:
ret, frame = video.read()
print(ret)
#image = cv2.resize(frame, (416, 416))
#image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
#cv2.imshow("results", image)
cv2.imshow("results", frame)
cv2.waitKey(5)
这里首先把video,选择0作为视频输入,再读取video,这里返回第一个参数是是否有采集到图像为布偶类型,第二个是图像。接着输出图像,并每张图像延迟5ms
如果不注释则会把图像尺寸修改416*416,并将bgr该为rgb适合作为pytorch或者tensorflow输入,具体效果就是拍阿凡达了