0

我将 Python 中的 Picamera 库与新的 HQ 相机结合使用,我发现如果我想使用图像端口并循环拍照,我必须在循环中一次又一次地设置分辨率。这是正常行为吗?必须一遍又一遍地设置它似乎很愚蠢(我检查了设置分辨率的调用,它不是一个非常快的调用)。

这是我正在使用的代码:

from picamera.array import PiRGBArray
from picamera.camera import PiCamera

with PiCamera() as camera:
    with PiRGBArray(camera) as output:
        #camera.resolution = (1280, 720) #THIS DOES NOT WORK
        while not self._stop_camera_stream:
            camera.resolution = (1280, 720) #BUT THIS DOES
            camera.capture(output, 'rgb')
            print('Captured %dx%d image' % (output.array.shape[1], output.array.shape[0]))
            #The line beginning here are for a preview inside a PyQt5 Window
            image = output.array
            h, w, ch = image.shape
            bytesPerLine = ch*w
            convertedToQtFormat = QImage(image, w, h, bytesPerLine, QImage.Format_RGB888)
            p = convertedToQtFormat.scaled(640,480,Qt.KeepAspectRatio)
            self.changePixmap.emit(p)
            output.truncate(0)
4

0 回答 0