Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/pipeline/datatype/ImgDetectionsT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <array>
#include <cstring>
#include <stdexcept>
#include <utility>
#include <vector>

#include "depthai/pipeline/datatype/ImgDetections.hpp"
Expand All @@ -27,7 +28,8 @@ void ImgDetectionsT<DetectionT>::setSegmentationMask(const std::vector<std::uint
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->segmentationMaskWidth = width;
this->segmentationMaskHeight = height;
}
Expand All @@ -39,7 +41,7 @@ void ImgDetectionsT<DetectionT>::setSegmentationMask(dai::ImgFrame& frame) {
}
auto dataSpan = frame.getData();
std::vector<std::uint8_t> 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();
}
Expand Down Expand Up @@ -87,7 +89,7 @@ void ImgDetectionsT<DetectionT>::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;
}
Expand Down
6 changes: 4 additions & 2 deletions src/pipeline/datatype/SegmentationMask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <cstring>
#include <optional>
#include <stdexcept>
#include <utility>
#include <vector>

#include "depthai/common/RotatedRect.hpp"
Expand Down Expand Up @@ -43,7 +44,8 @@ void SegmentationMask::setMask(const std::vector<std::uint8_t>& 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;
}
Expand Down Expand Up @@ -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;
}
Expand Down