如下所示:
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
|
#coding:utf-8 import cv2 import sys from PIL import Image def CatchUsbVideo(window_name, camera_idx): cv2.namedWindow(window_name) # 捕捉摄像头 cap = cv2.VideoCapture(camera_idx) while cap.isOpened(): ok, frame = cap.read() # 读取一帧数据 if not ok: break # 显示图像 cv2.imshow(window_name, frame) c = cv2.waitKey( 10 ) if c & 0xFF = = ord ( 'q' ): break # 释放摄像头并销毁所有窗口 cap.release() cv2.destroyAllWindows() if __name__ = = '__main__' : CatchUsbVideo( "FaceRect" , 0 ) |
以上这篇python使用opencv驱动摄像头的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/Jailman/article/details/78428180