Class CameraSensor
A sensor that wraps a Camera object to generate visual observations for an agent.
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
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
GetName()
Accessor for the name of the sensor.
Declaration
public string GetName()
Returns
Type | Description |
---|---|
String | Sensor name. |
Implements
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
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
Update()
Update any internal state of the sensor. This is called once per each agent step.
Declaration
public void Update()
Implements
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 |