import cv2
# 开启电脑摄像头读取
cap = cv2.VideoCapture(0)
# 视频帧率
fps = int(cap.get(cv2.CAP_PROP_FPS))
# 视频的宽
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
# 视频的高
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
print(width)
print(height)
# cap.read()的类型是元组,第一个值为bool类型,表示是否存在当前帧,第二个值为三维列表,表示当前帧的信息
ret, frame = cap.read()
while(ret):
# 显示当前帧
cv2.imshow("capture", frame)
# 等待键盘输入
key = cv2.waitKey(fps)
# 输入空格
if key == 32:
break
# 没有输入则读取下一帧
ret, frame = cap.read()
# 释放画面
cap.release()
cv2.destroyAllWindows()
标签:视频,CAP,int,frame,cap,cv2,opencv,操作
From: https://www.cnblogs.com/alexmisko/p/17062540.html