# depth_merger

Python API: `depthai_nodes.node.depth_merger`

## Classes

| Name | Description |
| --- | --- |
| [`DepthMerger`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/depth_merger.md#depth_merger-Classes-DepthMerger) | Merge 2D detections with aligned depth to produce spatial detections. |

### class `DepthMerger`

```python
class DepthMerger(BaseHostNode)
```

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,
)
```

Attributes

| Name | Description |
| --- | --- |
| `host_spatials_calc` |  |
| `output` | Output stream containing spatial detections. |
| `shrinking_factor` | Fraction of each bounding-box edge trimmed before sampling depth. |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/depth_merger.md#depth_merger-Classes-DepthMerger-__init__) | Create a spatial-detection output and set ROI shrinking. |
| [`build`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/depth_merger.md#depth_merger-Classes-DepthMerger-build) | Connect detection and depth streams and initialize spatial conversion. |
| [`process`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/depth_merger.md#depth_merger-Classes-DepthMerger-process) | Convert detections to spatial detections and send them through `output`. |

#### method `__init__`

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

Create a spatial-detection output and set ROI shrinking.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `shrinkingFactor` | `float` | Fraction trimmed from each side before sampling depth. The build call supplies its own value. | `0` |

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

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output2d` | `dai.Node.Output` | Upstream output producing 2D detections. | required |
| `outputDepth` | `dai.Node.Output` | Upstream output producing aligned depth frames. | required |
| `calibData` | `dai.CalibrationHandler` | Device calibration used to convert image coordinates into spatial coordinates. | required |
| `depthAlignmentSocket` | `dai.CameraBoardSocket` | Camera socket the depth frame is aligned to. | `dai.CameraBoardSocket.CAM_A` |
| `shrinkingFactor` | `float` | Percentage of each bounding box edge trimmed before depth averaging. | `0` |

Returns

| Type | Description |
| --- | --- |
| `DepthMerger` | The configured node instance. |

#### method `process`

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

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

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `message2d` | `dai.Buffer` | `dai.ImgDetection` or `dai.ImgDetections` to project into camera space. | required |
| `depth` | `dai.ImgFrame` | Depth frame aligned to the configured calibration camera. | required |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If the detection input type is unsupported. |
