使用 Opencv 包从设备捕获图像在备用调用中提供绿色图像

问题描述

我正在尝试使用连接到机器的设备捕获图像。它交替捕获,一次很好,另一次捕获绿色背景图像,并且交替正确发生。

我通过 API 调用不断调用函数

这是我的代码

Now = datetime.Now()
timestamp = datetime.timestamp(Now)
filename = f'{timestamp}.jpg'
try:
    cap = cv2.VideoCapture(0)
    cap.set(3,1920)
    cap.set(4,1080)
    if cap.isOpened():
        _,frame = cap.read()
        cap.release()
        if _ and frame is not None:
            cv2.imwrite(filename,frame)
            cap.release()

except RuntimeError:
    print("Error")
with open(filename,"rb") as image_file:
    encoded = base64.b64encode(image_file.read())
#os.remove(filename)
return encoded.decode("utf-8")`

一个问题是调用这个函数来截屏非常耗时,单击大约需要 3-4 秒。请帮助优化调用方法

此设备捕获其他笔记本电脑或连接到它的任何 dvi 输入设备的屏幕作为输入,它可以在其他机器上作为 USB 输出,使用相机应用程序可以看到真实图像。 设备:https://www.epiphan.com/products/avio-hd/

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)