def test_overlay_array1(camera, mode): resolution, framerate = mode # Draw a cross overlay w, h = resolution w = bcm_host.VCOS_ALIGN_UP(w, 32) h = bcm_host.VCOS_ALIGN_UP(h, 16) a = np.zeros((h, w, 3), dtype=np.uint8) a[resolution[1] // 2, :, :] = 0xff a[:, resolution[0] // 2, :] = 0xff overlay = camera.add_overlay(a, resolution, alpha=128) assert len(camera.overlays) == 1 assert camera.overlays[0].alpha == 128 camera.remove_overlay(overlay) assert not camera.overlays
def __init__( self, cam: 'Camera', contiguous: bool = True, ): super().__init__() self._cam = cam self._contiguous = contiguous # Initialize reshaping parameters. # In raw input mode, the sensor sends us data with resolution # rounded up to nearest multiples of 16 or 32. Find this input, # which will be used for the initial reshaping of the data. width, height = cam.resolution fwidth = bcm_host.VCOS_ALIGN_UP(width, 16) fheight = bcm_host.VCOS_ALIGN_UP(height, 16) self._in_shape = (fheight, fwidth, 3) # Once reshaped, any extraneous rows or columns introduced # by the rounding up of the frame shape will need to be # sliced off. Additionally, any unwanted channels will # need to be removed, so we'll combine the two cropping # procedures into one. channels = cam.channels if channels in ('r', 'g', 'b'): ch_index = 'rgb'.find(channels) self._out_shape = (height, width) else: ch_index = slice(None) self._out_shape = (height, width, 3) if self._in_shape == self._out_shape: self._out_slice = (slice(None), slice(None), ch_index) else: self._out_slice = (slice(height), slice(width), ch_index) self._n_bytes_in = np.prod(self._in_shape) self._n_bytes_out = np.prod(self._out_shape)