# lane_detection

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

## Classes

| Name | Description |
| --- | --- |
| [`LaneDetectionParser`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/lane_detection.md#lane_detection-Classes-LaneDetectionParser) | Parser class for Ultra-Fast-Lane-Detection model. It expects one output layer containing the lane detection results. It supports two versions of the model: CuLane and TuSimple. Results are representented with clusters of points. |

### class `LaneDetectionParser`

```python
class LaneDetectionParser(BaseParser)
```

Parser class for Ultra-Fast-Lane-Detection model. It expects one output layer containing the lane detection results. It supports
two versions of the model: CuLane and TuSimple. Results are representented with clusters of points.

Output messages:

Type: dai.beta.Clusters Description: Detected lanes represented as clusters of points.

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If the row anchors are not specified. |
| `ValueError` | If the griding number is not specified. |
| `ValueError` | If the number of points per lane is not specified. |

Attributes

| Name | Description |
| --- | --- |
| `cls_num_per_lane` | Number of points per lane. |
| `griding_num` | Griding number. |
| `input_shape` |  |
| `input_size` | Input size (width,height). |
| `layout` |  |
| `output_layer_name` | Name of the output layer relevant to the parser. |
| `row_anchors` | List of row anchors. |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/lane_detection.md#lane_detection-Classes-LaneDetectionParser-__init__) | Initializes the lane detection parser node. |
| [`build`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/lane_detection.md#lane_detection-Classes-LaneDetectionParser-build) | Configures the parser. |
| [`compute`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/lane_detection.md#lane_detection-Classes-LaneDetectionParser-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/lane_detection.md#lane_detection-Classes-LaneDetectionParser-emit) | Create a `dai.beta.Clusters` message and send it on `out`. |
| [`extract`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/lane_detection.md#lane_detection-Classes-LaneDetectionParser-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/lane_detection.md#lane_detection-Classes-LaneDetectionParser-run) | Read queued network outputs, parse them, and emit results while running. |
| [`setClsNumPerLane`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/lane_detection.md#lane_detection-Classes-LaneDetectionParser-setClsNumPerLane) | Set the number of points per lane for the lane detection model. |
| [`setGridingNum`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/lane_detection.md#lane_detection-Classes-LaneDetectionParser-setGridingNum) | Set the griding number for the lane detection model. |
| [`setInputSize`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/lane_detection.md#lane_detection-Classes-LaneDetectionParser-setInputSize) | Set the input size for the lane detection model. |
| [`setOutputLayerName`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/lane_detection.md#lane_detection-Classes-LaneDetectionParser-setOutputLayerName) | Set the output layer name for the lane detection model. |
| [`setRowAnchors`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/lane_detection.md#lane_detection-Classes-LaneDetectionParser-setRowAnchors) | Set the row anchors for the lane detection model. |

#### method `__init__`

```python
def __init__(
    output_layer_name: str = '',
    row_anchors: list[int] = None,
    griding_num: int = None,
    cls_num_per_lane: int = None,
    input_size: tuple[int, int] = None,
)
```

Initializes the lane detection parser node.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_name` | `str` | Name of the output layer relevant to the parser. | `''` |
| `row_anchors` | `list[int]` | List of row anchors. | `None` |
| `griding_num` | `int` | Griding number. | `None` |
| `cls_num_per_lane` | `int` | Number of points per lane. | `None` |
| `input_size` | `tuple[int, int]` | Input size (width,height). | `None` |

#### method `build`

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

Configures the parser.

Args

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

Returns

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

#### static method `compute`

```python
def compute(
    tensor: np.ndarray,
    *,
    row_anchors: list[int],
    griding_num: int,
    cls_num_per_lane: int,
    input_size: tuple[int, int],
) -> list[list[tuple[int, int]]]
```

Compute parser results from extracted tensors without sending messages.

> **Note**
> Uses [depthai_nodes.node.parsers.utils.lane_detection.compute_lane_detection_points](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/lane_detection.md#lane_detection-Functions-compute_lane_detection_points); see that helper for tensor layout and validation details.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `tensor` | `np.ndarray` | Batched logits with grid classes, sampled rows, and lanes as the remaining axes; only the first batch item is used. | required |
| `row_anchors` | `list[int]` | Image row positions, in pixels, for the lane sampling grid. | required |
| `griding_num` | `int` | Number of horizontal grid cells, excluding the no-lane class. | required |
| `cls_num_per_lane` | `int` | Number of sampled row positions per lane. | required |
| `input_size` | `tuple[int, int]` | Model input size as `(width, height)`. | required |

Returns

| Type | Description |
| --- | --- |
| `list[list[tuple[int, int]]]` | One list per lane containing normalized XY point tuples. Lanes with fewer than three valid samples have empty lists. |

#### method `emit`

```python
def emit(output: dai.NNData, points)
```

Create a `dai.beta.Clusters` 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 |
| `points` |  | Lists of normalized XY points, one list per lane. | required |

#### method `extract`

```python
def extract(output: dai.NNData) -> 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 |
| --- | --- |
| `np.ndarray` | Dequantized float32 batched UFLD grid tensor. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If no output name is configured and the message does not contain exactly one layer, or configured class requirements are not met. |

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

```python
def setClsNumPerLane(cls_num_per_lane: int)
```

Set the number of points per lane for the lane detection model.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `cls_num_per_lane` | `int` | Number of classes per lane. | required |

#### method `setGridingNum`

```python
def setGridingNum(griding_num: int)
```

Set the griding number for the lane detection model.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `griding_num` | `int` | Griding number. | required |

#### method `setInputSize`

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

Set the input size for the lane detection model.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `input_size` | `tuple[int, int]` | Input size (width,height). | required |

#### method `setOutputLayerName`

```python
def setOutputLayerName(output_layer_name: str)
```

Set the output layer name for the lane detection model.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_name` | `str` | Name of the output layer. | required |

#### method `setRowAnchors`

```python
def setRowAnchors(row_anchors: list[int])
```

Set the row anchors for the lane detection model.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `row_anchors` | `list[int]` | List of row anchors. | required |
