# SegmentationParser

SegmentationParser 节点接收分割神经网络（NN）的原始输出，对每个像素应用 argmax，将原始输出张量转换为单通道分割掩码，然后作为
[SegmentationMask](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/segmentation_mask.md) 消息输出。
某些分割神经网络直接输出单通道分割掩码，在这种情况下，SegmentationParser 节点可直接将原始输出张量转换为 SegmentationMask 消息，而无需应用 argmax。

## 如何放置

#### Python

```python
pipeline = dai.Pipeline()
segmentation = pipeline.create(dai.node.SegmentationParser)
```

#### C++

```cpp
dai::Pipeline pipeline;
auto segmentation = pipeline.create<dai::node::SegmentationParser>();
```

## 输入与输出

## 使用示例

#### Python

```python
model = dai.NNModelDescription("luxonis/deeplab-v3-plus:512x512")
pipeline = dai.Pipeline()
camera = pipeline.create(dai.node.Camera).build()
nn = pipeline.create(dai.node.NeuralNetwork).build(camera, model)
parser = pipeline.create(dai.node.SegmentationParser).build(nn.out, model )
```

#### C++

```cpp
dai::NNModelDescription model("luxonis/deeplab-v3-plus:512x512");
dai::Pipeline pipeline;
auto camera = pipeline.create<dai::node::Camera>()->build();
auto nn = pipeline.create<dai::node::NeuralNetwork>()->build(camera, model);
auto parser = pipeline.create<dai::node::SegmentationParser>()->build(nn->out, model);
```

## 功能示例

 * [语义分割（Python）](https://github.com/luxonis/depthai-core/blob/main/examples/python/Segmentation/semantic_segmentation.py) - 运行
   DeepLabv3+ 分割模型并在视频流上显示分割掩码。
 * [分割示例（C++）](https://github.com/luxonis/depthai-core/tree/main/examples/cpp/Segmentation) - 浏览 depthai-core 中的 C++ 分割示例。

## 参考

### dai::node::SegmentationParser

Kind: class

SegmentationParser node. Parses raw segmentation output from segmentation neural networks into a dai::SegmentationMask datatype.
The parser supports two output model types:

warning: Only OAK4 supports running SegmentationParser on device. On other platforms, the node will automatically switch to host
execution.

#### std::variant< NNModelDescription , NNArchive , std::string > Model

Kind: enum

#### std::shared_ptr< SegmentationParserConfig > initialConfig

Kind: variable

Initial config to use when parsing segmentation masks.

#### Input input

Kind: variable

Input NN results with segmentation data to parser

#### Input inputConfig

Kind: variable

Input SegmentationParserConfig message with ability to modify parameters in runtime.

#### Output out

Kind: variable

Outputs segmentation mask

#### ~SegmentationParser()

Kind: function

#### SegmentationParser()

Kind: function

#### SegmentationParser(std::unique_ptr< Properties > props)

Kind: function

#### std::shared_ptr< SegmentationParser > build(Node::Output & nnInput, const Model & model)

Kind: function

Build SegmentationParser node.

parameters: nnInput: Output to link; model: Neural network model

#### std::shared_ptr< SegmentationParser > build(Node::Output & nnInput, const NNArchive & nnArchive)

Kind: function

Build SegmentationParser node.

parameters: nnInput: Output to link; nnArchive: Neural network archive

#### std::shared_ptr< SegmentationParser > build(Node::Output & nnInput, const dai::nn_archive::v1::Head & head)

Kind: function

Build SegmentationParser node with the specific head from NNArchive . Useful when model outputs multiple segmentation heads.

parameters: nnInput: Output to link; head: Specific head from NNArchive to use for this parser

#### void setNNArchive(const NNArchive & nnArchive)

Kind: function

Set NNArchive for this Node .

parameters: nnArchive: NNArchive to set

#### void setNNArchiveHead(const dai::nn_archive::v1::Head & head)

Kind: function

Set NNArchive head for this Node .

parameters: head: NNArchive head to set

#### void setLabels(const std::vector< std::string > & labels)

Kind: function

Sets the class labels associated with the segmentation mask. The label at index $i$ in the parameters: labels: Vector of class
labels

#### std::vector< std::string > getLabels()

Kind: function

Returns the class labels associated with the segmentation mask.

#### void setBackgroundClass(bool backgroundClass)

Kind: function

Sets whether the first class (index 0) is considered the background class. If true, the pixels classified as index 0 will be
treated as background. parameters: backgroundClass: Boolean indicating if the first class is the background class note: Only
applicable if the number of classes is greater than 1 and the output classes are not in a single layer (eg. classesInOneLayer =
false).

#### bool getBackgroundClass()

Kind: function

Gets whether the first class (index 0) is considered the background class.

#### void setRunOnHost(bool runOnHost)

Kind: function

Specify whether to run on host or device By default, the node will run on device.

#### bool runOnHost()

Kind: function

Check if the node is set to run on host

#### void run()

Kind: function

#### void buildInternal()

Kind: function

Function called from within the

#### DeviceNodeCRTP()

Kind: function

#### DeviceNodeCRTP(const std::shared_ptr< Device > & device)

Kind: function

#### DeviceNodeCRTP(std::unique_ptr< Properties > props)

Kind: function

#### DeviceNodeCRTP(std::unique_ptr< Properties > props, bool confMode)

Kind: function

#### DeviceNodeCRTP(const std::shared_ptr< Device > & device, std::unique_ptr< Properties > props, bool confMode)

Kind: function

### 需要帮助？

请前往 [OAKChina 官网](https://www.oakchina.cn/) 获取技术支持或解答您的任何疑问。
