# ppdet

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

## 类

### PPTextDetectionParser

用于解析 PaddlePaddle OCR 文本检测模型输出的解析器类。

输出消息：

类型：dai.ImgDetections 描述：dai.ImgDetections 消息，包含检测到的文本的边界框和相应的置信度分数。

#### 方法

##### init

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

初始化解析器节点。

参数

 * `output_layer_name` (`str`)：与解析器相关的输出层的名称。
 * `conf_threshold` (`float`)：边界框的阈值。
 * `mask_threshold` (`float`)：掩码的阈值。
 * `max_det` (`int`)：候选边界框的最大数量。

##### build

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

配置解析器。

参数

 * `head_config` (`dict[str, Any]`)：解析器的头部配置。

返回

 * `PPTextDetectionParser`：设置了头部配置的解析器对象。

##### compute

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

在不发送消息的情况下，从提取的张量计算解析器结果。

> **注意**
> 使用 [depthai_nodes.node.parsers.utils.ppdet.compute_pp_text_detections](/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/ppdet.md)；有关张量布局和验证详细信息，请参阅该帮助程序。

参数

 * `predictions` (`np.ndarray`)：`parse_paddle_detection_outputs` 接受的文本概率张量。
 * `mask_threshold` (`float`)：用于将文本概率图二值化的阈值。
 * `conf_threshold` (`float`)：用于过滤候选的最小检测置信度。
 * `max_det` (`int`)：在抑制期间保留或考虑的最大检测候选数量。

返回

 * `tuple[np.ndarray, np.ndarray, np.ndarray]`：归一化的中心 XY/宽度/高度框、旋转角度（以度为单位）和置信度分数。

##### emit

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

创建 `dai.ImgDetections` 消息并将其发送到 `out`。

复制源时间戳和序列号，并在存在时携带源图像变换。

参数

 * `output` (`dai.NNData`)：携带张量和源时间戳、序列号以及可选图像变换的神经网络输出。
 * `bboxes` (`np.ndarray`)：`compute()` 返回的归一化中心 XY/宽度/高度框。
 * `angles` (`np.ndarray`)：与框对应的旋转角度（以度为单位）。
 * `scores` (`np.ndarray`)：与计算负载对应的置信度分数。

##### extract

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

选择并反量化解析所需的模型张量。

参数

 * `output` (`dai.NNData`)：携带张量和源时间戳、序列号以及可选图像变换的神经网络输出。

返回

 * `np.ndarray`：以 NCHW 存储顺序请求的反量化文本概率张量。

引发

 * `ValueError`：如果未配置输出名称且消息不包含恰好一个层，或者未满足配置的类要求。

##### run

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

读取排队的网络输出，解析它们，并在运行时发出结果。

管道调用此处理循环。当输入队列关闭或节点停止时，它会退出。

##### setMaskThreshold

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

设置用于从模型输出概率创建掩码的掩码阈值。

参数

 * `mask_threshold` (`float`)：掩码的阈值。

##### setOutputLayerName

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

设置输出层的名称。

参数

 * `output_layer_name` (`str`)：输出层的名称。

#### 属性

##### conf_threshold

边界框的阈值。

##### mask_threshold

掩码的阈值。

##### max_det

候选边界框的最大数量。

##### output_layer_name

与解析器相关的输出层的名称。
