# mlsd

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

## Functions

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

Parameters

 * `tpMap` (`np.ndarray`): Four-dimensional line-displacement tensor in NCHW layout.
 * `heat` (`np.ndarray`): Heat tensor used to rank line-center candidates.
 * `topk_n` (`int`): Maximum number of line-center candidates to examine.
 * `score_thr` (`float`): Minimum candidate score.
 * `dist_thr` (`float`): Minimum line length in output-map pixels.

Returns

 * `tuple[np.ndarray, np.ndarray]`: Normalized endpoint coordinates of shape `(N, 4)` and float32 line scores.

Raises

 * `ValueError`: If `tpMap` is not four-dimensional.

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

Parameters

 * `tpMap` (`np.ndarray`): Tensor containing the vector map.
 * `heat` (`np.ndarray`): Tensor containing the heat map.
 * `topk_n` (`int`): Number of top candidates to keep.

Returns

 * `tuple[np.ndarray, np.ndarray, np.ndarray]`: Detected points, confidence scores for the detected points, and vector map.

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

Parameters

 * `pts` (`np.ndarray`): Detected points.
 * `pts_score` (`np.ndarray`): Confidence scores for the detected points.
 * `vmap` (`np.ndarray`): Vector map.
 * `score_thr` (`float`): Confidence score threshold for detected lines.
 * `dist_thr` (`float`): Minimum line length in output-map pixels.
 * `input_size` (`int`): Input size of the model.

Returns

 * `tuple[np.ndarray, list[float]]`: Detected lines and their confidence scores.
