CameraImage

readonly struct NatML.Devices.CameraImage

Camera images contain pixel buffers along with EXIF metadata captured by CameraDevice instances.

Inspecting the Image Size

Camera images provide information about their size:

Image Width

/// <summary>
/// Image width.
/// </summary>
int width { get; }

The image width.

Image Height

/// <summary>
/// Image height.
/// </summary>
int height { get; }

The image height.

Inspecting the Image Timestamp

/// <summary>
/// Image timestamp in nanoseconds.
/// </summary>
long timestamp { get; }

The image timestamp in nanoseconds.

For camera images generated by CameraDevice instances, the timestamp is based on the system media clock.

Inspecting the Image Format

/// <summary>
/// Image format.
/// </summary>
Format format { get; }

The image format. Only a fixed set of image formats are supported:

Image Format

/// <summary>
/// Image buffer format.
/// </summary>
enum Format {
    /// <summary>
    /// Unknown image format.
    /// </summary>
    Unknown = 0,
    /// <summary>
    /// Generic YUV 420 planar format.
    /// </summary>
    YCbCr420 = 1,
    /// <summary>
    /// RGBA8888.
    /// </summary>
    RGBA8888 = 2,
    /// <summary>
    /// BGRA8888.
    /// </summary>
    BGRA8888 = 3,    
}

Checking for Mirroring

/// <summary>
/// Whether the image is vertically mirrored.
/// </summary>
bool verticallyMirrored { get; }

Some camera devices generate images that are vertically mirrored, depending on their facing. This property reports whether images should be mirrored to correct this transformation.

Accessing the Pixel Buffer

The camera image contains either an interleaved or planar pixel buffer, depending on the image format.

Interleaved Images

/// <summary>
/// Image pixel buffer.
/// </summary>
NativeArray<byte> pixelBuffer { get; }

For interleaved images, the pixelBuffer contains a contiguous pixel buffer with the pixel data.

Pixel buffers may contain padding bytes, defined by the image rowStride.

For planar images, the pixelBuffer is uninitialized.

Planar Images

/// <summary>
/// Image plane for planar formats.
/// </summary>
Plane[] planes { get; }

For planar images, the planes contains an array of CameraImage.Plane instances referring to each plane within the image.

For interleaved images, the planes property is null.

Inspecting the Camera Device

/// <summary>
/// Camera device that this buffer was generated from.
/// </summary>
IMediaDevice<CameraImage> device { get; }

The device identifies the camera device that the image was generated from.

Inspecting EXIF Metadata

Camera images can provide their EXIF metadata:

All metadata fields are nullable types.

Exposure Bias

/// <summary>
/// Exposure bias value in EV.
/// </summary>
float? exposureBias { get; }

The exposure bias value in EV.

Exposure Duration

 /// <summary>
 /// Image exposure duration in seconds.
 /// </summary>
 float? exposureDuration { get; }

The exposure duration in seconds.

Sensor Sensitivity (ISO)

/// <summary>
/// Sensor sensitivity ISO value.
/// </summary>
float? ISO { get; }

The sensor sensitivity ISO value.

Focal Length

/// <summary>
/// Camera focal length in millimeters.
/// </summary>
float? focalLength { get; }

The camera focal length in millimeters.

F-number

/// <summary>
/// Image aperture f-number.
/// </summary>
float? fNumber { get; }

The image aperture f-number.

Brightness

/// <summary>
/// Ambient brightness.
/// </summary>
float? brightness { get; }

The ambient brightness.

Intrinsic Matrix

/// <summary>
/// Camera intrinsics as a flattened row-major 3x3 matrix.
/// </summary>
float[] intrinsics { get; }

The camera intrinsic matrix in row-major layout.

Last updated