avatar

python调用opencv打开摄像头
1
2
3
4
5
6
7
8
9
10
11
12
13
# -*- coding: UTF-8 -*-
import cv2
cap = cv2.VideoCapture(0)#摄像头设备编号
#逐帧视频播放
while(1):
ret, frame = cap.read()#获得一帧
cv2.imshow("capture", frame)#shwo帧
if cv2.waitKey(1) & 0xFF == ord('q'):
#检测到键盘输入q时跳出循环并释放对象
break
#释放
cap.release()
cv2.destroyAllWindows()