# mediapipe_palm_detection

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

## Classes

| Name | Description |
| --- | --- |
| [`MPPalmDetectionParser`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/mediapipe_palm_detection.md#mediapipe_palm_detection-Classes-MPPalmDetectionParser) | Parser class for parsing the output of the Mediapipe Palm detection model. As the result, the node sends out the detected hands in the form of a message containing bounding boxes, labels, and confidence scores. |

### class `MPPalmDetectionParser`

```python
class MPPalmDetectionParser(DetectionParser)
```

Parser class for parsing the output of the Mediapipe Palm detection model. As the result, the node sends out the detected hands in
the form of a message containing bounding boxes, labels, and confidence scores.

> **Note**
> Emits `dai.ImgDetections` messages. dai.ImgDetections message containing bounding boxes, labels, and confidence scores of detected hands.

See also:

Official MediaPipe Hands solution:
[https://ai.google.dev/edge/mediapipe/solutions/vision/hand_landmarker](https://ai.google.dev/edge/mediapipe/solutions/vision/hand_landmarker)

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `conf_threshold` |  | Confidence score threshold for detected hands. |
| `iou_threshold` |  | Non-maximum suppression threshold. |
| `label_names` | `list[str]` |  |
| `max_det` |  | Maximum number of detections to keep. |
| `output_layer_names` |  | Names of the output layers relevant to the parser. |
| `scale` |  | Scale of the input image. |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/mediapipe_palm_detection.md#mediapipe_palm_detection-Classes-MPPalmDetectionParser-__init__) | Initializes the parser node. |
| [`build`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/mediapipe_palm_detection.md#mediapipe_palm_detection-Classes-MPPalmDetectionParser-build) | Configures the parser. |
| [`compute`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/mediapipe_palm_detection.md#mediapipe_palm_detection-Classes-MPPalmDetectionParser-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/mediapipe_palm_detection.md#mediapipe_palm_detection-Classes-MPPalmDetectionParser-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/mediapipe_palm_detection.md#mediapipe_palm_detection-Classes-MPPalmDetectionParser-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/mediapipe_palm_detection.md#mediapipe_palm_detection-Classes-MPPalmDetectionParser-run) | Read queued network outputs, parse them, and emit results while running. |
| [`setOutputLayerNames`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/mediapipe_palm_detection.md#mediapipe_palm_detection-Classes-MPPalmDetectionParser-setOutputLayerNames) | Sets the output layer name(s) for the parser. |
| [`setScale`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/mediapipe_palm_detection.md#mediapipe_palm_detection-Classes-MPPalmDetectionParser-setScale) | Sets the scale of the input image. |

#### method `__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,
)
```

Initializes the parser node.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_names` | `list[str]` | Names of the output layers relevant to the parser. | `None` |
| `conf_threshold` | `float` | Confidence score threshold for detected hands. | `0.5` |
| `iou_threshold` | `float` | Non-maximum suppression threshold. | `0.5` |
| `max_det` | `int` | Maximum number of detections to keep. | `100` |
| `scale` | `int` | Scale of the input image. | `192` |

#### method `build`

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

Configures the parser.

Args

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

Returns

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

#### static method `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]
```

Compute parser results from extracted tensors without sending messages.

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

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `bboxes` | `np.ndarray` | Per-anchor palm box and landmark predictions. | required |
| `scores` | `np.ndarray` | Per-anchor palm score logits. | required |
| `anchors` | `np.ndarray` | Precomputed anchor coordinates used to decode model predictions. | required |
| `conf_threshold` | `float` | Minimum detection confidence used to filter candidates. | required |
| `iou_threshold` | `float` | Intersection-over-union threshold for non-maximum suppression. | required |
| `max_det` | `int` | Maximum number of detection candidates to retain or consider during suppression. | required |
| `scale` | `int` | Side length of the square model input in pixels. | required |
| `label_names` | `list[str] | None` | Optional class-name lookup indexed by predicted class ID. | `None` |

Returns

| Type | Description |
| --- | --- |
| `tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, list[str] | None]` | Normalized center-XY/width/height boxes, confidence scores, angles in degrees, zero-valued class IDs, and optional class names. |

#### method `emit`

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

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 |
| `scores` | `np.ndarray` | Confidence scores corresponding to the computed payload. | required |
| `angles` | `np.ndarray` | Rotation angles in degrees corresponding to the boxes. | required |
| `labels` | `np.ndarray` | Integer class IDs corresponding to the boxes. | required |
| `label_names` | `list[str] | None` | Optional class names corresponding to the detections. | required |

#### method `extract`

```python
def extract(output: dai.NNData) -> tuple[np.ndarray, 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 |
| --- | --- |
| `tuple[np.ndarray, np.ndarray]` | Palm box/landmark predictions reshaped to `(N, 18)` and flattened scores, selected by their final tensor dimensions. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If no tensors are available or box tensors cannot be reshaped to 18 values per anchor. |

#### 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 `setOutputLayerNames`

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

Sets the output layer name(s) for the parser.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_names` | `list[str]` | The name of the output layer(s) from which the scores are extracted. | required |

#### method `setScale`

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

Sets the scale of the input image.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `scale` | `int` | Scale of the input image. | required |
