# xfeat

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

## Classes

| Name | Description |
| --- | --- |
| [`XFeatBaseParser`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatBaseParser) | Base parser class for parsing the output of the XFeat model. It is the parent class of the XFeatMonoParser and XFeatStereoParser classes. |
| [`XFeatMonoParser`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatMonoParser) | Parser class for parsing the output of the XFeat model. It can be used for parsing the output from one source (e.g. one camera). The reference frame can be set with trigger method. |
| [`XFeatStereoParser`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatStereoParser) | Parser class for parsing the output of the XFeat model. It can be used for parsing the output from two sources (e.g. two cameras - left and right). |

### class `XFeatBaseParser`

```python
class XFeatBaseParser(BaseParser)
```

Base parser class for parsing the output of the XFeat model. It is the parent class of the XFeatMonoParser and XFeatStereoParser
classes.

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If the number of output layers is not 3. |
| `ValueError` | If the original image size is not specified. |
| `ValueError` | If the input image size is not specified. |
| `ValueError` | If the maximum number of keypoints is not specified. |
| `ValueError` | If the output layer containing features is not specified. |
| `ValueError` | If the output layer containing keypoints is not specified. |
| `ValueError` | If the output layer containing heatmaps is not specified. |

Attributes

| Name | Description |
| --- | --- |
| `input` |  |
| `input_size` | Input image size. |
| `max_keypoints` | Maximum number of keypoints to keep. |
| `original_size` | Original image size. |
| `output_layer_feats` | Name of the output layer containing features. |
| `output_layer_heatmaps` | Name of the output layer containing heatmaps. |
| `output_layer_keypoints` | Name of the output layer containing keypoints. |

Properties

| Name | Type | Description |
| --- | --- | --- |
| [`reference_input`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatBaseParser-reference_input) | `dai.Node.Input | None` | Returns the reference input. |
| [`target_input`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatBaseParser-target_input) | `dai.Node.Input | None` | Returns the target input. |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatBaseParser-__init__) | Store tensor names and image geometry for XFeat decoding. |
| [`build`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatBaseParser-build) | Configures the parser. |
| [`extractTensors`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatBaseParser-extractTensors) | Extracts the tensors from the output. It returns the features, keypoints, and heatmaps. It also handles the reshaping of the tensors by requesting the NCHW storage order. |
| [`reference_input.setter`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatBaseParser-reference_input.setter) | Replace the stored XFeat input port. |
| [`setInputSize`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatBaseParser-setInputSize) | Sets the input image size. |
| [`setMaxKeypoints`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatBaseParser-setMaxKeypoints) | Sets the maximum number of keypoints to keep. |
| [`setOriginalSize`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatBaseParser-setOriginalSize) | Sets the original image size. |
| [`setOutputLayerFeats`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatBaseParser-setOutputLayerFeats) | Sets the output layer containing features. |
| [`setOutputLayerHeatmaps`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatBaseParser-setOutputLayerHeatmaps) | Sets the output layer containing heatmaps. |
| [`setOutputLayerKeypoints`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatBaseParser-setOutputLayerKeypoints) | Sets the output layer containing keypoints. |
| [`target_input.setter`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatBaseParser-target_input.setter) | Replace the stored XFeat input port. |
| [`validateParams`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatBaseParser-validateParams) | Validates the parameters. |

#### property `reference_input`

```python
reference_input: dai.Node.Input | None
```

Returns the reference input.

#### property `target_input`

```python
target_input: dai.Node.Input | None
```

Returns the target input.

#### method `__init__`

```python
def __init__(
    output_layer_feats: str = '',
    output_layer_keypoints: str = '',
    output_layer_heatmaps: str = '',
    original_size: tuple[float, float] = None,
    input_size: tuple[float, float] = (640, 352),
    max_keypoints: int = 4096,
)
```

