def flush(self):
super(PiBayerArray, self).flush()
self._demo = None
data = self.getvalue()[-6404096:]
if data[:4] != b'BRCM':
raise PiCameraValueError('Unable to locate Bayer data at end of buffer')
# Strip header
data = data[32768:]
# Reshape into 2D pixel values
data = np.frombuffer(data, dtype=np.uint8).\
reshape((1952, 3264))[:1944, :3240]
# Unpack 10-bit values; every 5 bytes contains the high 8-bits of 4
# values followed by the low 2-bits of 4 values packed into the fifth
# byte
data = data.astype(np.uint16) << 2
for byte in range(4):
data[:, byte::5] |= ((data[:, 4::5] >> ((4 - byte) * 2)) & 3)
data = np.delete(data, np.s_[4::5], 1)
# XXX Should test camera's vflip and hflip settings here and adjust
self.array = np.zeros(data.shape + (3,), dtype=data.dtype)
self.array[1::2, 0::2, 0] = data[1::2, 0::2] # Red
self.array[0::2, 0::2, 1] = data[0::2, 0::2] # Green
self.array[1::2, 1::2, 1] = data[1::2, 1::2] # Green
self.array[0::2, 1::2, 2] = data[0::2, 1::2] # Blue
评论列表
文章目录