MatOutput

class NatML.Devices.Outputs.MatOutput : CameraOutput

The MatOutput converts CameraImage instances into an OpenCV Mat.

This class is part of the NatDevice-OpenCV integration library.

Creating the Output

/// <summary>
/// Create a Mat output.
/// </summary>
MatOutput ();

The matrix output is trivially constructed.

Specifying the Orientation

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

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

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.

Specifying the Color Format

/// <summary>
/// Get or set the conversion format.
/// </summary>
int format { get; set; }

The matrix output supports specifying a color conversion to perform when converting incoming CameraImage instances. This is useful for implementing computer vision pipelines that operate on greyscale image data, or other non-RGBA formats.

The format MUST be one of the Imgproc.COLOR_RGBA2*** constants.

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 upload the CameraImage into a RenderTexture. 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;
    /// <summary>
    /// Conversion format.
    /// </summary>
    int format;
}

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

Accessing the Matrix

/// <summary>
/// OpenCV matrix containing the latest camera image.
/// </summary>
Mat matrix { get; }

When the output has been updated with a CameraImage, the matrix will contain the converted pixel data in the correct color format and 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