Raspberry Pi camera RAW images with Python

The PiCamera Python module acquires RAW Bayer masked data from the color Raspberry Pi camera module. Getting raw Bayer images from the camera into 2592 x 1944 pixels for the V1 camera, 3280 x 2464 for the V2 camera requires a program as simple as:

import picamera
import picamera.array

with picamera.PiCamera() as cam:
    with picamera.array.PiBayerArray(cam) as stream:
        cam.capture(stream, 'jpeg', bayer=True)
        img = stream.array

Python code for Raspberry Pi camera Bayer non-demasked image

It takes several seconds to load and process the first image. Acquiring an image series is much faster.

References: