1

I'm getting an error the second time I run camera.capture(output,'yuv'), what am I doing wrong?

my code:

from time import sleep
from picamera import PiCamera
from picamera.array import PiYUVArray
import numpy
w=64
h=48
camera=PiCamera()
output=PiYUVArray(camera)
camera.resolution=(w,h)
camera.start_preview()
sleep(2)
while True:
    print('output')
    camera.capture(output,'yuv')
    #some elaboration here
    sleep(10)

output:

output
output
Traceback (most recent call last):
  File "test1.py", line 14, in <module>
    camera.capture(output,'yuv')
  File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 1421, in capture
    if not encoder.wait(self.CAPTURE_TIMEOUT):
  File "/usr/lib/python2.7/dist-packages/picamera/encoders.py", line 395, in wait
    self.stop()
  File "/usr/lib/python2.7/dist-packages/picamera/encoders.py", line 419, in stop
    self._close_output()
  File "/usr/lib/python2.7/dist-packages/picamera/encoders.py", line 349, in _close_output
    mo.close_stream(output, opened)
  File "/usr/lib/python2.7/dist-packages/picamera/mmalobj.py", line 371, in close_stream
    stream.flush()
  File "/usr/lib/python2.7/dist-packages/picamera/array.py", line 296, in flush
    self.array = bytes_to_yuv(self.getvalue(), self.size or self.camera.resolution)
  File "/usr/lib/python2.7/dist-packages/picamera/array.py", line 93, in bytes_to_yuv
    'Incorrect buffer length for resolution %dx%d' % (width, height))
picamera.exc.PiCameraValueError: Incorrect buffer length for resolution 64x48
6
  • That doesn't look like it's the full error (the actual error message is missing)
    – Dirk
    Jun 30, 2019 at 19:20
  • sorry @Dirk you are right, I edited the post
    – Miky
    Jun 30, 2019 at 20:04
  • Does stackoverflow.com/questions/40065328/… help?
    – Dirk
    Jun 30, 2019 at 22:56
  • so if understood I should clear the output variable after my elaboration?
    – Miky
    Jul 1, 2019 at 9:32
  • Yes, that's how I understand it should work.
    – Dirk
    Jul 1, 2019 at 15:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.