Store tensor names and image geometry for XFeat decoding.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_feats` | `str` | Feature-descriptor layer name. | `''` |
| `output_layer_keypoints` | `str` | Keypoint-logit layer name. | `''` |
| `output_layer_heatmaps` | `str` | Reliability heatmap layer name. | `''` |
| `original_size` | `tuple[float, float]` | Source image size as `(width, height)`. | `None` |
| `input_size` | `tuple[float, float]` | Model input size as `(width, height)`. | `(640, 352)` |
| `max_keypoints` | `int` | Maximum number of feature points to keep. | `4096` |

#### method `build`

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

Configures the parser.

Args

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

Returns

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

#### method `extractTensors`

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

Extracts the tensors from the output. It returns the features, keypoints, and heatmaps. It also handles the reshaping of the
tensors by requesting the NCHW storage order.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output` | `dai.NNData` | Output from the Neural Network node. | required |

Returns

| Type | Description |
| --- | --- |
| `tuple[np.ndarray, np.ndarray, np.ndarray]` | Tuple of features, keypoints, and heatmaps. |

#### method `reference_input.setter`

```python
def reference_input.setter(reference_input: dai.Node.Input | None)
```

Replace the stored XFeat input port.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `reference_input` | `dai.Node.Input | None` | Input port for the corresponding neural-network stream. | required |

#### method `setInputSize`

```python
def setInputSize(input_size: tuple[int, int])
```

Sets the input image size.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `input_size` | `tuple[int, int]` | Input image size. | required |

#### method `setMaxKeypoints`

```python
def setMaxKeypoints(max_keypoints: int)
```

Sets the maximum number of keypoints to keep.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `max_keypoints` | `int` | Maximum number of keypoints. | required |

#### method `setOriginalSize`

```python
def setOriginalSize(original_size: tuple[int, int])
```

Sets the original image size.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `original_size` | `tuple[int, int]` | Original image size. | required |

#### method `setOutputLayerFeats`

```python
def setOutputLayerFeats(output_layer_feats: str)
```

Sets the output layer containing features.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_feats` | `str` | Name of the output layer containing features. | required |

#### method `setOutputLayerHeatmaps`

```python
def setOutputLayerHeatmaps(output_layer_heatmaps: str)
```

Sets the output layer containing heatmaps.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_heatmaps` | `str` | Name of the output layer containing heatmaps. | required |

#### method `setOutputLayerKeypoints`

```python
def setOutputLayerKeypoints(output_layer_keypoints: str)
```

Sets the output layer containing keypoints.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_keypoints` | `str` | Name of the output layer containing keypoints. | required |

#### method `target_input.setter`

```python
def target_input.setter(target_input: dai.Node.Input | None)
```

Replace the stored XFeat input port.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `target_input` | `dai.Node.Input | None` | Input port for the corresponding neural-network stream. | required |

#### method `validateParams`

```python
def validateParams()
```

Validates the parameters.

### class `XFeatMonoParser`

```python
class XFeatMonoParser(XFeatBaseParser)
```

Parser class for parsing the output of the XFeat model. It can be used for parsing the output from one source (e.g. one camera).
The reference frame can be set with trigger method.

> **Note**
> Emits `dai.TrackedFeatures` messages. TrackedFeatures message containing matched keypoints with the same ID.

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If the original image size is not specified. |
| `ValueError` | If the input image size is not specified. |
| `ValueError` | If the maximum number of keypoints is not specified. |
| `ValueError` | If the output layer containing features is not specified. |
| `ValueError` | If the output layer containing keypoints is not specified. |
| `ValueError` | If the output layer containing heatmaps is not specified. |

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `input_size` |  | Input image size. |
| `max_keypoints` |  | Maximum number of keypoints to keep. |
| `original_size` |  | Original image size. |
| `output_layer_feats` |  | Name of the output layer containing features. |
| `output_layer_heatmaps` |  | Name of the output layer containing heatmaps. |
| `output_layer_keypoints` |  | Name of the output layer containing keypoints. |
| `previous_results` |  | Previous results from the model. Previous results are used to match keypoints between two frames. |
| `trigger` | `bool` | Trigger to set the reference frame. |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatMonoParser-__init__) | Initializes the XFeatParser node. |
| [`compute`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatMonoParser-compute) | Compute features for the first batch item. |
| [`emit`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatMonoParser-emit) | Match features against the stored reference and emit tracked points. |
| [`extract`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatMonoParser-extract) | Extract feature, keypoint, and heatmap tensors from one network result. |
| [`run`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatMonoParser-run) | Read queued network outputs, parse them, and emit results while running. |
| [`setTrigger`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatMonoParser-setTrigger) | Sets the trigger to set the reference frame. |

#### method `__init__`

```python
def __init__(
    output_layer_feats: str = 'feats',
    output_layer_keypoints: str = 'keypoints',
    output_layer_heatmaps: str = 'heatmaps',
    original_size: tuple[float, float] = None,
    input_size: tuple[float, float] = (640, 352),
    max_keypoints: int = 4096,
)
```

Initializes the XFeatParser node.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_feats` | `str` | Name of the output layer containing features. | `'feats'` |
| `output_layer_keypoints` | `str` | Name of the output layer containing keypoints. | `'keypoints'` |
| `output_layer_heatmaps` | `str` | Name of the output layer containing heatmaps. | `'heatmaps'` |
| `original_size` | `tuple[float, float]` | Original image size. | `None` |
| `input_size` | `tuple[float, float]` | Input image size. | `(640, 352)` |
| `max_keypoints` | `int` | Maximum number of keypoints to keep. | `4096` |

