# lane_detection

Python API: `depthai_nodes.node.parsers.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.

Output messages:

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

Raises

 * `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.

#### Methods

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

Parameters

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

##### build

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

Configures the parser.

Parameters

 * `head_config` (`dict[str, Any]`): The head configuration for the parser.

Returns

 * `LaneDetectionParser`: The parser object with the head configuration set.

##### 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); see that helper for tensor layout and validation details.

Parameters

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

Returns

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

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

Parameters

 * `output` (`dai.NNData`): Neural network output carrying tensors and source timestamps, sequence number, and optional image
   transformation.
 * `points`: Lists of normalized XY points, one list per lane.

##### extract

```python
def extract(output: dai.NNData) -> np.ndarray:
```

Select and dequantize the model tensors needed for parsing.

Parameters

 * `output` (`dai.NNData`): Neural network output carrying tensors and source timestamps, sequence number, and optional image
   transformation.

Returns

 * `np.ndarray`: Dequantized float32 batched UFLD grid tensor.

Raises

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

##### run

```python
def run(self):
```

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.

##### setClsNumPerLane

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

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

Parameters

 * `cls_num_per_lane` (`int`): Number of classes per lane.

##### setGridingNum

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

Set the griding number for the lane detection model.

Parameters

 * `griding_num` (`int`): Griding number.

##### setInputSize

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

Set the input size for the lane detection model.

Parameters

 * `input_size` (`tuple[int, int]`): Input size (width,height).

##### setOutputLayerName

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

Set the output layer name for the lane detection model.

Parameters

 * `output_layer_name` (`str`): Name of the output layer.

##### setRowAnchors

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

Set the row anchors for the lane detection model.

Parameters

 * `row_anchors` (`list[int]`): List of row anchors.

#### Attributes

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