# ppdet

Python API: `depthai_nodes.node.parsers.ppdet`

## Classes

| Name | Description |
| --- | --- |
| [`PPTextDetectionParser`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/ppdet.md#ppdet-Classes-PPTextDetectionParser) | Parser class for parsing the output of the PaddlePaddle OCR text detection model. |

### class `PPTextDetectionParser`

```python
class PPTextDetectionParser(DetectionParser)
```

Parser class for parsing the output of the PaddlePaddle OCR text detection model.

Output messages:

Type: dai.ImgDetections Description: dai.ImgDetections message containing bounding boxes and the respective confidence scores of
detected text.

Attributes

| Name | Description |
| --- | --- |
| `conf_threshold` | The threshold for bounding boxes. |
| `mask_threshold` | The threshold for the mask. |
| `max_det` | The maximum number of candidate bounding boxes. |
| `output_layer_name` | Name of the output layer relevant to the parser. |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/ppdet.md#ppdet-Classes-PPTextDetectionParser-__init__) | Initializes the parser node. |
| [`build`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/ppdet.md#ppdet-Classes-PPTextDetectionParser-build) | Configures the parser. |
| [`compute`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/ppdet.md#ppdet-Classes-PPTextDetectionParser-compute) | Compute parser results from extracted tensors without sending messages. |
| [`emit`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/ppdet.md#ppdet-Classes-PPTextDetectionParser-emit) | Create a `dai.ImgDetections` message and send it on `out`. |
| [`extract`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/ppdet.md#ppdet-Classes-PPTextDetectionParser-extract) | Select and dequantize the model tensors needed for parsing. |
| [`run`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/ppdet.md#ppdet-Classes-PPTextDetectionParser-run) | Read queued network outputs, parse them, and emit results while running. |
| [`setMaskThreshold`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/ppdet.md#ppdet-Classes-PPTextDetectionParser-setMaskThreshold) | Sets the mask threshold for creating the mask from model output probabilities. |
| [`setOutputLayerName`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/ppdet.md#ppdet-Classes-PPTextDetectionParser-setOutputLayerName) | Sets the name of the output layer. |

#### method `__init__`

```python
def __init__(
    output_layer_name: str = '',
    conf_threshold: float = 0.5,
    mask_threshold: float = 0.25,
    max_det: int = 100,
)
```

Initializes the parser node.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_name` | `str` | Name of the output layer relevant to the parser. | `''` |
| `conf_threshold` | `float` | The threshold for bounding boxes. | `0.5` |
| `mask_threshold` | `float` | The threshold for the mask. | `0.25` |
| `max_det` | `int` | The maximum number of candidate bounding boxes. | `100` |

#### method `build`

```python
def build(head_config: dict[str, Any]) -> PPTextDetectionParser
```

Configures the parser.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `head_config` | `dict[str, Any]` | The head configuration for the parser. | required |

Returns

| Type | Description |
| --- | --- |
| `PPTextDetectionParser` | The parser object with the head configuration set. |

#### static method `compute`

```python
def compute(
    predictions: np.ndarray,
    *,
    mask_threshold: float,
    conf_threshold: float,
    max_det: int,
) -> tuple[np.ndarray, np.ndarray, np.ndarray]
```

Compute parser results from extracted tensors without sending messages.

> **Note**
> Uses [depthai_nodes.node.parsers.utils.ppdet.compute_pp_text_detections](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/ppdet.md#ppdet-Functions-compute_pp_text_detections); see that helper for tensor layout and validation details.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `predictions` | `np.ndarray` | Text probability tensor accepted by `parse_paddle_detection_outputs`. | required |
| `mask_threshold` | `float` | Threshold used to binarize the text probability map. | required |
| `conf_threshold` | `float` | Minimum detection confidence used to filter candidates. | required |
| `max_det` | `int` | Maximum number of detection candidates to retain or consider during suppression. | required |

Returns

| Type | Description |
| --- | --- |
| `tuple[np.ndarray, np.ndarray, np.ndarray]` | Normalized center-XY/width/height boxes, rotation angles in degrees, and confidence scores. |

#### method `emit`

```python
def emit(output: dai.NNData, bboxes: np.ndarray, angles: np.ndarray, scores: np.ndarray)
```

Create a `dai.ImgDetections` message and send it on `out`.

Copies source timestamps and sequence number, and carries the source image transformation when present.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output` | `dai.NNData` | Neural network output carrying tensors and source timestamps, sequence number, and optional image transformation. | required |
| `bboxes` | `np.ndarray` | Normalized center-XY/width/height boxes returned by `compute()`. | required |
| `angles` | `np.ndarray` | Rotation angles in degrees corresponding to the boxes. | required |
| `scores` | `np.ndarray` | Confidence scores corresponding to the computed payload. | required |

#### method `extract`

```python
def extract(output: dai.NNData) -> np.ndarray
```

Select and dequantize the model tensors needed for parsing.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output` | `dai.NNData` | Neural network output carrying tensors and source timestamps, sequence number, and optional image transformation. | required |

Returns

| Type | Description |
| --- | --- |
| `np.ndarray` | Dequantized text probability tensor requested in NCHW storage order. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If no output name is configured and the message does not contain exactly one layer, or configured class requirements are not met. |

#### method `run`

```python
def run()
```

Read queued network outputs, parse them, and emit results while running.

The pipeline invokes this processing loop. It exits when the input queue closes or the node stops.

#### method `setMaskThreshold`

```python
def setMaskThreshold(mask_threshold: float = 0.25)
```

Sets the mask threshold for creating the mask from model output probabilities.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `mask_threshold` | `float` | The threshold for the mask. | `0.25` |

#### method `setOutputLayerName`

```python
def setOutputLayerName(output_layer_name: str)
```

Sets the name of the output layer.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_name` | `str` | The name of the output layer. | required |
