# img_frame_overlay

Python API: `depthai_nodes.node.img_frame_overlay`

## Classes

### ImgFrameOverlay

Blend two image streams into a single frame.

Parameters

 * `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.

#### Methods

##### init

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

Initialize the image-processing node.

Parameters

 * `alpha` (`float`): Background weight between 0 and 1. The default of 0.5 gives background and foreground equal weight.
 * `preserveBackground` (`bool`): Preserve background pixels where the foreground is zero.

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

Parameters

 * `frame1` (`dai.Node.Output`): Upstream output producing the background frame.
 * `frame2` (`dai.Node.Output`): Upstream output producing the foreground frame.
 * `alpha` (`float | None`): Optional blend weight for the background frame.
 * `preserveBackground` (`bool | None`): Optional override for whether zero-valued foreground pixels preserve the background
   frame.

Returns

 * `ImgFrameOverlay`: The configured node instance.

##### process

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

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

Parameters

 * `frame1` (`dai.Buffer`): Background image frame.
 * `frame2` (`dai.Buffer`): Foreground image frame, resized to the background dimensions before blending.

##### setAlpha

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

Set the background contribution used during overlay.

Parameters

 * `alpha` (`float`): Weight of the background frame in the blended output.

##### setPreserveBackground

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

Set whether zero-valued foreground pixels preserve the background.

Parameters

 * `preserveBackground` (`bool`): If True, zero areas in the foreground frame are ignored in the output image.

#### Attributes

##### out

Output stream of blended `dai.ImgFrame` messages.
