# xfeat

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

## Functions

| Name | Description |
| --- | --- |
| [`bilinear`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/xfeat.md#xfeat-Functions-bilinear) | Given an input and a flow-field grid, computes the output using input values and pixel locations from grid. Supported only bilinear interpolation method to sample the input pixels. |
| [`compute_xfeat_matches`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/xfeat.md#xfeat-Functions-compute_xfeat_matches) | Match XFeat descriptors by mutual nearest-neighbor similarity. |
| [`compute_xfeat_result`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/xfeat.md#xfeat-Functions-compute_xfeat_result) | Compute ranked XFeat keypoints and descriptors. |
| [`detect_and_compute`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/xfeat.md#xfeat-Functions-detect_and_compute) | Detect and compute keypoints. |
| [`local_maximum_filter`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/xfeat.md#xfeat-Functions-local_maximum_filter) | Apply a local maximum filter to the input array. |
| [`match`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/xfeat.md#xfeat-Functions-match) | Match keypoints. |
| [`normgrid`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/xfeat.md#xfeat-Functions-normgrid) | Normalize coords to [-1,1]. |

### function `bilinear`

```python
def bilinear(im, pos, H, W)
```

Given an input and a flow-field grid, computes the output using input values and pixel locations from grid. Supported only
bilinear interpolation method to sample the input pixels.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `im` | `np.ndarray` | Input feature map, shape (N, C, H, W) | required |
| `pos` | `np.ndarray` | Point coordinates, shape (N, Hg, Wg, 2) | required |
| `H` | `int` | Height of the output feature map | required |
| `W` | `int` | Width of the output feature map | required |

Returns

| Type | Description |
| --- | --- |
| `np.ndarray` | A tensor with sampled points, shape (N, C, Hg, Wg) |

### function `compute_xfeat_matches`

```python
def compute_xfeat_matches(
    result1: dict[str, Any],
    result2: dict[str, Any],
    min_cossim: float = -1,
) -> tuple[np.ndarray, np.ndarray]
```

Match XFeat descriptors by mutual nearest-neighbor similarity.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `result1` | `dict[str, Any]` | Reference result containing `keypoints` and `descriptors`. | required |
| `result2` | `dict[str, Any]` | Target result containing `keypoints` and `descriptors`. | required |
| `min_cossim` | `float` | Minimum descriptor cosine similarity; a non-positive value disables this threshold. | `-1` |

Returns

| Type | Description |
| --- | --- |
| `tuple[np.ndarray, np.ndarray]` | Reference and target keypoint arrays of shape `(N, 2)` in corresponding order. |

### function `compute_xfeat_result`

```python
def compute_xfeat_result(
    feats: np.ndarray,
    keypoints: np.ndarray,
    heatmaps: np.ndarray,
    *,
    resize_rate_w: float,
    resize_rate_h: float,
    input_size: tuple[int, int],
    max_keypoints: int,
) -> list[dict[str, Any]] | None
```

Compute ranked XFeat keypoints and descriptors.

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 |
| `input_size` | `tuple[int, int]` | Model input size as `(width, height)`. | required |
| `max_keypoints` | `int` | Maximum number of highest-scoring keypoints retained per image. | required |

Returns

| Type | Description |
| --- | --- |
| `list[dict[str, Any]] | None` | One result dictionary per batch item, with `keypoints`, `scores`, and `descriptors`. Returns `None` when no candidate keypoints are found. |

### function `detect_and_compute`

```python
def detect_and_compute(
    feats: np.ndarray,
    kpts: np.ndarray,
    heatmaps: np.ndarray,
    resize_rate_w: float,
    resize_rate_h: float,
    input_size: tuple[int, int],
    top_k: int = 4096,
) -> list[dict[str, Any]]
```

Detect and compute keypoints.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `feats` | `np.ndarray` | Features. | required |
| `kpts` | `np.ndarray` | Keypoints. | required |
| `heatmaps` | `np.ndarray` | Heatmaps. | required |
| `resize_rate_w` | `float` | Resize rate for width. | required |
| `resize_rate_h` | `float` | Resize rate for height. | required |
| `input_size` | `tuple[int, int]` | Input size. | required |
| `top_k` | `int` | Maximum number of keypoints to keep. | `4096` |

Returns

| Type | Description |
| --- | --- |
| `list[dict[str, Any]]` | List of dictionaries containing keypoints, scores, and descriptors. |

### function `local_maximum_filter`

```python
def local_maximum_filter(x: np.ndarray, kernel_size: int) -> np.ndarray
```

Apply a local maximum filter to the input array.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `x` | `np.ndarray` | Input array. | required |
| `kernel_size` | `int` | Size of the local maximum filter. | required |

Returns

| Type | Description |
| --- | --- |
| `np.ndarray` | Output array after applying the local maximum filter. |

### function `match`

```python
def match(
    result1: dict[str, Any],
    result2: dict[str, Any],
    min_cossim: float = -1,
) -> tuple[np.ndarray, np.ndarray]
```

Match keypoints.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `result1` | `dict[str, Any]` | Result 1. | required |
| `result2` | `dict[str, Any]` | Result 2. | required |
| `min_cossim` | `float` | Minimum cosine similarity. | `-1` |

Returns

| Type | Description |
| --- | --- |
| `tuple[np.ndarray, np.ndarray]` | Matched keypoints. |

### function `normgrid`

```python
def normgrid(x, H, W)
```

Normalize coords to [-1,1].

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `x` | `np.ndarray` | Input coordinates, shape (N, Hg, Wg, 2) | required |
| `H` | `int` | Height of the output feature map | required |
| `W` | `int` | Width of the output feature map | required |

Returns

| Type | Description |
| --- | --- |
| `np.ndarray` | Normalized coordinates, shape (N, Hg, Wg, 2) |
