# SpatialLocationCalculator

SpatialLocationCalculator node calculates the spatial coordinates of the ROI (region-of-interest) based on the depth map from the
inputDepth. It will average the depth values in the ROI and remove the ones out of range.

You can also calculate spatial coordinates on host side, [demo
here](https://github.com/luxonis/oak-examples/tree/master/gen2-calc-spatials-on-host). The demo also has the same logic that's
performed on the device (calc.py file).

## How to place it

#### Python

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

#### C++

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

## Inputs and Outputs

## Usage

#### Python

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

# Set initial config
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)

# You can later send configs from the host (XLinkIn) / Script node to the InputConfig
```

#### C++

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

// Set initial config
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);

// You can later send configs from the host (XLinkIn) / scripting node to the InputConfig
```

## Examples of functionality

 * [Spatial location calculator](https://docs.luxonis.com/software/depthai/examples/spatial_location_calculator.md)

## Spatial coordinate system

OAK camera uses left-handed (Cartesian) coordinate system for all spatial coordinates.

Middle of the frame is 0,0 in terms of X,Y coordinates. If you go up, Y will increase, and if you go right, X will increase.

## Reference

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

### Need assistance?

Head over to [Discussion Forum](https://discuss.luxonis.com/) for technical support or any other questions you might have.
