# DetectionParser

`DetectionParser` decodes MobileNet-SSD or YOLO outputs from
[NeuralNetwork](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/neural_network.md). Its `input` accepts
`NNData`, and `out` emits
[ImgDetections](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/img_detections.md).

## Runtime thresholds

Configure startup thresholds with `setConfidenceThreshold()`, `setIouThreshold()`, or `initialConfig`. After pipeline startup,
send [DetectionParserConfig](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/detection_parser_config.md)
messages through `inputConfig` to change confidence and IoU thresholds. The input has a non-blocking queue of size 4 and does not
wait for a configuration message by default.

The following snippet assumes `pipeline`, a configured `nn` node, and its `nn_archive` already exist:

```python
parser = pipeline.create(dai.node.DetectionParser).build(nn.out, nn_archive)
parser.setConfidenceThreshold(0.5)
parser.setIouThreshold(0.5)
config_queue = parser.inputConfig.createInputQueue()

pipeline.start()

config = dai.DetectionParserConfig()
config.setConfidenceThreshold(0.6)
config.setIouThreshold(0.4)
config_queue.send(config)
```

The update applies to subsequent detections. IoU updates affect YOLO non-maximum suppression; MobileNet-SSD and end-to-end YOLO
models do not use this threshold.

## Reference

### dai::node::DetectionParser

Kind: class

DetectionParser node. Parses detection results from Mobilenet-SSD or YOLO neural networks.

note: If multiple detection heads are present in the NNArchive , only one type is supported (either YOLO or Mobilenet-SSD) and the
last one will be used.

#### std::shared_ptr< DetectionParserConfig > initialConfig

Kind: variable

Initial runtime thresholds. Send a config to inputConfig to change them after startup.

#### Input inputConfig

Kind: variable

Runtime threshold configuration. Non-blocking queue of size 4; does not wait by default.

#### Input input

Kind: variable

Input NN results with detection data to parse Default queue is blocking with size 5

#### Output out

Kind: variable

Outputs image frame with detected edges

#### ~DetectionParser()

Kind: function

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

Kind: function

Build DetectionParser node. Connect output to this node's input. Also call setNNArchive() with provided NNArchive .

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

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

Kind: function

Build DetectionParser node with a specific NNArchive head.

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

#### void setNumFramesPool(int numFramesPool)

Kind: function

Specify number of frames in pool. parameters: numFramesPool: How many frames should the pool have

#### int getNumFramesPool()

Kind: function

Returns number of frames in pool

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

Kind: function

Set NNArchive for this Node . If the archive's type is SUPERBLOB, use default number of shaves.

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 setModelPath(const std::filesystem::path & modelPath)

Kind: function

Load network xml and bin files into assets. parameters: xmlModelPath: Path to the neural network model file.

#### void setBlobPath(const std::filesystem::path & path)

Kind: function

Load network blob into assets and use once pipeline is started. parameters: Error: if file doesn't exist or isn't a valid network
blob. parameters: path: Path to network blob

#### void setBlob(const OpenVINO::Blob & blob)

Kind: function

Retrieves some input tensor information from the blob parameters: blob: OpenVINO blob to retrieve the information from

#### void setBlob(const std::filesystem::path & path)

Kind: function

Same functionality as the setBlobPath() . Load network blob into assets and use once pipeline is started. parameters: Error: if
file doesn't exist or isn't a valid network blob. parameters: path: Path to network blob

#### void setInputImageSize(int width, int height)

Kind: function

Set input image size This should only be used instead of setBlob, not besides it

#### void setInputImageSize(const std::tuple< int, int > & size)

Kind: function

Set preview output size, as a tuple<width, height>

#### void setNNFamily(DetectionNetworkType type)

Kind: function

Sets NN Family to parse. Possible values are: DetectionNetworkType::YOLO - 0 DetectionNetworkType::MOBILENET - 1 warning: If NN
Family is set manually, user must ensure that it matches the actual model being used.

#### DetectionNetworkType getNNFamily()

Kind: function

Gets NN Family to parse

#### void setConfidenceThreshold(float thresh)

Kind: function

