1

I have a camera connected to my computer that produces 16bit grayscale images. I am importing them with the camera manufacturer's proprietary software and then insert them into a numpy array.

imObj = fc2.Image()
frame = np.array(c.retrieve_buffer(imObj)) 

This casts the array as a uint8. If I try to add the dtype parameter to the array declaration:

frame = np.array(c.retrieve_buffer(imObj), dtype = np.uint16)

I get the following output:

typeError: __array__() takes no arguments (1 given) 

Anybody know what is causing this?

EDIT: I am using pyflycapture2. I don't know how to call or set the Image class attributes.

DanGoodrick
  • 2,818
  • 6
  • 28
  • 52

1 Answers1

3

It seems you are possibly using pyflycapture2, which does not seem to have an __array__ hook capable of recasting the data.

Instead, its __array__ hook chooses the dtype appropriate to the image. That is, it returns a uint8 based array if the underlying format is PIXEL_FORMAT_MONO8 and a uint16 based array when the format is PIXEL_FORMAT_MONO16.

It might be worth checking that the image format (c.retrieve_buffer(imObj).img.format) is what you think it is?

donkopotamus
  • 22,114
  • 2
  • 48
  • 60
  • In other words, `np.array` is trying to call `c.retrieve_buffer(imObj).__array__(dtype)`. If that object were an `ndarray` it would work, since `A.__array__(np.uint16)` works for an ordinary array. – hpaulj Mar 15 '16 at 22:42