# MLDepthFeature

This feature is used to provide depth data to predictors that require such data. Implementers can derive from this class and provide custom logic for sampling depth given a pixel location.

## Creating the Feature

```csharp
/// <summary>
/// Initialize the depth feature with the depth map dimensions.
/// </summary>
/// <param name="width">Depth map width.</param>
/// <param name="height">Depth map height.</param>
protected MLDepthFeature (int width, int height);
```

The depth feature is constructed by specifying the feature size. The data type is assumed to be `float32`. If the data type is different, the full feature type can be specified instead:

```csharp
/// <summary>
/// Initialize the depth feature with the depth map feature type.
/// </summary>
/// <param name="type">Depth map feature type.</param>
protected MLDepthFeature (MLImageType type);
```

## Inspecting the Feature

The depth feature exposes its underlying `type`, along with convenience properties for inspecting the aforementioned `type`.

### Feature Type

```csharp
/// <summary>
/// Feature type.
/// </summary>
MLFeatureType type { get; }
```

Refer to the [Inspecting the Feature](/unity/api/mlfeature.md#inspecting-the-feature) section of the [`MLFeature`](/unity/api/mlfeature.md) class for more information.

{% hint style="info" %}
The `type` is always an [`MLImageType`](/unity/api/mlfeaturetype/mlimagetype.md).
{% endhint %}

### Depth Map Width

```csharp
/// <summary>
/// Depth map width.
/// </summary>
int width { get; }
```

The depth feature provides this convenience property for accessing the `width` of the feature `type`.

### Depth Map Height

```csharp
/// <summary>
/// Depth map height.
/// </summary>
int height { get; }
```

The depth feature provides this convenience property for accessing the `height` of the feature `type`.

## Sampling Pixel Depth

```csharp
/// <summary>
/// Sample the depth feature at a given point.
/// </summary>
/// <param name="point">Point to sample in normalized coordinates.</param>
/// <returns>Depth in meters.</returns>
abstract float Sample (Vector2 point);
```

The depth feature defines the `Sample` method for sampling the depth at a given normalized viewport coordinate.

{% hint style="info" %}
The `point` is specified in normalized coordinates, and as such must be in range `[0.0, 1.0]`.
{% endhint %}

{% hint style="success" %}
The depth unit is assumed to be in meters, except defined otherwise by implementations.
{% endhint %}

## Projecting to 3D Space

```csharp
/// <summary>
/// Project a 2D point into 3D world space using depth.
/// </summary>
/// <param name="point">Point to transform in normalized camera coordinates.</param>
/// <returns>Projected point in 3D world space.</param>
abstract Vector3 Unproject (Vector2 point);
```

The depth feature defines the `ViewportToWorldPoint` for projecting a normalized 2D viewport point into 3D space using its underlying depth data.

{% hint style="info" %}
The `point` is specified in normalized coordinates, and as such must be in range `[0.0, 1.0]`.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.natml.ai/unity/api/mlfeature/mldepthfeature.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
