At the moment I am capturing RGB output from the camera into a numpy array and then getting a grayscale image by performing a dot-product of the RGB matrix with an RGB to grayscale conversion. Something like:

Code: Select all

```
def rgb2grey(rgb):
return np.dot(rgb[...,:3], [0.1140, 0.5870, 0.2989]).astype(int)
```

I want my output to be a 2D matrix so that I work it forward more easily. E.g. for a 1280 x 480 image I would like a 1280 x 480 matrix where each element is between 0 and 255.

I have tried to achieve this in two separate ways.

First outputting the Y data from the YUV data into an array of the same resolution:

Code: Select all

```
import time
import picamera
import picamera.array
import numpy as np
with picamera.PiCamera() as camera:
camera.resolution = (100, 100)
time.sleep(2)
y_data = np.empty((112, 128), dtype=np.uint8)
try:
camera.capture(y_data, 'yuv')
except IOError:
pass
y_data = y_data[:100, :100]
# y_data now contains the Y-plane only
```

Secondly I tried to use the PiYUVArray method.

Code: Select all

```
import time
import picamera
import picamera.array
with picamera.PiCamera() as camera:
with picamera.array.PiYUVArray(camera) as stream:
camera.resolution = (1280, 720)
camera.start_preview()
time.sleep(2)
camera.capture(stream, 'yuv')
print(stream.array.shape)
```