#### method `compute`

```python
def compute(
    feats: np.ndarray,
    keypoints: np.ndarray,
    heatmaps: np.ndarray,
    *,
    resize_rate_w: float,
    resize_rate_h: float,
) -> dict[str, Any] | None
```

Compute features for the first batch item.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `feats` | `np.ndarray` | Batched dense feature-descriptor tensor. | required |
| `keypoints` | `np.ndarray` | Model keypoint tensor. | required |
| `heatmaps` | `np.ndarray` | Model heatmap tensor. | required |
| `resize_rate_w` | `float` | Horizontal scale factor mapping model coordinates to the source image. | required |
| `resize_rate_h` | `float` | Vertical scale factor mapping model coordinates to the source image. | required |

Returns

| Type | Description |
| --- | --- |
| `dict[str, Any] | None` | A dictionary containing keypoints, scores, and descriptors for the first image, or `None` when no candidates are found. |

#### method `emit`

```python
def emit(output: dai.NNData, result: dict[str, Any] | None)
```

Match features against the stored reference and emit tracked points.

> **Note**
> Emits an empty message if no current features or no reference is available. Copies current timestamps and sequence number. A pending trigger replaces the stored reference with a non-None result after matching.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output` | `dai.NNData` | Neural network output carrying tensors and source timestamps, sequence number, and optional image transformation. | required |
| `result` | `dict[str, Any] | None` | Current computed keypoints, scores, and descriptors, or `None`. | required |

#### method `extract`

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

Extract feature, keypoint, and heatmap tensors from one network result.

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, np.ndarray]` | A tuple of feature descriptors, keypoint logits, and heatmaps, as produced by `extractTensors()`. |

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

```python
def setTrigger()
```

Sets the trigger to set the reference frame.

### class `XFeatStereoParser`

```python
class XFeatStereoParser(XFeatBaseParser)
```

Parser class for parsing the output of the XFeat model. It can be used for parsing the output from two sources (e.g. two cameras -
left and right).

> **Note**
> Emits `dai.TrackedFeatures` messages. TrackedFeatures message containing matched keypoints with the same ID.

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If the original image size is not specified. |
| `ValueError` | If the input image size is not specified. |
| `ValueError` | If the maximum number of keypoints is not specified. |
| `ValueError` | If the output layer containing features is not specified. |
| `ValueError` | If the output layer containing keypoints is not specified. |
| `ValueError` | If the output layer containing heatmaps is not specified. |

Attributes

