docs.unity3d.com
    Show / Hide Table of Contents

    Class CameraSensor

    A sensor that wraps a Camera object to generate visual observations for an agent.

    Inheritance
    Object
    CameraSensor
    Namespace: Unity.MLAgents.Sensors
    Syntax
    public class CameraSensor : object, ISensor, IBuiltInSensor, IDisposable

    Constructors

    CameraSensor(Camera, Int32, Int32, Boolean, String, SensorCompressionType, ObservationType)

    Creates and returns the camera sensor.

    Declaration
    public CameraSensor(Camera camera, int width, int height, bool grayscale, string name, SensorCompressionType compression, ObservationType observationType = default(ObservationType))
    Parameters
    Type Name Description
    Camera camera

    Camera object to capture images from.

    Int32 width

    The width of the generated visual observation.

    Int32 height

    The height of the generated visual observation.

    Boolean grayscale

    Whether to convert the generated image to grayscale or keep color.

    String name

    The name of the camera sensor.

    SensorCompressionType compression

    The compression to apply to the generated image.

    ObservationType observationType

    The type of observation.

    Properties

    Camera

    The Camera used for rendering the sensor observations.

    Declaration
    public Camera Camera { get; set; }
    Property Value
    Type Description
    Camera

    CompressionType

    The compression type used by the sensor.

    Declaration
    public SensorCompressionType CompressionType { get; set; }
    Property Value
    Type Description
    SensorCompressionType

    Methods

    Dispose()

    Clean up the owned Texture2D.

    Declaration
    public void Dispose()

    GetBuiltInSensorType()

    Declaration
    public BuiltInSensorType GetBuiltInSensorType()
    Returns
    Type Description
    BuiltInSensorType

    GetCompressedObservation()

    Generates a compressed image. This can be valuable in speeding-up training.

    Declaration
    public byte[] GetCompressedObservation()
    Returns
    Type Description
    Byte[]

    Compressed image.

    Implements
    ISensor.GetCompressedObservation()

    GetCompressionSpec()

    Return information on the compression type being used. If no compression is used, return Default().

    Declaration
    public CompressionSpec GetCompressionSpec()
    Returns
    Type Description
    CompressionSpec

    An object describing the compression used by the sensor.

    Implements
    ISensor.GetCompressionSpec()

    GetName()

    Accessor for the name of the sensor.

    Declaration
    public string GetName()
    Returns
    Type Description
    String

    Sensor name.

    Implements
    ISensor.GetName()

    GetObservationSpec()

    Returns a description of the observations that will be generated by the sensor. The shape will be h x w x 1 for grayscale and h x w x 3 for color. The dimensions have translational equivariance along width and height, and no property along the channels dimension.

    Declaration
    public ObservationSpec GetObservationSpec()
    Returns
    Type Description
    ObservationSpec
    Implements
    ISensor.GetObservationSpec()

    ObservationToTexture(Camera, Texture2D, Int32, Int32)

    Renders a Camera instance to a 2D texture at the corresponding resolution.

    Declaration
    public static void ObservationToTexture(Camera obsCamera, Texture2D texture2D, int width, int height)
    Parameters
    Type Name Description
    Camera obsCamera

    Camera.

    Texture2D texture2D

    Texture2D to render to.

    Int32 width

    Width of resulting 2D texture.

    Int32 height

    Height of resulting 2D texture.

    Reset()

    Resets the internal state of the sensor. This is called at the end of an Agent's episode. Most implementations can leave this empty.

    Declaration
    public void Reset()
    Implements
    ISensor.Reset()

    Update()

    Update any internal state of the sensor. This is called once per each agent step.

    Declaration
    public void Update()
    Implements
    ISensor.Update()

    Write(ObservationWriter)

    Writes out the generated, uncompressed image to the provided ObservationWriter.

    Declaration
    public int Write(ObservationWriter writer)
    Parameters
    Type Name Description
    ObservationWriter writer

    Where the observation is written to.

    Returns
    Type Description
    Int32
    Implements
    ISensor.Write(ObservationWriter)
    In This Article
    • Constructors
      • CameraSensor(Camera, Int32, Int32, Boolean, String, SensorCompressionType, ObservationType)
    • Properties
      • Camera
      • CompressionType
    • Methods
      • Dispose()
      • GetBuiltInSensorType()
      • GetCompressedObservation()
      • GetCompressionSpec()
      • GetName()
      • GetObservationSpec()
      • ObservationToTexture(Camera, Texture2D, Int32, Int32)
      • Reset()
      • Update()
      • Write(ObservationWriter)
    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023