'numpy.ndarray' object is not callable?

902 views Asked by At

Running this script:

import time
import picamera
import picamera.array
import numpy as np

with picamera.PiCamera() as camera:
    with picamera.array.PiBayerArray(camera) as stream:
        camera.capture(stream, 'jpeg', bayer=True)
        # Demosaic data and write to output (just use stream.array if you
        # want to skip the demosaic step)
        output = (stream.array() >> 2).astype(np.uint8)
        with open('image.jpg', 'wb') as f:
            output.tofile(f)

Gives the following error:

Traceback (most recent call last):
  File "numpy_simple.py", line 11, in <module>
    output = (stream.array() >> 2).astype(np.uint8)
TypeError: 'numpy.ndarray' object is not callable

While running:

output = (stream.demosaic() >> 2).astype(np.uint8)
        with open('image.data', 'wb') as f:
            output.tofile(f)

Does not give any error.

I'm a bit confused.

1

There are 1 answers

0
Brad Solomon On BEST ANSWER

array is an attribute, not a method. You don't need to call it.

Use stream.array, not stream.array().

Source: PiArrayOutput, which is the base class for PiBayerArray.

Conversely, .demosaic() is an instance method, which is why you need to call it to get its return value.