# mlsd

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

## Functions

| Name | Description |
| --- | --- |
| [`compute_mlsd_lines`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/mlsd.md#mlsd-Functions-compute_mlsd_lines) | Decode line segments from M-LSD displacement and heat tensors. |
| [`decode_scores_and_points`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/mlsd.md#mlsd-Functions-decode_scores_and_points) | Decode the scores and points from the neural network output tensors. Used for MLSD model. |
| [`get_lines`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/mlsd.md#mlsd-Functions-get_lines) | Get lines from the detected points and scores. The lines are filtered by the score threshold and distance threshold. Used for MLSD model. |

### function `compute_mlsd_lines`

```python
def compute_mlsd_lines(
    tpMap: np.ndarray,
    heat: np.ndarray,
    *,
    topk_n: int,
    score_thr: float,
    dist_thr: float,
) -> tuple[np.ndarray, np.ndarray]
```

Decode line segments from M-LSD displacement and heat tensors.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `tpMap` | `np.ndarray` | Four-dimensional line-displacement tensor in NCHW layout. | required |
| `heat` | `np.ndarray` | Heat tensor used to rank line-center candidates. | required |
| `topk_n` | `int` | Maximum number of line-center candidates to examine. | required |
| `score_thr` | `float` | Minimum candidate score. | required |
| `dist_thr` | `float` | Minimum line length in output-map pixels. | required |

Returns

| Type | Description |
| --- | --- |
| `tuple[np.ndarray, np.ndarray]` | Normalized endpoint coordinates of shape `(N, 4)` and float32 line scores. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If `tpMap` is not four-dimensional. |

### function `decode_scores_and_points`

```python
def decode_scores_and_points(
    tpMap: np.ndarray,
    heat: np.ndarray,
    topk_n: int,
) -> tuple[np.ndarray, np.ndarray, np.ndarray]
```

Decode the scores and points from the neural network output tensors. Used for MLSD model.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `tpMap` | `np.ndarray` | Tensor containing the vector map. | required |
| `heat` | `np.ndarray` | Tensor containing the heat map. | required |
| `topk_n` | `int` | Number of top candidates to keep. | required |

Returns

| Type | Description |
| --- | --- |
| `tuple[np.ndarray, np.ndarray, np.ndarray]` | Detected points, confidence scores for the detected points, and vector map. |

### function `get_lines`

```python
def get_lines(
    pts: np.ndarray,
    pts_score: np.ndarray,
    vmap: np.ndarray,
    score_thr: float,
    dist_thr: float,
    input_size: int = 512,
) -> tuple[np.ndarray, list[float]]
```

Get lines from the detected points and scores. The lines are filtered by the score threshold and distance threshold. Used for MLSD
model.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `pts` | `np.ndarray` | Detected points. | required |
| `pts_score` | `np.ndarray` | Confidence scores for the detected points. | required |
| `vmap` | `np.ndarray` | Vector map. | required |
| `score_thr` | `float` | Confidence score threshold for detected lines. | required |
| `dist_thr` | `float` | Minimum line length in output-map pixels. | required |
| `input_size` | `int` | Input size of the model. | `512` |

Returns

| Type | Description |
| --- | --- |
| `tuple[np.ndarray, list[float]]` | Detected lines and their confidence scores. |
