# host_spatials_calc

Python API: `depthai_nodes.node.host_spatials_calc`

## 类

### HostSpatialsCalc

从深度区域计算相机空间坐标。

深度值和返回的坐标使用相同的单位，通常是毫米。

> **Note**
> 四坐标 ROI 用作 NumPy 切片边界，不进行裁剪。点输入被钳制，以便采样方块适合帧内。

#### 方法

##### init

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

配置校准、点采样和接受的深度范围。

参数

 * `calibData` (`dai.CalibrationHandler`): 用于获取相机内参的设备校准数据。
 * `depthAlignmentSocket` (`dai.CameraBoardSocket`): 深度像素对齐的相机。
 * `delta` (`int`): 围绕点输入采样的正方形的半尺寸（像素）。
 * `threshLow` (`int`): 深度帧单位中接受的最小深度（包含）。
 * `threshHigh` (`int`): 深度帧单位中接受的最大深度（包含）。

##### calcSpatials

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

将深度区域的质心投影到相机空间。

参数

 * `depthData` (`dai.ImgFrame`): 与配置的相机对齐的深度帧。
 * `roi` (`list[int]`): 像素坐标，格式为 `[xmin, ymin, xmax, ymax]`，或由 `delta` 扩展的点 `[x, y]`。切片上限是排他性的。
 * `averagingMethod` (`Callable`): 在包含的配置阈值内对深度样本进行缩减的函数；默认为平均值。

返回

 * `dict[str, float]`: 包含深度帧单位中的 `x`、`y` 和 `z` 的字典。如果没有样本通过深度阈值，则所有值为零。

抛出

 * `ValueError`: 如果 ROI 既不包含两个坐标也不包含四个坐标。

##### setDeltaRoi

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

设置点采样正方形的半尺寸。

参数

 * `delta` (`int`): 半尺寸（像素）。浮点值将被截断为整数。

抛出

 * `TypeError`: 如果 delta 既不是整数也不是浮点数。

##### setLowerThreshold

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

设置 ROI 平均期间使用的下深度阈值。

参数

 * `thresholdLow` (`int`): 接受的下深度值。

##### setUpperThreshold

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

设置 ROI 平均期间使用的上深度阈值。

参数

 * `thresholdHigh` (`int`): 接受的上深度值。

#### 属性

##### calibData

##### delta

##### depth_alignment_socket

##### thresh_high

##### thresh_low
