打开摄像头
import cv2
capture = cv2.VideoCapture(0)
while True:
ret, frame = capture.read()
frame = cv2.flip(frame,1) #镜像操作
cv2.imshow("video", frame)
key = cv2.waitKey(50)
#print(key)
if key == ord('q'): #判断是哪一个键按下
break
cv2.destroyAllWindows()
- 因为我们是面对摄像头的,所以通过flip对摄像头获得的内容做了左右镜像
- 通过waitKey这个函数进行获取按下的键(以毫秒为单位,这里就是每50毫秒获取一次),当按下q这个键时,关闭视频