python matplotlib打开相机

python matplotlib打开相机,第1张

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

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()

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/570093.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-09
下一篇 2022-04-09

发表评论

登录后才能评论

评论列表(0条)

保存