# SpatialLocationCalculator

SpatialLocationCalculator节点 根据 inputDepth 提供的 depth 深度图计算 ROI（感兴趣区域）的空间坐标。它会计算 ROI 内深度值的平均值，并去除超出范围的值。

你也可以在主机端计算空间坐标，[示例在此](https://github.com/luxonis/oak-examples/tree/master/gen2-calc-spatials-on-host)。该示例还包含了设备端执行的相同逻辑（calc.py
文件）。

## 如何放置

#### Python

```python
pipeline = dai.Pipeline()
spatialCalc = pipeline.create(dai.node.SpatialLocationCalculator)
```

#### C++

```cpp
dai::Pipeline pipeline;
auto spatialCalc = pipeline.create<dai::node::SpatialLocationCalculator>();
```

## 输入和输出

## 使用示例

#### Python

```python
pipeline = dai.Pipeline()
spatialCalc = pipeline.create(dai.node.SpatialLocationCalculator)
spatialCalc.setWaitForConfigInput(False)

# 设置初始配置
config = dai.SpatialLocationCalculatorConfigData()
config.depthThresholds.lowerThreshold = 100
config.depthThresholds.upperThreshold = 10000

topLeft = dai.Point2f(0.4, 0.4)
bottomRight = dai.Point2f(0.6, 0.6)
config.roi = dai.Rect(topLeft, bottomRight)

spatial_calc.initialConfig.addROI(config)

# 稍后你可以从主机（XLinkIn）/ Script 节点发送配置到 InputConfig
```

#### C++

```cpp
dai::Pipeline pipeline;
auto spatialCalc = pipeline.create<dai::node::SpatialLocationCalculator>();
spatialCalc->setWaitForConfigInput(false);

// 设置初始配置
dai::SpatialLocationCalculatorConfigData config;
config.depthThresholds.lowerThreshold = 100;
config.depthThresholds.upperThreshold = 10000;

dai::Point2f topLeft(0.4f, 0.4f);
dai::Point2f bottomRight(0.6f, 0.6f);
config.roi = dai::Rect(topLeft, bottomRight);

spatialCalc->initialConfig.addROI(config);

// 稍后你可以从主机（XLinkIn）/ 脚本节点发送配置到 InputConfig
```

## 功能示例

 * [空间位置计算器](https://docs.luxonis.com/software/depthai/examples/spatial_location_calculator.md)

## 空间坐标系

OAK 相机使用 左手（笛卡尔）坐标系 处理所有空间坐标。

画面中心为 X、Y 坐标的 0,0 点。向上移动时 Y 值增加，向右移动时 X 值增加。

## 参考

### depthai.node.SpatialLocationCalculator(depthai.Node)

Kind: Class

SpatialLocationCalculator node. Calculates spatial location data on a set of
ROIs on depth map.

#### getWaitForConfigInput(self) -> bool: bool

Kind: Method

See also:
setWaitForConfigInput

Returns:
True if wait for inputConfig message, false otherwise

#### setWaitForConfigInput(self, wait: bool)

Kind: Method

Specify whether or not wait until configuration message arrives to inputConfig
Input.

Parameter ``wait``:
True to wait for configuration message, false otherwise.

#### initialConfig

Kind: Property

Initial config to use when calculating spatial location data.

#### inputConfig

Kind: Property

Input SpatialLocationCalculatorConfig message with ability to modify parameters
in runtime. Default queue is non-blocking with size 4.

#### inputDepth

Kind: Property

Input message with depth data used to retrieve spatial information about
detected object. Default queue is non-blocking with size 4.

#### out

Kind: Property

Outputs SpatialLocationCalculatorData message that carries spatial location
results.

#### passthroughDepth

Kind: Property

Passthrough message on which the calculation was performed. Suitable for when
input queue is set to non-blocking behavior.

### 需要帮助？

请前往 [OAKChina 官网](https://www.oakchina.cn/) 获取技术支持或解答您的任何疑问。
