# lane_detection

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

## 类

### LaneDetectionParser

Ultra-Fast-Lane-Detection 模型的解析器类。它期望一个包含车道检测结果的输出层。它支持两个版本的模型：CuLane 和 TuSimple。结果以点簇表示。

输出消息：

类型：dai.beta.Clusters 描述：检测到的车道表示为点簇。

引发

 * `ValueError`：如果未指定行锚点。
 * `ValueError`：如果未指定网格编号。
 * `ValueError`：如果未指定每条车道的点数。

#### 方法

##### 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):
```

初始化车道检测解析器节点。

参数

 * `output_layer_name` (`str`)：与解析器相关的输出层名称。
 * `row_anchors` (`list[int]`)：行锚点列表。
 * `griding_num` (`int`)：网格编号。
 * `cls_num_per_lane` (`int`)：每条车道的点数。
 * `input_size` (`tuple[int, int]`)：输入大小（宽度，高度）。

##### build

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

配置解析器。

参数

 * `head_config` (`dict[str, Any]`)：解析器的头部配置。

返回

 * `LaneDetectionParser`：设置了头部配置的解析器对象。

##### 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]]]:
```

从提取的张量计算解析器结果，而不发送消息。

> **注意**
> 使用 [depthai_nodes.node.parsers.utils.lane_detection.compute_lane_detection_points](/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/lane_detection.md)；有关张量布局和验证详细信息，请参阅该帮助程序。

参数

 * `tensor` (`np.ndarray`)：带有网格类、采样行和车道的批处理 logits 作为剩余轴；仅使用第一个批处理项。
 * `row_anchors` (`list[int]`)：车道采样网格的图像行位置（像素）。
 * `griding_num` (`int`)：水平网格单元格的数量，不包括无车道类。
 * `cls_num_per_lane` (`int`)：每条车道的采样行位置数量。
 * `input_size` (`tuple[int, int]`)：模型输入大小，格式为 `(宽度, 高度)`。

返回

 * `list[list[tuple[int, int]]]`：每条车道一个列表，包含归一化的 XY 点元组。有效样本少于三个的车道具有空列表。

##### emit

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

创建 `dai.beta.Clusters` 消息并将其发送到 `out`。

复制源时间戳和序列号，并在存在时携带源图像转换。

参数

 * `output` (`dai.NNData`)：携带张量和源时间戳、序列号以及可选图像转换的神经网络输出。
 * `points`：归一化 XY 点列表，每条车道一个列表。

##### extract

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

选择并反量化解析所需的模型张量。

参数

 * `output` (`dai.NNData`)：携带张量和源时间戳、序列号以及可选图像转换的神经网络输出。

返回

 * `np.ndarray`：反量化的 float32 批处理 UFLD 网格张量。

引发

 * `ValueError`：如果未配置输出名称且消息不包含恰好一个层，或者未满足配置的类要求。

##### run

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

读取排队的网络输出，解析它们，并在运行时发出结果。

管道调用此处理循环。当输入队列关闭或节点停止时，它会退出。

##### setClsNumPerLane

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

设置车道检测模型每条车道的点数。

参数

 * `cls_num_per_lane` (`int`)：每条车道的类数。

##### setGridingNum

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

设置车道检测模型的网格编号。

参数

 * `griding_num` (`int`)：网格编号。

##### setInputSize

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

设置车道检测模型的输入大小。

参数

 * `input_size` (`tuple[int, int]`)：输入大小（宽度，高度）。

##### setOutputLayerName

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

设置车道检测模型的输出层名称。

参数

 * `output_layer_name` (`str`)：输出层名称。

##### setRowAnchors

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

设置车道检测模型的行锚点。

参数

 * `row_anchors` (`list[int]`)：行锚点列表。

#### 属性

##### cls_num_per_lane

每条车道的点数。

##### griding_num

网格编号。

##### input_shape

##### input_size

输入大小（宽度，高度）。

##### layout

##### output_layer_name

与解析器相关的输出层名称。

##### row_anchors

行锚点列表。
