1

I want to get photo from raspberry pi camera in python and i tried this code and it's works for me:

for filename in camera.capture_continuous('img.jpg'):
    test_img = cv2.imread('img.jpg')

But this code doesn't

rawCapture = PiRGBArray(camera, size=RESOLUTION)
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
    test_img = frame.array.copy()

I want second code to work.

This is the error i get:

Traceback (most recent call last):
  File "full.py", line 231, in <module>
    for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
  File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 1702, in capture_continuous
    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 238, in flush
    self.array = bytes_to_rgb(self.getvalue(), self.size or self.camera.resolution)
  File "/usr/lib/python2.7/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 640x480
Exception in thread Thread-1 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
  File "/usr/local/lib/python2.7/dist-packages/telepot/__init__.py", line 448, in run
  File "/usr/local/lib/python2.7/dist-packages/telepot/__init__.py", line 367, in k
  File "/usr/lib/python2.7/threading.py", line 168, in acquire
<type 'exceptions.TypeError'>: 'NoneType' object is not callable
  • The first exception in that traceback suggests that the buffer allocated by PiRGBArray is the wrong size, which means either it's a different resolution to the camera's, or it hasn't been scaled to fit the 32x16 block size of the camera – Dave Jones Dec 21 '17 at 10:34
  • RESOLUTION is set to (640, 480) Will it be problem? – Arash Kadkhodaei Dec 22 '17 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.