| Name | Description |
| --- | --- |
| `input_size` | Input image size. |
| `max_keypoints` | Maximum number of keypoints to keep. |
| `original_size` | Original image size. |
| `out` | Parser sends the processed network results to this output in a form of DepthAI message. It is a linking point from which the processed network results are retrieved. |
| `output_layer_feats` | Name of the output layer from which the features are extracted. |
| `output_layer_heatmaps` | Name of the output layer from which the heatmaps are extracted. |
| `output_layer_keypoints` | Name of the output layer from which the keypoints are extracted. |
| `reference_input` | Node's input. It is a linking point to which the Neural Network's output is linked. It accepts the output of the Neural Network node. |
| `target_input` | Node's input. It is a linking point to which the Neural Network's output is linked. It accepts the output of the Neural Network node. |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatStereoParser-__init__) | Initializes the XFeatParser node. |
| [`compute`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatStereoParser-compute) | Compute and match features between reference and target tensors. |
| [`emit`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatStereoParser-emit) | Emit matched reference and target points, or an empty feature message. |
| [`extract`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatStereoParser-extract) | Extract matching tensors from both network results. |
| [`run`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/xfeat.md#xfeat-Classes-XFeatStereoParser-run) | Read queued network outputs, parse them, and emit results while running. |

#### method `__init__`

```python
def __init__(
    output_layer_feats: str = 'feats',
    output_layer_keypoints: str = 'keypoints',
    output_layer_heatmaps: str = 'heatmaps',
    original_size: tuple[float, float] = None,
    input_size: tuple[float, float] = (640, 352),
    max_keypoints: int = 4096,
)
```

Initializes the XFeatParser node.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_feats` | `str` | Name of the output layer containing features. | `'feats'` |
| `output_layer_keypoints` | `str` | Name of the output layer containing keypoints. | `'keypoints'` |
| `output_layer_heatmaps` | `str` | Name of the output layer containing heatmaps. | `'heatmaps'` |
| `original_size` | `tuple[float, float]` | Original image size. | `None` |
| `input_size` | `tuple[float, float]` | Input image size. | `(640, 352)` |
| `max_keypoints` | `int` | Maximum number of keypoints to keep. | `4096` |

#### method `compute`

```python
def compute(
    reference_tensors: tuple[np.ndarray, np.ndarray, np.ndarray],
    target_tensors: tuple[np.ndarray, np.ndarray, np.ndarray],
    *,
    resize_rate_w: float,
    resize_rate_h: float,
) -> dict[str, tuple[np.ndarray, np.ndarray] | str | None]
```

Compute and match features between reference and target tensors.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `reference_tensors` | `tuple[np.ndarray, np.ndarray, np.ndarray]` | Reference feature, keypoint, and heatmap tensors. | required |
| `target_tensors` | `tuple[np.ndarray, np.ndarray, np.ndarray]` | Target feature, keypoint, and heatmap tensors. | required |
| `resize_rate_w` | `float` | Horizontal scale factor applied to keypoint coordinates. | required |
| `resize_rate_h` | `float` | Vertical scale factor applied to keypoint coordinates. | required |

Returns

| Type | Description |
| --- | --- |
| `dict[str, tuple[np.ndarray, np.ndarray] | str | None]` | Dictionary with `status` (`matched`, `reference_missing`, or `target_missing`) and `match_result` (paired point arrays, or `None`). |

#### method `emit`

```python
def emit(
    reference_output: dai.NNData,
    target_output: dai.NNData,
    result: dict[str, tuple[np.ndarray, np.ndarray] | str | None],
)
```

Emit matched reference and target points, or an empty feature message.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `reference_output` | `dai.NNData` | Supplies the sequence number and, if reference features are missing, timestamps. | required |
| `target_output` | `dai.NNData` | Supplies timestamps for matches and missing target features. | required |
| `result` | `dict[str, tuple[np.ndarray, np.ndarray] | str | None]` | Status and paired points returned by `compute()`. | required |

#### method `extract`

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

Extract matching tensors from both network results.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `reference_output` | `dai.NNData` | Reference-image network output. | required |
| `target_output` | `dai.NNData` | Target-image network output. | required |

Returns

| Type | Description |
| --- | --- |
| `tuple[tuple[np.ndarray, np.ndarray, np.ndarray], tuple[np.ndarray, np.ndarray, np.ndarray]]` | Reference and target tuples, each containing features, keypoint logits, and heatmaps. |

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