PiCamera 将图像存储在 RGBArray 中
PiCamera storing an image in an RGBArray
您好,我正在尝试使用 PiCamera 模块在录制过程中捕捉低分辨率图像。但是它在 camera.capture 行崩溃并给出以下错误
File "/usr/lib/python3/dist-packages/picamera/array.py", line 238,
in flush
self.array = bytes_to_rgb(self.getvalue(), self.size or self.camera.resolution) File
"/usr/lib/python3/dist-packages/picamera/array.py", line 127, in
bytes_to_rgb
'Incorrect buffer length for resolution %dx%d' % (width, height)) picamera.exc.PiCameraValueError: Incorrect buffer length for
resolution 1280x726
到目前为止,这是我的代码:
from picamera import PiCamera
from picamera.array import PiRGBArray
import numpy as np
import time
camera = PiCamera()
resolution = (128,80)
camera.resolution = (1280, 726)
camera.start_preview()
time.sleep(2)
RGBArray = PiRGBArray(camera)
camera.capture(RGBArray, format='rgb',splitter_port=0,resize=resolution)
print("i crash on the line above")
如果我将相机分辨率设置为 camera.resolution = (128,80) 并从 camera.capture() 中删除 "resize" 参数它工作正常但我想记录更高的分辨率。我似乎无法在任何地方找到解决方案。
已解决 PiRGBArray(camera) 需要更改为 PiRGBArray(camera,size=128,80)
PiRGBArray(camera) 需要改为 PiRGBArray(camera,size=128,80)
您好,我正在尝试使用 PiCamera 模块在录制过程中捕捉低分辨率图像。但是它在 camera.capture 行崩溃并给出以下错误
File "/usr/lib/python3/dist-packages/picamera/array.py", line 238, in flush self.array = bytes_to_rgb(self.getvalue(), self.size or self.camera.resolution) File "/usr/lib/python3/dist-packages/picamera/array.py", line 127, in bytes_to_rgb 'Incorrect buffer length for resolution %dx%d' % (width, height)) picamera.exc.PiCameraValueError: Incorrect buffer length for resolution 1280x726
到目前为止,这是我的代码:
from picamera import PiCamera
from picamera.array import PiRGBArray
import numpy as np
import time
camera = PiCamera()
resolution = (128,80)
camera.resolution = (1280, 726)
camera.start_preview()
time.sleep(2)
RGBArray = PiRGBArray(camera)
camera.capture(RGBArray, format='rgb',splitter_port=0,resize=resolution)
print("i crash on the line above")
如果我将相机分辨率设置为 camera.resolution = (128,80) 并从 camera.capture() 中删除 "resize" 参数它工作正常但我想记录更高的分辨率。我似乎无法在任何地方找到解决方案。
已解决 PiRGBArray(camera) 需要更改为 PiRGBArray(camera,size=128,80)
PiRGBArray(camera) 需要改为 PiRGBArray(camera,size=128,80)