# SpatialLocationCalculator

SpatialLocationCalculator 节点 根据 inputDepth 输入的深度图计算 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-v3/depthai/examples/spatial_location_calculator/spatial_location_calculator.md)

## 空间坐标系

OAK相机使用RDF（右-下-前）坐标系处理所有空间坐标。

帧中心是X,Y坐标的(0,0)点。向下移动Y增加，向右移动X增加。

## 参考

### dai::node::SpatialLocationCalculator

Kind: class

SpatialLocationCalculator node. Calculates the spatial locations of detected objects based on the input depth map. Spatial
location calculations can be additionally refined by using a segmentation mask. If keypoints are provided, the spatial location is
calculated around each keypoint.

#### std::shared_ptr< SpatialLocationCalculatorConfig > initialConfig

Kind: variable

Initial config to use when calculating spatial location data.

#### Input inputConfig

Kind: variable

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

#### Input inputDetections

Kind: variable

Input messages on which spatial location will be calculated. Possible datatypes are ImgDetections or Keypoints.

#### Input inputDepth

Kind: variable

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

#### Output out

Kind: variable

Outputs SpatialLocationCalculatorData message that carries spatial locations for each additional ROI that is specified in the
config.

#### Output outputDetections

Kind: variable

Outputs SpatialImgDetections message that carries spatial locations along with original input data.

#### Output passthroughDepth

Kind: variable

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

#### SpatialLocationCalculator()

Kind: function

#### SpatialLocationCalculator(std::unique_ptr< Properties > props)

Kind: function

#### void setRunOnHost(bool runOnHost)

Kind: function

Specify whether to run on host or device By default, the node will run on device.

#### bool runOnHost()

Kind: function

Check if the node is set to run on host

#### void run()

Kind: function

#### DeviceNodeCRTP()

Kind: function

#### DeviceNodeCRTP(const std::shared_ptr< Device > & device)

Kind: function

#### DeviceNodeCRTP(std::unique_ptr< Properties > props)

Kind: function

#### DeviceNodeCRTP(std::unique_ptr< Properties > props, bool confMode)

Kind: function

#### DeviceNodeCRTP(const std::shared_ptr< Device > & device, std::unique_ptr< Properties > props, bool confMode)

Kind: function

### 需要帮助？

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