0

Using the PiCamera Advanced Recipies in the link I am trying to capture the image to a numpy array. My code basic lines of code are.

final_image = np.empty((height , width , 3), dtype=np.uint8)
bright_imag_calc = cv2.cvtColor(final_image, cv2.COLOR_BGR2RGB)
bright_imag_calc1 = Image.fromarray(bright_imag_calc)

But I am getting the following error:

/home/pi/tflite1/tflite1-env/lib/python3.7/site-packages/picamera/encoders.py:544: PiCameraResolutionRounded: frame size rounded up from 300x300 to 320x304
  width, height, fwidth, fheight)))
Traceback (most recent call last):
  File "del_now.py", line 199, in <module>
    camera.capture(final_image, "bgr")
  File "/home/pi/tflite1/tflite1-env/lib/python3.7/site-packages/picamera/camera.py", line 1421, in capture
    if not encoder.wait(self.CAPTURE_TIMEOUT):
  File "/home/pi/tflite1/tflite1-env/lib/python3.7/site-packages/picamera/encoders.py", line 398, in wait
    raise self.exception
  File "/home/pi/tflite1/tflite1-env/lib/python3.7/site-packages/picamera/encoders.py", line 267, in _callback
    stop = self._callback_write(buf)
  File "/home/pi/tflite1/tflite1-env/lib/python3.7/site-packages/picamera/encoders.py", line 1019, in _callback_write
    super(PiOneImageEncoder, self)._callback_write(buf, key)
  File "/home/pi/tflite1/tflite1-env/lib/python3.7/site-packages/picamera/encoders.py", line 1160, in _callback_write
    super(PiRawImageMixin, self)._callback_write(buf, key)
  File "/home/pi/tflite1/tflite1-env/lib/python3.7/site-packages/picamera/encoders.py", line 580, in _callback_write
    return super(PiRawMixin, self)._callback_write(buf, key)
  File "/home/pi/tflite1/tflite1-env/lib/python3.7/site-packages/picamera/encoders.py", line 309, in _callback_write
    "output %r" % (buf.length, output))
picamera.exc.PiCameraIOError: Failed to write 291840 bytes from buffer to output <picamera.streams.BufferIO object at 0x62f70c60>

2 Answers 2

2

You have to ensure that the horizontal resolution is rounded up to the nearest multiple of 32 while the vertical resolution has to be a multiple of 16. This works for the Raspberry Pi HQ camera:

camera = PiCamera()
camera.resolution = (4032, 3040)  # instead of (4056, 3040)
camera.framerate = 24
camera.start_preview()

img = np.empty(
  (camera.resolution[1] * camera.resolution[0] * 3, ),
  dtype=np.uint8)

camera.capture(img, 'bgr')
img = img.reshape((camera.resolution[1], camera.resolution[0], 3))
0

If you share a bit more of your code, that would help. But from the error message, I will assume you have a mismatch in resolution size and your buffer size (numpy array size). For the capture to be able to append to your buffer, it must be within the size limits of the image resolution.

Example:

camera = picamera.PiCamera()
camera.resolution = (240,240)

final_image = np.empty((240 , 240 , 3), dtype=np.uint8)

camera.capture(final_image) # size of output must be within set or default resolution

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.