Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arrays with resized camera feed #121

lwd8cmd opened this issue Jul 5, 2014 · 1 comment

arrays with resized camera feed #121

lwd8cmd opened this issue Jul 5, 2014 · 1 comment


Copy link

@lwd8cmd lwd8cmd commented Jul 5, 2014

Arrays (PiMotionArray, PiRGBArray,...) use camera.resolution to get width, height, but should use video stream resolution (if camera.start_recording has resize parameter set).

Example code:

import picamera
import picamera.array

with picamera.PiCamera() as camera:
    with picamera.array.PiMotionArray(camera) as output:
        camera.resolution = camera.MAX_RESOLUTION
        camera.framerate = 4
        camera.start_recording('foo.h264', resize=(1296, 972), motion_output=output)

This gives

Traceback (most recent call last):
  File "", line 10, in <module>
  File "/usr/lib/python2.7/dist-packages/picamera/", line 1056, in stop_recording
  File "/usr/lib/python2.7/dist-packages/picamera/", line 731, in close
  File "/usr/lib/python2.7/dist-packages/picamera/", line 942, in stop
  File "/usr/lib/python2.7/dist-packages/picamera/", line 633, in _close_output
  File "/usr/lib/python2.7/dist-packages/picamera/", line 509, in flush
    reshape((frames, rows, cols))
ValueError: total size of new array must be unchanged

PiMotionArray class fetch image width and height from (in this case camera.MAX_RESOLUTION), but actual stream might be resized (e.g. (1296, 972)).

As a workaround I defined DetectMotion and manually inserted resolution

class DetectMotion(picamera.array.PiMotionAnalysis):
    def __init__(self, camera):
        width, height = (1296, 972)
        self.cols = (width + 15) // 16 + 1
        self.rows = (height + 15) // 16

and it works correctly, but I guess these classes should get the right resolution automatically.

Copy link

@waveform80 waveform80 commented Jul 5, 2014

Ahh, I was wondering when this would come up. Unfortunately, while I can detect the resolution of the camera trivially in the array classes, I can't detect the value of the resize parameter easily. I guess the best solution for now is to allow the resolution to be specified in the array constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants