# mlsd

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

## Classes

| Name | Description |
| --- | --- |
| [`MLSDParser`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/mlsd.md#mlsd-Classes-MLSDParser) | Parser class for parsing the output of the M-LSD line detection model. The parser is specifically designed to parse the output of the M-LSD model. As the result, the node sends out the detected lines in the form of a message. |

### class `MLSDParser`

```python
class MLSDParser(BaseParser)
```

Parser class for parsing the output of the M-LSD line detection model. The parser is specifically designed to parse the output of
the M-LSD model. As the result, the node sends out the detected lines in the form of a message.

> **Note**
> Emits `dai.beta.Lines` messages. Native message containing detected lines and confidence scores.

Attributes

| Name | Description |
| --- | --- |
| `dist_thr` | Minimum line length in output-map pixels. |
| `output_layer_heat` | Name of the output layer containing the heat tensor. |
| `output_layer_tpmap` | Name of the output layer containing the tpMap tensor. |
| `score_thr` | Confidence score threshold for detected lines. |
| `topk_n` | Number of top candidates to keep. |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/mlsd.md#mlsd-Classes-MLSDParser-__init__) | Initializes the parser node. |
| [`build`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/mlsd.md#mlsd-Classes-MLSDParser-build) | Configures the parser. |
| [`compute`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/mlsd.md#mlsd-Classes-MLSDParser-compute) | Compute parser results from extracted tensors without sending messages. |
| [`emit`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/mlsd.md#mlsd-Classes-MLSDParser-emit) | Create a `dai.beta.Lines` message and send it on `out`. |
| [`extract`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/mlsd.md#mlsd-Classes-MLSDParser-extract) | Select and dequantize the model tensors needed for parsing. |
| [`run`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/mlsd.md#mlsd-Classes-MLSDParser-run) | Read queued network outputs, parse them, and emit results while running. |
| [`setDistanceThreshold`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/mlsd.md#mlsd-Classes-MLSDParser-setDistanceThreshold) | Sets the distance threshold for merging lines. |
| [`setOutputLayerHeat`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/mlsd.md#mlsd-Classes-MLSDParser-setOutputLayerHeat) | Sets the name of the output layer containing the heat tensor. |
| [`setOutputLayerTPMap`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/mlsd.md#mlsd-Classes-MLSDParser-setOutputLayerTPMap) | Sets the name of the output layer containing the tpMap tensor. |
| [`setScoreThreshold`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/mlsd.md#mlsd-Classes-MLSDParser-setScoreThreshold) | Sets the confidence score threshold for detected lines. |
| [`setTopK`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/mlsd.md#mlsd-Classes-MLSDParser-setTopK) | Sets the number of top candidates to keep. |

#### method `__init__`

```python
def __init__(
    output_layer_tpmap: str = '',
    output_layer_heat: str = '',
    topk_n: int = 200,
    score_thr: float = 0.1,
    dist_thr: float = 20.0,
)
```

Initializes the parser node.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_tpmap` | `str` | Name of the output tensor containing line displacements. | `''` |
| `output_layer_heat` | `str` | Name of the output tensor containing the heatmap. | `''` |
| `topk_n` | `int` | Number of top candidates to keep. | `200` |
| `score_thr` | `float` | Confidence score threshold for detected lines. | `0.1` |
| `dist_thr` | `float` | Minimum line length in output-map pixels. | `20.0` |

#### method `build`

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

Configures the parser.

Args

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

Returns

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

#### static method `compute`

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

Compute parser results from extracted tensors without sending messages.

> **Note**
> Uses [depthai_nodes.node.parsers.utils.mlsd.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); see that helper for tensor layout and validation details.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `tpMap` | `np.ndarray` | Four-dimensional line-displacement tensor in NCHW layout. | required |
| `heat_np` | `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. |

#### method `emit`

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

Create a `dai.beta.Lines` message and send it on `out`.

Copies source timestamps and sequence number, and carries the source image transformation when present.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output` | `dai.NNData` | Neural network output carrying tensors and source timestamps, sequence number, and optional image transformation. | required |
| `lines` | `np.ndarray` | Normalized `[x1, y1, x2, y2]` line endpoints. | required |
| `scores` | `np.ndarray` | Confidence scores corresponding to the computed payload. | required |

#### method `extract`

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

Select and dequantize the model tensors needed for parsing.

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]` | Float32 displacement and heat tensors. Displacement is requested in NCHW order. |

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

```python
def setDistanceThreshold(dist_thr: float)
```

Sets the distance threshold for merging lines.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `dist_thr` | `float` | Minimum line length in output-map pixels. | required |

#### method `setOutputLayerHeat`

```python
def setOutputLayerHeat(output_layer_heat: str)
```

Sets the name of the output layer containing the heat tensor.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_heat` | `str` | Name of the output layer containing the heat tensor. | required |

#### method `setOutputLayerTPMap`

```python
def setOutputLayerTPMap(output_layer_tpmap: str)
```

Sets the name of the output layer containing the tpMap tensor.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_tpmap` | `str` | Name of the output layer containing the tpMap tensor. | required |

#### method `setScoreThreshold`

```python
def setScoreThreshold(score_thr: float)
```

Sets the confidence score threshold for detected lines.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `score_thr` | `float` | Confidence score threshold for detected lines. | required |

#### method `setTopK`

```python
def setTopK(topk_n: int)
```

Sets the number of top candidates to keep.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `topk_n` | `int` | Number of top candidates to keep. | required |
