# depth_merger

Python API: `depthai_nodes.node.depth_merger`

## Classes

### DepthMerger

Merge 2D detections with aligned depth to produce spatial detections.

> **Example**
> With a pipeline, neural network, stereo node, and device calibration:

```text
depth_merger = pipeline.create(DepthMerger).build(
    output2d=nn.out,
    outputDepth=stereo.depth,
    calibData=calibration,
)
```

#### Methods

##### init

```python
def __init__(shrinkingFactor: float = 0):
```

Create a spatial-detection output and set ROI shrinking.

Parameters

 * `shrinkingFactor` (`float`): Fraction trimmed from each side before sampling depth. The build call supplies its own value.

##### build

```python
def build(output2d: dai.Node.Output, outputDepth: dai.Node.Output, calibData: dai.CalibrationHandler, depthAlignmentSocket: dai.CameraBoardSocket = dai.CameraBoardSocket.CAM_A, shrinkingFactor: float = 0) -> DepthMerger:
```

Connect detection and depth streams and initialize spatial conversion.

Parameters

 * `output2d` (`dai.Node.Output`): Upstream output producing 2D detections.
 * `outputDepth` (`dai.Node.Output`): Upstream output producing aligned depth frames.
 * `calibData` (`dai.CalibrationHandler`): Device calibration used to convert image coordinates into spatial coordinates.
 * `depthAlignmentSocket` (`dai.CameraBoardSocket`): Camera socket the depth frame is aligned to.
 * `shrinkingFactor` (`float`): Percentage of each bounding box edge trimmed before depth averaging.

Returns

 * `DepthMerger`: The configured node instance.

##### process

```python
def process(message2d: dai.Buffer, depth: dai.ImgFrame):
```

Convert detections to spatial detections and send them through `output`.

Parameters

 * `message2d` (`dai.Buffer`): `dai.ImgDetection` or `dai.ImgDetections` to project into camera space.
 * `depth` (`dai.ImgFrame`): Depth frame aligned to the configured calibration camera.

Raises

 * `ValueError`: If the detection input type is unsupported.

#### Attributes

##### host_spatials_calc

##### output

Output stream containing spatial detections.

##### shrinking_factor

Fraction of each bounding-box edge trimmed before sampling depth.
