# SegmentationParser

SegmentationParser node takes the raw output of a segmentation NN and applies per-pixel argmax to convert the raw output tensor
into a single-channel segmentation mask, which is then output as a
[SegmentationMask](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/segmentation_mask.md) message. Some
segmentation NNs output the segmentation mask directly as a single-channel output, in which case the SegmentationParser node can
be used to simply convert the raw output tensor into a SegmentationMask message without applying argmax.

## How to place it

#### Python

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

#### C++

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

## Inputs and Outputs

## Usage

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

## Examples of functionality

 * [Semantic segmentation
   (Python)](https://github.com/luxonis/depthai-core/blob/main/examples/python/Segmentation/semantic_segmentation.py) - Run a
   DeepLabv3+ segmentation model and display the segmentation masks on a video stream.
 * [Segmentation examples (C++)](https://github.com/luxonis/depthai-core/tree/main/examples/cpp/Segmentation) - Browse the C++
   segmentation examples in depthai-core.

## Reference

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

### Need assistance?

Head over to [Discussion Forum](https://discuss.luxonis.com/) for technical support or any other questions you might have.
