mipicsi – Support for MIPI CSI-2 camera interfaces
Captures image frames from camera sensors attached to a MIPI CSI-2 receiver, such as the one in the ESP32-P4. The camera sensor itself is configured separately (typically over I2C); this module only receives the image data the sensor transmits.
By default, captured frames are in the same format the sensor sends,
described by PixelFormat. For example, an RGB565 sensor gives RGB565
frames. RAW formats contain Bayer data, with the color order given by
BayerOrder.
mipicsi.Camera may be able to convert the format as it receives a
frame. To do this, pass the desired output_format when creating the
Camera. An exception will be raised if it cannot be done in hardware
without another buffer.
Available on these boards
- class mipicsi.BayerOrder
The Bayer element order of a sensor’s RAW output, in the sequence a 2x2 pixel block transmits (top-left first, reading order)
- BGGR: BayerOrder
The first element is Blue, then Green. The next row starts with Green, then Red
- GBRG: BayerOrder
The first element is Green, then Blue. The next row starts with Red, then Green
- GRBG: BayerOrder
The first element is Green, then Red. The next row starts with Blue, then Green
- RGGB: BayerOrder
The first element is Red, then Green. The next row starts with Green, then Blue
- class mipicsi.Camera(sensor: circuitpython_typing.CameraSensor, *, output_format: PixelFormat | None = None)
Receive frames from a camera sensor on a MIPI CSI-2 interface
The camera sensor is configured separately (typically over I2C) to transmit frames. Use the dedicated MIPI CSI-2 receiver pins.
The sensor object must implement
circuitpython_typing.CameraSensor, which has these properties:widthandheight: the image size in pixelspixel_format: thePixelFormatthe sensor transmitslane_bit_rate_mbps: the bit rate of each data lanedata_lanes: the number of data lanes used, 1 or 2bayer_order: theBayerOrderof RAW data
and these methods:
_start(): start transmitting frames_stop(): stop transmitting frames
_start()and_stop()are internal. The camera calls them when streaming starts and stops; user code should not call them.The sensor’s properties are validated when the Camera is created and are validated again when
videocore.VideoBuffer.play()is called. The sensor may change its configuration while it is not playing.The sensor sets the image size and format, and the receiver, such as
videocore.VideoBuffer, is set up to match when playing starts. The sensor’s mode should not change between_start()and_stop()calls. (The sensor class should raise an exception when it is attempted.) To use a new mode, stop playing, change the sensor, and play again.Camera objects implement the internal videosource protocol, so a
videocore.VideoBuffercan stream their frames into a framebuffer.Configure and initialize the MIPI CSI-2 camera receiver
sensor = sc2336.SC2336(i2c) camera = mipicsi.Camera(sensor)
- Parameters:
sensor – A camera sensor to receive frames from. The receiver is configured to match the sensor’s current mode. The sensor starts streaming when a
videocore.VideoBufferplays the camera.output_format – The format of the captured frames. Defaults to the sensor’s
pixel_format. When different, frames are converted as they are captured, for example from RAW10 toPixelFormat.RGB565. Not all conversions are supported.
- __exit__() None
Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.
- class mipicsi.PixelFormat
Format of the data in the captured frames. The camera sensor must be configured (typically over I2C) to transmit the corresponding MIPI CSI-2 data type.
- RGB565: PixelFormat
A 16-bit format with 5 bits of Red, 6 bits of Green, and 5 bits of Blue (MIPI data type
RGB565)
- RGB888: PixelFormat
A 24-bit format with 8 bits of Red, Green and Blue (MIPI data type
RGB888)
- GRAYSCALE: PixelFormat
An 8-bit format with 8 bits of luminance (MIPI data types for 8-bit grayscale)
- YUV422: PixelFormat
A 16-bit YUV 4:2:2 format, in the byte order the sensor transmits (MIPI data type
YUV422 8-bit)
- RAW8: PixelFormat
8 bits per pixel of raw Bayer data (MIPI data type
RAW8)
- RAW10: PixelFormat
10 bits per pixel of raw Bayer data (MIPI data type
RAW10)
- RAW12: PixelFormat
12 bits per pixel of raw Bayer data (MIPI data type
RAW12)