# tiling

Python API: `depthai_nodes.node.tiling`

## Classes

### Tiling

Emit groups of ImageManip crop configurations at startup and on updates.

`build()` stores the initial configuration. When the pipeline invokes `run()`, the node sends the first `dai.MessageGroup`. Each
call to `updateTilingConfig()` recomputes and sends another group. Keys are zero-based string indexes. There is no trigger input.

Use with `FrameCropper.fromManipConfigs(waitForConfig=False)` to reuse the latest group for subsequent frames.

#### Methods

##### init

```python
def __init__(self):
```

Initialize logging and the platform-specific output image format.

Raises

 * `ValueError`: If the pipeline device platform has no configured image-frame format.

##### build

```python
def build(overlap: float, gridSize: tuple[int, int], canvasShape: tuple[int, int], resizeShape: tuple[int, int], resizeMode: dai.ImageManipConfig.ResizeMode, globalDetection: bool = False, gridMatrix: np.ndarray | list | None = None) -> Tiling:
```

Store the initial configuration for emission when the pipeline starts.

Parameters

 * `overlap` (`float`): Fractional overlap between adjacent cells, in [0, 1).
 * `gridSize` (`tuple[int, int]`): Grid dimensions as `(columns, rows)`.
 * `canvasShape` (`tuple[int, int]`): Source canvas size as `(width, height)` pixels.
 * `resizeShape` (`tuple[int, int]`): Output crop size as `(width, height)` pixels.
 * `resizeMode` (`dai.ImageManipConfig.ResizeMode`): ImageManip resizing policy for each crop.
 * `globalDetection` (`bool`): Prepend a crop covering the entire canvas when true.
 * `gridMatrix` (`np.ndarray | list | None`): Optional row-major grid labels. Four-connected cells with equal labels are merged
   into their enclosing rectangle.

Returns

 * `Tiling`: This node. Crop generation and validation occur when it runs.

##### run

```python
def run(self):
```

Compute and send the initial crop-configuration group once.

##### updateTilingConfig

```python
def updateTilingConfig(overlap: float | None = None, gridSize: tuple[int, int] | None = None, canvasShape: tuple[int, int] | None = None, resizeShape: tuple[int, int] | None = None, resizeMode: dai.ImageManipConfig.ResizeMode | None = None, globalDetection: bool | None = None, gridMatrix: np.ndarray | list | None | None = None):
```

Update selected settings and immediately emit a new configuration group.

> **Note**
> Updates mutate the stored configuration before crop validation. `None` cannot be used to clear an existing grid matrix.

Parameters

 * `overlap` (`float | None`): Fractional overlap between adjacent cells, in [0, 1). `None` preserves the current value.
 * `gridSize` (`tuple[int, int] | None`): Grid dimensions as `(columns, rows)`. `None` preserves the current value.
 * `canvasShape` (`tuple[int, int] | None`): Source canvas size as `(width, height)` pixels. `None` preserves the current value.
 * `resizeShape` (`tuple[int, int] | None`): Output crop size as `(width, height)` pixels. `None` preserves the current value.
 * `resizeMode` (`dai.ImageManipConfig.ResizeMode | None`): ImageManip resizing policy for each crop. `None` preserves the current
   value.
 * `globalDetection` (`bool | None`): Prepend a crop covering the entire canvas when true. `None` preserves the current value.
 * `gridMatrix` (`np.ndarray | list | None | None`): Optional row-major grid labels. Four-connected cells with equal labels are
   merged into their enclosing rectangle. `None` preserves the current value.

Raises

 * `RuntimeError`: If `build()` has not been called.
 * `ValueError`: If overlap is outside [0, 1) or the grid matrix dimensions disagree with `gridSize`.

#### Attributes

##### out

Return the output stream of tile configuration groups.

##### tileCount

Return the number of tiles in the current configuration.

##### tilePositions

Return crop rectangles as `(xmin, ymin, xmax, ymax)` pixel bounds.

Requires `build()` first. Includes the full canvas first when global detection is enabled, followed by the computed cell or group
rectangles.

### TilingCfg

Configuration shared by tiling geometry and ImageManip generation.

#### Attributes

##### canvasShape

Source canvas size as `(width, height)` pixels.

##### globalDetection

Prepend a crop covering the entire canvas when true.

##### gridMatrix

Optional row-major grid labels. Four-connected cells with equal labels are merged into their enclosing rectangle.

##### gridSize

Grid dimensions as `(columns, rows)`.

##### overlap

Fractional overlap between adjacent cells, in [0, 1).

##### resizeMode

ImageManip resizing policy for each crop.

##### resizeShape

Output crop size as `(width, height)` pixels.
