diff --git a/src/pipeline/datatype/ImgDetectionsT.cpp b/src/pipeline/datatype/ImgDetectionsT.cpp index 88a8597db0..b38da049bf 100644 --- a/src/pipeline/datatype/ImgDetectionsT.cpp +++ b/src/pipeline/datatype/ImgDetectionsT.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "depthai/pipeline/datatype/ImgDetections.hpp" @@ -27,7 +28,8 @@ void ImgDetectionsT::setSegmentationMask(const std::vectorsegmentationMaskWidth = width; this->segmentationMaskHeight = height; } @@ -39,7 +41,7 @@ void ImgDetectionsT::setSegmentationMask(dai::ImgFrame& frame) { } auto dataSpan = frame.getData(); std::vector vecMask(dataSpan.begin(), dataSpan.end()); - setData(vecMask); + setData(std::move(vecMask)); // Call the rvalue overload to allocate a new memory holder this->segmentationMaskWidth = frame.getWidth(); this->segmentationMaskHeight = frame.getHeight(); } @@ -87,7 +89,7 @@ void ImgDetectionsT::setCvSegmentationMask(cv::Mat mask) { } else { dataVec.insert(dataVec.begin(), mask.datastart, mask.dataend); } - setData(dataVec); + setData(std::move(dataVec)); // Call the rvalue overload to allocate a new memory holder this->segmentationMaskWidth = mask.cols; this->segmentationMaskHeight = mask.rows; } diff --git a/src/pipeline/datatype/SegmentationMask.cpp b/src/pipeline/datatype/SegmentationMask.cpp index 82e8a6863b..a94798681f 100644 --- a/src/pipeline/datatype/SegmentationMask.cpp +++ b/src/pipeline/datatype/SegmentationMask.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "depthai/common/RotatedRect.hpp" @@ -43,7 +44,8 @@ void SegmentationMask::setMask(const std::vector& mask, size_t wid if(mask.size() != width * height) { throw std::runtime_error("SegmentationMask: data size does not match width*height"); } - setData(mask); + auto vecMask = mask; // Avoid mutating shared storage by moving a copy of the input into a new buffer + setData(std::move(vecMask)); // Call the rvalue overload to allocate a new memory holder this->width = width; this->height = height; } @@ -240,7 +242,7 @@ void SegmentationMask::setCvMask(cv::Mat mask) { } else { dataVec.insert(dataVec.begin(), mask.datastart, mask.dataend); } - setData(dataVec); + setData(std::move(dataVec)); // Call the rvalue overload to allocate a new memory holder this->width = mask.cols; this->height = mask.rows; }