Class DetectionParser

Inheritance Relationships

Base Types

Class Documentation

class DetectionParser : public dai::DeviceNodeCRTP<DeviceNode, DetectionParser, DetectionParserProperties>, public dai::HostRunnable

DetectionParser node. Parses detection results from different neural networks and is being used internally by MobileNetDetectionNetwork and YoloDetectionNetwork.

Public Functions

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

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

void setNumFramesPool(int numFramesPool)

Specify number of frames in pool.

Parameters:

numFramesPool – How many frames should the pool have

int getNumFramesPool()

Returns number of frames in pool

void setNNArchive(const NNArchive &nnArchive)

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

Parameters:

nnArchiveNNArchive to set

void setModelPath(const std::filesystem::path &modelPath)

Load network xml and bin files into assets.

Parameters:

xmlModelPath – Path to the neural network model file.

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

Load network blob into assets and use once pipeline is started.

Throws:

Error – if file doesn’t exist or isn’t a valid network blob.

Parameters:

path – Path to network blob

void setBlob(OpenVINO::Blob blob)

Retrieves some input tensor information from the blob

Parameters:

blobOpenVINO blob to retrieve the information from

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

Same functionality as the setBlobPath(). Load network blob into assets and use once pipeline is started.

Throws:

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)

Set input image size

This should only be used instead of setBlob, not besides it

void setInputImageSize(std::tuple<int, int> size)
void setNNFamily(DetectionNetworkType type)

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()

Gets NN Family to parse

void setConfidenceThreshold(float thresh)

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

float getConfidenceThreshold() const

Retrieves threshold at which to filter the rest of the detections.

Returns:

Detection confidence

void setNumClasses(int numClasses)

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)

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

Parameters:

classes – Vector of class names

void setCoordinateSize(int coordinates)
void setAnchors(std::vector<float> anchors)

Set anchors for anchor-based yolo models

Warning

This method is deprecated, use setAnchorsV2 instead.

Parameters:

anchors – Flattened vector of anchors

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

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)

Set anchors for anchor-based yolo models (v2)

Parameters:

anchors – 3D vector of anchors [layer][anchor][dim]

void setIouThreshold(float thresh)

Set IOU threshold for non-maxima suppression

Parameters:

thresh – IOU threshold

void setSubtype(const std::string &subtype)

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)

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

void setDecodeSegmentation(bool decode)

Enable/disable segmentation mask decoding.

void setNumKeypoints(int numKeypoints)

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

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

Set strides for yolo models

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

Set edges connections between keypoints.

Note

This is only applicable if keypoints decoding is enabled.

Parameters:

edges – Vector edges connections represented as pairs of keypoint indices.

int getNumClasses() const

Get number of classes to decode.

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

Get class names to decode.

int getCoordinateSize() const

Get number of coordinates per bounding box.

std::vector<float> getAnchors() const

Get anchors for anchor-based yolo models

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

Get anchor masks for anchor-based yolo models

float getIouThreshold() const

Get IOU threshold for non-maxima suppression

std::string getSubtype() const

Get subtype for the parser.

bool getDecodeKeypoints() const

Get whether keypoints decoding is enabled.

bool getDecodeSegmentation() const

Get whether segmentation mask decoding is enabled.

int getNKeypoints() const

Get number of keypoints to decode.

std::vector<int> getStrides() const

Get strides for yolo models

const NNArchiveVersionedConfig &getNNArchiveVersionedConfig() const

Get NNArchive set for this node

void setRunOnHost(bool runOnHost)

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

virtual bool runOnHost() const override

Check if the node is set to run on host

virtual void run() override
void decodeMobilenet(dai::NNData &nnData, dai::ImgDetections &outDetections, float confidenceThr)
inline DeviceNodeCRTP()
inline DeviceNodeCRTP(const std::shared_ptr<Device> &device)
inline DeviceNodeCRTP(std::unique_ptr<Properties> props)
inline DeviceNodeCRTP(std::unique_ptr<Properties> props, bool confMode)
inline DeviceNodeCRTP(const std::shared_ptr<Device> &device, std::unique_ptr<Properties> props, bool confMode)

Public Members

Input input = {*this, {"in", DEFAULT_GROUP, true, 5, {{{DatatypeEnum::NNData, true}}}, true}}

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

Output out = {*this, {"out", DEFAULT_GROUP, {{{DatatypeEnum::ImgDetections, false}}}}}

Outputs image frame with detected edges

Public Static Attributes

static constexpr const char *NAME = "DetectionParser"