# host_spatials_calc

Python API: `depthai_nodes.node.host_spatials_calc`

## Classes

| Name | Description |
| --- | --- |
| [`HostSpatialsCalc`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/host_spatials_calc.md#host_spatials_calc-Classes-HostSpatialsCalc) | Compute camera-space coordinates from depth regions. |

### class `HostSpatialsCalc`

```python
class HostSpatialsCalc
```

Compute camera-space coordinates from depth regions.

Depth values and returned coordinates use the same units, normally millimeters.

> **Note**
> Four-coordinate ROIs are used as NumPy slice bounds without clipping. Point inputs are clamped so the sampling square fits inside the frame.

Attributes

| Name | Description |
| --- | --- |
| `calibData` |  |
| `delta` |  |
| `depth_alignment_socket` |  |
| `thresh_high` |  |
| `thresh_low` |  |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/host_spatials_calc.md#host_spatials_calc-Classes-HostSpatialsCalc-__init__) | Configure calibration, point sampling, and accepted depth range. |
| [`calcSpatials`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/host_spatials_calc.md#host_spatials_calc-Classes-HostSpatialsCalc-calcSpatials) | Project the depth-region centroid into camera space. |
| [`setDeltaRoi`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/host_spatials_calc.md#host_spatials_calc-Classes-HostSpatialsCalc-setDeltaRoi) | Set the point-sampling square half-size. |
| [`setLowerThreshold`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/host_spatials_calc.md#host_spatials_calc-Classes-HostSpatialsCalc-setLowerThreshold) | Set the lower depth threshold used during ROI averaging. |
| [`setUpperThreshold`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/host_spatials_calc.md#host_spatials_calc-Classes-HostSpatialsCalc-setUpperThreshold) | Set the upper depth threshold used during ROI averaging. |

#### method `__init__`

```python
def __init__(
    calibData: dai.CalibrationHandler,
    depthAlignmentSocket: dai.CameraBoardSocket = dai.CameraBoardSocket.CAM_A,
    delta: int = 5,
    threshLow: int = 200,
    threshHigh: int = 30000,
)
```

Configure calibration, point sampling, and accepted depth range.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `calibData` | `dai.CalibrationHandler` | Device calibration used to obtain camera intrinsics. | required |
| `depthAlignmentSocket` | `dai.CameraBoardSocket` | Camera to which depth pixels are aligned. | `dai.CameraBoardSocket.CAM_A` |
| `delta` | `int` | Half-size in pixels of the square sampled around point inputs. | `5` |
| `threshLow` | `int` | Inclusive minimum accepted depth, in the depth frame units. | `200` |
| `threshHigh` | `int` | Inclusive maximum accepted depth, in the depth frame units. | `30000` |

#### method `calcSpatials`

```python
def calcSpatials(
    depthData: dai.ImgFrame,
    roi: list[int],
    averagingMethod: Callable = np.mean,
) -> dict[str, float]
```

Project the depth-region centroid into camera space.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `depthData` | `dai.ImgFrame` | Depth frame aligned to the configured camera. | required |
| `roi` | `list[int]` | Pixel coordinates as `[xmin, ymin, xmax, ymax]`, or a point `[x, y]` expanded by `delta`. Slice upper bounds are exclusive. | required |
| `averagingMethod` | `Callable` | Reducer for depth samples within the inclusive configured thresholds; defaults to the mean. | `np.mean` |

Returns

| Type | Description |
| --- | --- |
| `dict[str, float]` | Dictionary with `x`, `y`, and `z` in depth-frame units. All values are zero if no samples pass the depth thresholds. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If the ROI contains neither two nor four coordinates. |

#### method `setDeltaRoi`

```python
def setDeltaRoi(delta: int)
```

Set the point-sampling square half-size.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `delta` | `int` | Half-size in pixels. Floating-point values are truncated to integers. | required |

Raises

| Type | Description |
| --- | --- |
| `TypeError` | If delta is neither an int nor a float. |

#### method `setLowerThreshold`

```python
def setLowerThreshold(thresholdLow: int)
```

Set the lower depth threshold used during ROI averaging.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `thresholdLow` | `int` | Lower accepted depth value. | required |

#### method `setUpperThreshold`

```python
def setUpperThreshold(thresholdHigh: int)
```

Set the upper depth threshold used during ROI averaging.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `thresholdHigh` | `int` | Upper accepted depth value. | required |
