forked from jiejie1993/CNN_face_recognition
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatch_usb_vedio.py
More file actions
34 lines (26 loc) · 969 Bytes
/
catch_usb_vedio.py
File metadata and controls
34 lines (26 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 -*-
#-*- coding: utf-8 -*-
import cv2
import sys
from PIL import Image
def CatchUsbVideo(window_name, camera_idx):
cv2.namedWindow(window_name)
#视频来源,可以来自一段已存好的视频,也可以直接来自USB摄像头
cap = cv2.VideoCapture(0)
while cap.isOpened():
ok, frame = cap.read() #读取一帧数据
if not ok:
break
#显示图像并等待10毫秒按键输入,输入‘q’退出程序
cv2.imshow(window_name, frame)
c = cv2.waitKey(10)
if c & 0xFF == ord('q'):
break
#释放摄像头并销毁所有窗口
cap.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
if len(sys.argv) != 2:
print("Usage:%s camera_id\r\n" % (sys.argv[0]))
else:
CatchUsbVideo("截取视频流", int(sys.argv[1]))