# img_frame_overlay

Python API: `depthai_nodes.node.img_frame_overlay`

## Classes

| Name | Description |
| --- | --- |
| [`ImgFrameOverlay`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/img_frame_overlay.md#img_frame_overlay-Classes-ImgFrameOverlay) | Blend two image streams into a single frame. |

### class `ImgFrameOverlay`

```python
class ImgFrameOverlay(BaseHostNode)
```

Blend two image streams into a single frame.

Args

| Name | Description |
| --- | --- |
| `alpha` | Background weight between 0 and 1. The default of 0.5 gives background and foreground equal weight. |
| `preserveBackground` | Preserve background pixels where the foreground is zero. |

Attributes

| Name | Description |
| --- | --- |
| `out` | Output stream of blended `dai.ImgFrame` messages. |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/img_frame_overlay.md#img_frame_overlay-Classes-ImgFrameOverlay-__init__) | Initialize the image-processing node. |
| [`build`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/img_frame_overlay.md#img_frame_overlay-Classes-ImgFrameOverlay-build) | Connect the input streams and optionally update overlay settings. |
| [`process`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/img_frame_overlay.md#img_frame_overlay-Classes-ImgFrameOverlay-process) | Blend a synchronized background and foreground frame and emit the result. |
| [`setAlpha`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/img_frame_overlay.md#img_frame_overlay-Classes-ImgFrameOverlay-setAlpha) | Set the background contribution used during overlay. |
| [`setPreserveBackground`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/img_frame_overlay.md#img_frame_overlay-Classes-ImgFrameOverlay-setPreserveBackground) | Set whether zero-valued foreground pixels preserve the background. |

#### method `__init__`

```python
def __init__(alpha: float = 0.5, preserveBackground: bool = False)
```

Initialize the image-processing node.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `alpha` | `float` | Background weight between 0 and 1. The default of 0.5 gives background and foreground equal weight. | `0.5` |
| `preserveBackground` | `bool` | Preserve background pixels where the foreground is zero. | `False` |

#### method `build`

```python
def build(
    frame1: dai.Node.Output,
    frame2: dai.Node.Output,
    alpha: float | None = None,
    preserveBackground: bool | None = None,
) -> ImgFrameOverlay
```

Connect the input streams and optionally update overlay settings.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `frame1` | `dai.Node.Output` | Upstream output producing the background frame. | required |
| `frame2` | `dai.Node.Output` | Upstream output producing the foreground frame. | required |
| `alpha` | `float | None` | Optional blend weight for the background frame. | `None` |
| `preserveBackground` | `bool | None` | Optional override for whether zero-valued foreground pixels preserve the background frame. | `None` |

Returns

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

#### method `process`

```python
def process(frame1: dai.Buffer, frame2: dai.Buffer)
```

Blend a synchronized background and foreground frame and emit the result.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `frame1` | `dai.Buffer` | Background image frame. | required |
| `frame2` | `dai.Buffer` | Foreground image frame, resized to the background dimensions before blending. | required |

#### method `setAlpha`

```python
def setAlpha(alpha: float)
```

Set the background contribution used during overlay.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `alpha` | `float` | Weight of the background frame in the blended output. | required |

#### method `setPreserveBackground`

```python
def setPreserveBackground(preserveBackground: bool)
```

Set whether zero-valued foreground pixels preserve the background.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `preserveBackground` | `bool` | If True, zero areas in the foreground frame are ignored in the output image. | required |
