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

Closed
lwd8cmd opened this Issue Jul 5, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@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)
        camera.wait_recording(5)
        camera.stop_recording()

This gives

Traceback (most recent call last):
  File "test2.py", line 10, in <module>
    camera.stop_recording()
  File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 1056, in stop_recording
    encoder.close()
  File "/usr/lib/python2.7/dist-packages/picamera/encoders.py", line 731, in close
    self.stop()
  File "/usr/lib/python2.7/dist-packages/picamera/encoders.py", line 942, in stop
    self._close_output(PiVideoFrameType.motion_data)
  File "/usr/lib/python2.7/dist-packages/picamera/encoders.py", line 633, in _close_output
    output.flush()
  File "/usr/lib/python2.7/dist-packages/picamera/array.py", 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 self.camera.resolution (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.

@waveform80

This comment has been minimized.

Owner

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