PixelBufferOutput

class NatML.Devices.Outputs.PixelBufferOutput : CameraOutput

The PixelBufferOutput converts CameraImage instances into RGBA8888 pixel buffers.

Creating the Output

/// <summary>
/// Create a pixel buffer output.
/// </summary>
PixelBufferOutput ();

The output is trivially constructed.

Specifying Orientation

/// <summary>
/// Get or set the pixel buffer orientation.
/// </summary>
ScreenOrientation orientation { get; set; }

The pixel buffer output supports specifying the desired output orientation of the converted pixel buffer.

This property is especially useful on mobile devices where camera images are always returned in the "natural orientation" of the camera device.

This property is only supported on Android and iOS.

Updating with New Images

/// <summary>
/// Update the output with a new camera image.
/// </summary>
/// <param name="cameraImage">Camera image.</param>
void Update (CameraImage cameraImage);

The output will convert the CameraImage into an RGBA8888 pixel buffer. The output handles all formats supported by the camera image. The output supports specifying options that are used when converting the image:

/// <summary>
/// Update the output with a new camera image.
/// </summary>
/// <param name="image">Camera image.</param>
/// <param name="options">Conversion options.</param>
void Update (CameraImage image, ConversionOptions options);

The provided options can be null, in which case reasonable defaults are used.

Conversion Options

/// <summary>
/// Pixel buffer conversion options.
/// </summary>
class ConversionOptions {
    /// <summary>
    /// Desired pixel buffer orientation.
    /// </summary>
    ScreenOrientation orientation;
    /// <summary>
    /// Whether to vertically mirror the pixel buffer.
    /// </summary>
    bool mirror;
}

The ConversionOptions expose some options that can be used when performing the conversion.

Accessing the Pixel Buffer

/// <summary>
/// Pixel buffer with latest camera image.
/// The pixel buffer is always laid out in RGBA8888 format.
/// </summary>
NativeArray<byte> pixelBuffer { get; }

When the output has been updated with a CameraImage, the pixelBuffer will contain the converted pixel data in the correct pixel format and orientation.

The pixel buffer always has an RGBA8888 pixel layout.

Inspecting the Pixel Buffer

The output exposes details about converted pixel buffers:

Pixel Buffer Width

/// <summary>
/// Pixel buffer width.
/// </summary>
int width { get; }

The pixel buffer output provides the width of the converted pixel buffer.

Note that the width of the converted pixel buffer depends on the requested orientation.

Pixel Buffer Height

/// <summary>
/// Pixel buffer height.
/// </summary>
int height { get; }

The pixel buffer output provides the height of the converted pixel buffer.

Note that the height of the converted pixel buffer depends on the requested orientation.

Disposing the Output

/// <summary>
/// Dispose the camera output and release resources.
/// </summary>
void Dispose ();

Refer to the Disposing the Output section of the CameraOutput class for more information.

Last updated