Specifies confidence threshold at which to filter the rest of the detections. parameters: thresh: Detection confidence must be
greater than specified threshold to be added to the list note: Sets startup configuration. Send DetectionParserConfig to
inputConfig for runtime updates.

#### float getConfidenceThreshold()

Kind: function

Retrieves threshold at which to filter the rest of the detections. return: Detection confidence

#### void setNumClasses(int numClasses)

Kind: function

Set number of classes. This will clear any previously set class names. parameters: numClasses: Number of classes

#### void setClasses(const std::vector< std::string > & classes)

Kind: function

Set class names. This will clear any previously set number of classes. parameters: classes: Vector of class names

#### void setCoordinateSize(int coordinates)

Kind: function

Sets the number of coordinates per bounding box. parameters: coordinates: Number of coordinates. Default is 4

#### void setAnchors(const std::vector< float > & anchors)

Kind: function

Set anchors for anchor-based yolo models parameters: anchors: Flattened vector of anchors warning: This method is deprecated, use
setAnchorsV2 instead.

#### void setAnchorMasks(const std::map< std::string, std::vector< int >> & anchorMasks)

Kind: function

Set anchor masks for anchor-based yolo models parameters: anchorMasks: Map of anchor masks

#### void setAnchors(const std::vector< std::vector< std::vector< float >>> & anchors)

Kind: function

Set anchors for anchor-based yolo models (v2) parameters: anchors: 3D vector of anchors [layer][anchor][dim]

#### void setIouThreshold(float thresh)

Kind: function

Set IOU threshold for non-maxima suppression parameters: thresh: IOU threshold note: Sets startup configuration. Send
DetectionParserConfig to inputConfig for runtime updates.

#### void setSubtype(const std::string & subtype)

Kind: function

Set subtype for the parser. parameters: subtype: Subtype string, currently supported subtypes are: yolov6r1, yolov6r2 yolov8n,
yolov6, yolov8, yolov10, yolov11, yolov3, yolov3-tiny, yolov5, yolov7, yolo-p, yolov5-u

#### void setDecodeKeypoints(bool decode)

Kind: function

Enable/disable keypoints decoding. If enabled, number of keypoints must also be set.

#### void setDecodeSegmentation(bool decode)

Kind: function

Enable/disable segmentation mask decoding.

#### void setNumKeypoints(int numKeypoints)

Kind: function

Set number of keypoints to decode. Automatically enables keypoints decoding.

#### void setStrides(const std::vector< int > & strides)

Kind: function

Set strides for yolo models

#### void setKeypointEdges(const std::vector< dai::Edge > & edges)

Kind: function

Set edges connections between keypoints. parameters: edges: Vector edges connections represented as pairs of keypoint indices.
note: This is only applicable if keypoints decoding is enabled.

#### int getNumClasses()

Kind: function

Get number of classes to decode.

#### std::optional< std::vector< std::string > > getClasses()

Kind: function

Get class names to decode.

#### int getCoordinateSize()

Kind: function

Get number of coordinates per bounding box.

#### std::vector< float > getAnchors()

Kind: function

Get anchors for anchor-based yolo models

#### std::map< std::string, std::vector< int > > getAnchorMasks()

Kind: function

Get anchor masks for anchor-based yolo models

#### float getIouThreshold()

Kind: function

Get IOU threshold for non-maxima suppression

#### std::string getSubtype()

Kind: function

Get subtype for the parser.

#### bool getDecodeKeypoints()

Kind: function

Get whether keypoints decoding is enabled.

#### bool getDecodeSegmentation()

Kind: function

Get whether segmentation mask decoding is enabled.

#### int getNKeypoints()

Kind: function

Get number of keypoints to decode.

#### std::vector< int > getStrides()

Kind: function

Get strides for yolo models

#### const NNArchiveVersionedConfig & getNNArchiveVersionedConfig()

Kind: function

Get NNArchive set for this node

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

#### Properties & getProperties()

Kind: function

Get serialized startup properties, including initialConfig thresholds.

#### void decodeMobilenet(dai::NNData & nnData, dai::ImgDetections & outDetections, float confidenceThr)

Kind: function

Decode Mobilenet-SSD detections from NNData .

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