首页 > 解决方案 > 在 python 中使用 .read() 显示时如何更改 cv.VideoCapture(0) 帧大小?树莓派和 OpenCv

问题描述

我运行以下代码来扫描实时视频源中的二维码。但是,弹出的窗口很小,我必须拖动角落才能看到实时提要的全尺寸。如果我将 .set 3 和 4 更改为更大的值(但成比例),我会得到一个不正确的古怪图像。有没有办法在我运行代码时自动增加视频源窗口的大小,同时保持质量?我正在使用 Raspberry Pi 高质量相机。

    cap = cv.VideoCapture(0)
    cap.set(3,640)
    cap.set(4,480)

    timeout = time.time() + 8 # Number of seconds to scan for QR codes
    while True:
        sucess, img = cap.read()
        for barcode in decode(img):
            myData = barcode.data.decode('utf-8')
            print(myData)
        cv.imshow('Result',img)
        cv.waitKey(1)
        if time.time() > timeout:
            break
    cv.destroyAllWindows()

标签: cameraopencv-pythonraspberry-pi4

解决方案


推荐阅读