# host_spatials_calc

Python API: `depthai_nodes.node.host_spatials_calc`

## Classes

### 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.

#### Methods

##### 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.

Parameters

 * `calibData` (`dai.CalibrationHandler`): Device calibration used to obtain camera intrinsics.
 * `depthAlignmentSocket` (`dai.CameraBoardSocket`): Camera to which depth pixels are aligned.
 * `delta` (`int`): Half-size in pixels of the square sampled around point inputs.
 * `threshLow` (`int`): Inclusive minimum accepted depth, in the depth frame units.
 * `threshHigh` (`int`): Inclusive maximum accepted depth, in the depth frame units.

##### 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.

Parameters

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

Returns

 * `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

 * `ValueError`: If the ROI contains neither two nor four coordinates.

##### setDeltaRoi

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

Set the point-sampling square half-size.

Parameters

 * `delta` (`int`): Half-size in pixels. Floating-point values are truncated to integers.

Raises

 * `TypeError`: If delta is neither an int nor a float.

##### setLowerThreshold

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

Set the lower depth threshold used during ROI averaging.

Parameters

 * `thresholdLow` (`int`): Lower accepted depth value.

##### setUpperThreshold

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

Set the upper depth threshold used during ROI averaging.

Parameters

 * `thresholdHigh` (`int`): Upper accepted depth value.

#### Attributes

##### calibData

##### delta

##### depth_alignment_socket

##### thresh_high

##### thresh_low
