Class CameraSensor
A sensor that wraps a Camera object to generate visual observations for an agent.
Inherited Members
Namespace: Unity.MLAgents.Sensors
Syntax
public class CameraSensor : ISensor
Constructors
CameraSensor(Camera, Int32, Int32, Boolean, String, SensorCompressionType)
Creates and returns the camera sensor.
Declaration
public CameraSensor(Camera camera, int width, int height, bool grayscale, string name, SensorCompressionType compression)
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. |
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
GetCompressedObservation()
Generates a compressed image. This can be valuable in speeding-up training.
Declaration
public byte[] GetCompressedObservation()
Returns
| Type | Description |
|---|---|
| Byte[] | Compressed image. |
Implements
GetCompressionType()
Return the compression type being used. If no compression is used, return None.
Declaration
public SensorCompressionType GetCompressionType()
Returns
| Type | Description |
|---|---|
| SensorCompressionType | Compression type used by the sensor. |
Implements
GetName()
Accessor for the name of the sensor.
Declaration
public string GetName()
Returns
| Type | Description |
|---|---|
| String | Sensor name. |
Implements
GetObservationShape()
Accessor for the size of the sensor data. Will be h x w x 1 for grayscale and h x w x 3 for color.
Declaration
public int[] GetObservationShape()
Returns
| Type | Description |
|---|---|
| Int32[] | Size of each of the three dimensions. |
Implements
ObservationToTexture(Camera, Int32, Int32)
Renders a Camera instance to a 2D texture at the corresponding resolution.
Declaration
public static Texture2D ObservationToTexture(Camera obsCamera, int width, int height)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | obsCamera | Camera. |
| Int32 | width | Width of resulting 2D texture. |
| Int32 | height | Height of resulting 2D texture. |
Returns
| Type | Description |
|---|---|
| Texture2D | The 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 |