# ppdet

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

## Classes

### PPTextDetectionParser

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.

#### Methods

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

Parameters

 * `output_layer_name` (`str`): Name of the output layer relevant to the parser.
 * `conf_threshold` (`float`): The threshold for bounding boxes.
 * `mask_threshold` (`float`): The threshold for the mask.
 * `max_det` (`int`): The maximum number of candidate bounding boxes.

##### build

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

Configures the parser.

Parameters

 * `head_config` (`dict[str, Any]`): The head configuration for the parser.

Returns

 * `PPTextDetectionParser`: The parser object with the head configuration set.

##### 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); see that helper for tensor layout and validation details.

Parameters

 * `predictions` (`np.ndarray`): Text probability tensor accepted by `parse_paddle_detection_outputs`.
 * `mask_threshold` (`float`): Threshold used to binarize the text probability map.
 * `conf_threshold` (`float`): Minimum detection confidence used to filter candidates.
 * `max_det` (`int`): Maximum number of detection candidates to retain or consider during suppression.

Returns

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

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

Parameters

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

##### extract

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

Select and dequantize the model tensors needed for parsing.

Parameters

 * `output` (`dai.NNData`): Neural network output carrying tensors and source timestamps, sequence number, and optional image
   transformation.

Returns

 * `np.ndarray`: Dequantized text probability tensor requested in NCHW storage order.

Raises

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

##### run

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

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.

##### setMaskThreshold

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

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

Parameters

 * `mask_threshold` (`float`): The threshold for the mask.

##### setOutputLayerName

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

Sets the name of the output layer.

Parameters

 * `output_layer_name` (`str`): The name of the output layer.

#### Attributes

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