# superanimal_landmarker

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

## Classes

### SuperAnimalParser

Parser class for parsing the output of the SuperAnimal landmark model.

> **Note**
> Emits `dai.beta.Keypoints` messages. Output containing detected keypoints that exceed the confidence threshold.

#### Methods

##### init

```python
def __init__(output_layer_name: str = '', scale_factor: float = 256.0, n_keypoints: int = 39, score_threshold: float = 0.5, label_names: list[str] | None = None, edges: list[tuple[int, int]] | None = None):
```

Initializes the parser node.

Parameters

 * `output_layer_name` (`str`): Name of the output layer relevant to the parser.
 * `scale_factor` (`float`): Scale factor to divide the keypoints by.
 * `n_keypoints` (`int`): Number of keypoints.
 * `score_threshold` (`float`): Confidence score threshold for detected keypoints.
 * `label_names` (`list[str] | None`): Label names for the keypoints.
 * `edges` (`list[tuple[int, int]] | None`): Pairs of keypoint indexes defining skeleton edges. For example, `[(0, 1), (1, 2)]`
   connects keypoint 0 to 1 and 1 to 2.

##### build

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

Configures the parser.

Parameters

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

Returns

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

##### compute

```python
def compute(heatmaps: np.ndarray, *, scale_factor: float) -> tuple[np.ndarray, np.ndarray]:
```

Compute parser results from extracted tensors without sending messages.

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

Parameters

 * `heatmaps` (`np.ndarray`): Model heatmap tensor.
 * `scale_factor` (`float`): Nonzero divisor used to convert model coordinates to normalized coordinates.

Returns

 * `tuple[np.ndarray, np.ndarray]`: A pair of `(N, 2)` keypoint coordinates and `(N,)` scores. Coordinates are divided by
   `scale_factor`.

##### emit

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

Create a `dai.beta.Keypoints` 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.
 * `keypoints` (`np.ndarray`): Normalized keypoint coordinates returned by `compute()`.
 * `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 float32 heatmaps in the model tensor layout.

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.

#### Attributes

##### edges

Pairs of keypoint indexes defining skeleton edges. For example, `[(0, 1), (1, 2)]` connects keypoint 0 to 1 and 1 to 2.

##### label_names

Label names for the keypoints.

##### n_keypoints

Number of keypoints.

##### output_layer_name

Name of the output layer relevant to the parser.

##### scale_factor

Scale factor to divide the keypoints by.

##### score_threshold

Confidence score threshold for detected keypoints.
