# mediapipe_palm_detection

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

## 类

### MPPalmDetectionParser

用于解析 Mediapipe 手掌检测模型输出的解析器类。结果是，该节点以包含边界框、标签和置信度分数的消息形式发送检测到的手。

> **注意**
> 发出 `dai.ImgDetections` 消息。`dai.ImgDetections` 消息包含检测到的手的边界框、标签和置信度分数。

另请参阅：

官方 MediaPipe Hands
解决方案：[https://ai.google.dev/edge/mediapipe/solutions/vision/hand_landmarker](https://ai.google.dev/edge/mediapipe/solutions/vision/hand_landmarker)

#### 方法

##### init

```python
def __init__(output_layer_names: list[str] = None, conf_threshold: float = 0.5, iou_threshold: float = 0.5, max_det: int = 100, scale: int = 192):
```

初始化解析器节点。

参数

 * `output_layer_names` (`list[str]`): 与解析器相关的输出层名称。
 * `conf_threshold` (`float`): 检测到的手的置信度分数阈值。
 * `iou_threshold` (`float`): 非极大值抑制阈值。
 * `max_det` (`int`): 要保留的最大检测数量。
 * `scale` (`int`): 输入图像的比例。

##### build

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

配置解析器。

参数

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

返回

 * `MPPalmDetectionParser`: 设置了头部配置的解析器对象。

##### compute

```python
def compute(bboxes: np.ndarray, scores: np.ndarray, *, anchors: np.ndarray, conf_threshold: float, iou_threshold: float, max_det: int, scale: int, label_names: list[str] | None = None) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, list[str] | None]:
```

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

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

参数

 * `bboxes` (`np.ndarray`): 每个锚点的手掌框和地标预测。
 * `scores` (`np.ndarray`): 每个锚点的手掌分数 logits。
 * `anchors` (`np.ndarray`): 用于解码模型预测的预计算锚点坐标。
 * `conf_threshold` (`float`): 用于过滤候选的最小检测置信度。
 * `iou_threshold` (`float`): 非极大值抑制的交并比阈值。
 * `max_det` (`int`): 在抑制期间要保留或考虑的最大检测候选数量。
 * `scale` (`int`): 正方形模型输入的边长（像素）。
 * `label_names` (`list[str] | None`): 可选的按预测类别 ID 索引的类别名称查找。

返回

 * `tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, list[str] | None]`: 归一化的中心 XY/宽度/高度框、置信度分数、角度（度）、零值类别 ID 和可选的类别名称。

##### emit

```python
def emit(output: dai.NNData, bboxes: np.ndarray, scores: np.ndarray, angles: np.ndarray, labels: np.ndarray, label_names: list[str] | None):
```

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

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

参数

 * `output` (`dai.NNData`): 携带张量和源时间戳、序列号以及可选图像转换的神经网络输出。
 * `bboxes` (`np.ndarray`): `compute()` 返回的归一化中心 XY/宽度/高度框。
 * `scores` (`np.ndarray`): 与计算负载对应的置信度分数。
 * `angles` (`np.ndarray`): 与框对应的旋转角度（度）。
 * `labels` (`np.ndarray`): 与框对应的整数类别 ID。
 * `label_names` (`list[str] | None`): 与检测对应的可选类别名称。

##### extract

```python
def extract(output: dai.NNData) -> tuple[np.ndarray, np.ndarray]:
```

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

参数

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

返回

 * `tuple[np.ndarray, np.ndarray]`: 手掌框/地标预测重塑为 `(N, 18)` 和展平的分数，按其最终张量维度选择。

引发

 * `ValueError`: 如果没有可用的张量，或者框张量无法重塑为每个锚点 18 个值。

##### run

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

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

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

##### setOutputLayerNames

```python
def setOutputLayerNames(output_layer_names: list[str]):
```

设置解析器的输出层名称。

参数

 * `output_layer_names` (`list[str]`): 从中提取分数的输出层名称。

##### setScale

```python
def setScale(scale: int):
```

设置输入图像的比例。

参数

 * `scale` (`int`): 输入图像的比例。

#### 属性

##### conf_threshold

检测到的手的置信度分数阈值。

##### iou_threshold

非极大值抑制阈值。

##### label_names

##### max_det

要保留的最大检测数量。

##### output_layer_names

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

##### scale

输入图像的比例。
