# ImgDetections 图像检测

[DetectionNetwork](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/detection_network.md) 输出此消息。该消息包含一个
detections 列表， 其中包含 label（标签）、confidence（置信度）以及边界框信息（xmin、ymin、xmax、ymax）。

## 功能示例

 * [RGB 与 Yolo](https://docs.luxonis.com/software-v3/depthai/examples/detection_network/detection_network.md)

## 参考

### dai::ImgDetections

Kind: class

ImgDetections message. Carries normalized detections and optional segmentation mask. The segmentation mask is stored as a
single-channel INT8 2-d array, where the value represents the instance index in the list of detections. The value 255 is treated
as a background pixel (no instance).

#### ImgDetectionsT < dai::ImgDetection > Base

Kind: enum

#### std::vector< DetectionT > detections

Kind: variable

#### size_t segmentationMaskHeight

Kind: variable

#### size_t segmentationMaskWidth

Kind: variable

#### std::optional< ImgTransformation > transformation

Kind: variable

#### ~ImgDetections()

Kind: function

#### void serialize(std::vector< std::uint8_t > & metadata, DatatypeEnum & datatype)

Kind: function

#### DatatypeEnum getDatatype()

Kind: function

Get the datatype of this specific message.

return: DatatypeEnum

#### ImgDetections transformTo(const ImgTransformation & target)

Kind: function

Returns a new ImgDetections message with the detections transformed into the target image transformation. If the target
transformation has a different source coordinate system (eg. different camera socket) than the one the detections were originally
generated in, the remapping will be inaccurate due to the lack of depth information. The segmentation mask is not transformed. Use
ImageAlign node to transform the segmentation mask to the target transformation if needed. parameters: target: Target image
transformation.

#### DEPTHAI_SERIALIZE(ImgDetections, sequenceNum, ts, tsDevice, tsSystem, detections, transformation, segmentationMaskWidth,
segmentationMaskHeight)

Kind: function

### dai::ImgDetectionsT

Kind: class

#### std::vector< DetectionT > detections

Kind: variable

#### ImgDetectionsT()

Kind: function

#### ~ImgDetectionsT()

Kind: function

#### std::size_t getSegmentationMaskWidth()

Kind: function

Returns the width of the segmentation mask.

#### std::size_t getSegmentationMaskHeight()

Kind: function

Returns the height of the segmentation mask.

#### void setSegmentationMask(const std::vector< std::uint8_t > & mask, size_t width, size_t height)

Kind: function

Sets the segmentation mask from a vector of bytes. The size of the vector must be equal to width * height.

#### void setSegmentationMask(dai::ImgFrame & frame)

Kind: function

Sets the segmentation mask from an ImgFrame . parameters: frame: Frame must be of type GRAY8

#### std::optional< std::vector< std::uint8_t > > getMaskData()

Kind: function

Returns a copy of the segmentation mask data as a vector of bytes. If mask data is not set, returns std::nullopt.

#### std::optional< dai::ImgFrame > getSegmentationMask()

Kind: function

Returns the segmentation mask as an ImgFrame . If mask data is not set, returns std::nullopt.

#### void setCvSegmentationMask(cv::Mat mask)

Kind: function

note: This API only available if OpenCV support is enabled Copies cv::Mat data to Segmentation Mask buffer parameters: frame:
Input cv::Mat frame from which to copy the data note: Throws if mask is not a single channel INT8 type.

#### std::optional< cv::Mat > getCvSegmentationMask(cv::MatAllocator * allocator)

Kind: function

Retrieves mask data as a cv::Mat copy with specified width and height. If mask data is not set, returns std::nullopt. parameters:
allocator: Allows callers to supply a custom cv::MatAllocator for zero-copy/custom memory management; nullptr uses OpenCV’s
default.

#### std::optional< cv::Mat > getCvSegmentationMaskByIndex(uint8_t index, cv::MatAllocator * allocator)

Kind: function

Returns a binary mask where pixels belonging to the instance index are set to 1, others to 0. If mask data is not set, returns
std::nullopt. parameters: index: Instance index; allocator: Allows callers to supply a custom cv::MatAllocator for
zero-copy/custom memory management; nullptr uses OpenCV’s default.

#### std::optional< cv::Mat > getCvSegmentationMaskByClass(uint8_t semanticClass, cv::MatAllocator * allocator)

Kind: function

Retrieves data by the semantic class. If no mask data is not set, returns std::nullopt. parameters: semanticClass: Semantic class
index; allocator: Allows callers to supply a custom cv::MatAllocator for zero-copy/custom memory management; nullptr uses OpenCV’s
default.

### 需要帮助？

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