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 coordiantes on host side, demo here. The demo also has the same logic that’s performed on the device (calc.py file).

https://user-images.githubusercontent.com/18037362/146296930-9e7071f5-33b9-45f9-af21-cace7ffffc0f.gif

How to place it

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

Inputs and Outputs

               ┌───────────────────┐
               │                   │
inputConfig    │                   │       out
──────────────►│     Spatial       ├───────────►
               │     location      │
               │     calculator    │
inputDepth     │                   │passthroughDepth
──────────────►│-------------------├───────────►
               └───────────────────┘

Message types

Usage

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
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 coordinate system

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

https://github.com/luxonis/depthai-python/assets/18037362/f9bfaa0c-0286-46c0-910c-77c1337493e1

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

class depthai.node.SpatialLocationCalculator
class Id

Node identificator. Unique for every node on a single Pipeline

getAssetManager(*args, **kwargs)

Overloaded function.

  1. getAssetManager(self: depthai.Node) -> depthai.AssetManager

  2. getAssetManager(self: depthai.Node) -> depthai.AssetManager

getInputRefs(*args, **kwargs)

Overloaded function.

  1. getInputRefs(self: depthai.Node) -> List[depthai.Node.Input]

  2. getInputRefs(self: depthai.Node) -> List[depthai.Node.Input]

getInputs(self: depthai.Node) → List[depthai.Node.Input]
getName(self: depthai.Node)str
getOutputRefs(*args, **kwargs)

Overloaded function.

  1. getOutputRefs(self: depthai.Node) -> List[depthai.Node.Output]

  2. getOutputRefs(self: depthai.Node) -> List[depthai.Node.Output]

getOutputs(self: depthai.Node) → List[depthai.Node.Output]
getParentPipeline(*args, **kwargs)

Overloaded function.

  1. getParentPipeline(self: depthai.Node) -> depthai.Pipeline

  2. getParentPipeline(self: depthai.Node) -> depthai.Pipeline

getWaitForConfigInput(self: depthai.node.SpatialLocationCalculator)bool
setWaitForConfigInput(self: depthai.node.SpatialLocationCalculator, wait: bool)None
class dai::node::SpatialLocationCalculator : public dai::NodeCRTP<Node, SpatialLocationCalculator, SpatialLocationCalculatorProperties>

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

Public Functions

SpatialLocationCalculator(const std::shared_ptr<PipelineImpl> &par, int64_t nodeId)
SpatialLocationCalculator(const std::shared_ptr<PipelineImpl> &par, int64_t nodeId, std::unique_ptr<Properties> props)
void setWaitForConfigInput(bool wait)

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

Parameters
  • wait: True to wait for configuration message, false otherwise.

bool getWaitForConfigInput() const

See

setWaitForConfigInput

Return

True if wait for inputConfig message, false otherwise

Public Members

SpatialLocationCalculatorConfig initialConfig

Initial config to use when calculating spatial location data.

Input inputConfig = {*this, "inputConfig", Input::Type::SReceiver, false, 4, {{DatatypeEnum::SpatialLocationCalculatorConfig, false}}}

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

Input inputDepth = {*this, "inputDepth", Input::Type::SReceiver, false, 4, true, {{DatatypeEnum::ImgFrame, false}}}

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

Output out = {*this, "out", Output::Type::MSender, {{DatatypeEnum::SpatialLocationCalculatorData, false}}}

Outputs SpatialLocationCalculatorData message that carries spatial location results.

Output passthroughDepth = {*this, "passthroughDepth", Output::Type::MSender, {{DatatypeEnum::ImgFrame, false}}}

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

Public Static Attributes

static constexpr const char *NAME = "SpatialLocationCalculator"

Private Members

std::shared_ptr<RawSpatialLocationCalculatorConfig> rawConfig

Got questions?

Head over to Discussion Forum for technical support or any other questions you might have.