TextureOutput

class NatML.Devices.Outputs.TextureOutput : CameraOutput

The TextureOutput streams CameraImage instances into a Texture2D.

The TextureOutput uses the PixelBufferOutput to convert images to RGBA888 before uploading to the GPU.

Creating the Output

/// <summary>
/// Create a texture output.
/// </summary>
TextureOutput ();

The texture output is trivially constructed.

Specifying the Orientation

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

The texture output supports specifying the desired output orientation of the converted texture.

This 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="image">Camera image.</param>
void Update (CameraImage image);

The output will convert the CameraImage into an RGBA8888 pixel buffer and upload it to the GPU. 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>
/// Texture 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 Texture

/// <summary>
/// Texture containing the latest camera image.
/// </summary>
Texture2D texture { get; }

When the output has been updated with a CameraImage, the texture will contain the converted pixel data in the correct pixel format and orientation, available in both system and GPU memory.

The format of the texture is always TextureFormat.RGBA32.

The texture data is accessible both on the GPU and on the CPU using the Texture2D data access methods.

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