当前位置 : 主页 > 编程语言 > python >

python matplotlib打开相机

来源:互联网 收集:自由互联 发布时间:2022-06-15
如何通过按键保存图片呢??? import cv2 import matplotlib . pyplot as plt capture = cv2 . VideoCapture ( 0 ) fig = plt . figure () plt . ion () if capture is not None : while ( True ): # 获取一帧 ret , frame = capture . re


如何通过按键保存图片呢???

import cv2
import matplotlib.pyplot as plt

capture = cv2.VideoCapture(0)
fig = plt.figure()
plt.ion()

if capture is not None:
while (True):
# 获取一帧
ret, frame = capture.read()
if frame is not None:
# opencv
# cv2.imshow("camera", frame)
# cv2.waitKey(1)

# matplotlib
plt.imshow(frame)
plt.pause(0.1)
fig.clf()
else:
print("Fail to grab")
continue
else:
print("Fail to open camera")
plt.ioff()


网友评论