I want to build an animal counter based on pi zero w, pi cam, python and opencv.

I read some tutorials (especially from https://www.pyimagesearch.com) how to setup all that stuff and in principle it works.

(e.g. the test_video.py from https://www.pyimagesearch.com/2016/08/29/common-errors-using-the-raspberry-pi-camera-module/ is running)

For the part of counting i found a partially (and thats the problem) working project on github: https://github.com/narayananramu/opencv-people-counter.
This contains of two different scripts. The counter.py which counts people on a recorded video file works great.

I get this error when I run the raspberry.py on a live feed from raspi cam:

pi@raspizero:~/opencv-people-counter $ python raspberry.py
[INFO] starting background model...
Traceback (most recent call last):
  File "raspberry.py", line 27, in <module>
    for f 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
  File "/usr/lib/python2.7/dist-packages/picamera/encoders.py", line 419, in stop
  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
  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

What am i doing wrong?

(I didn't touch the code from github)

  • Does stackoverflow.com/questions/40065328/… help – Dirk Sep 7 '18 at 16:04
  • I don't have opencv installed, but testing with PiCamera and capture_continuous I find that this error happens when rawCapture.truncate(0) is NOT called. Maybe post the exact source you are running and how you are calling the program. – HeatfanJohn Sep 9 '18 at 16:26

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.