Skip to content
Snippets Groups Projects
Commit aa4a1656 authored by Thibault Allenet's avatar Thibault Allenet
Browse files

Change cv::Mat to cv::Mat*

parent 26381a58
No related branches found
No related tags found
2 merge requests!10Update backend_opencv with modifications from aidge_core,!4Change tensorimpl opencv `future_std::span<cv::Mat>` to `cv::Mat`
......@@ -37,15 +37,19 @@ private:
const Tensor &mTensor; // Impl needs to access Tensor information, but is not
// supposed to change it!
cv::Mat mData;
std::unique_ptr<cv::Mat> mDataOwner = std::unique_ptr<cv::Mat>(new cv::Mat(0,0,OpenCvType<T>::type));
cv::Mat* mData;
std::unique_ptr<cv::Mat> mDataOwner;
public:
static constexpr const char *Backend = "opencv";
TensorImpl_opencv() = delete;
TensorImpl_opencv(const Tensor &tensor)
: TensorImpl(Backend), mTensor(tensor) {}
: TensorImpl(Backend), mTensor(tensor)
{
mDataOwner = std::unique_ptr<cv::Mat>(new cv::Mat(0,0,OpenCvType<T>::type));
mData = mDataOwner.get();
}
bool operator==(const TensorImpl &otherImpl) const override final {
// Create iterators for both matrices
......@@ -69,11 +73,11 @@ public:
}
// native interface
const cv::Mat data() const { return mData; }
const cv::Mat data() const { return *mData; }
std::size_t scalarSize() const override { return sizeof(T); }
std::size_t size() const override { return mData.total() * mData.channels(); }
std::size_t size() const override { return mData->total() * mData->channels();}
void setDevice(DeviceIdx_t device) override {
AIDGE_ASSERT(device == 0, "device cannot be != 0 for Opencv backend");
......@@ -160,29 +164,29 @@ public:
void *rawPtr(NbElts_t offset = 0) override {
lazyInit();
return (mData.ptr<T>() + offset);
return (mData->ptr<T>() + offset);
};
const void *rawPtr(NbElts_t offset = 0) const override {
AIDGE_ASSERT(size() >= mTensor.size(), "accessing uninitialized const rawPtr");
return (mData.ptr<T>() + offset);
return (mData->ptr<T>() + offset);
};
void *hostPtr(NbElts_t offset = 0) override {
lazyInit();
return (mData.ptr<T>() + offset);
return (mData->ptr<T>() + offset);
};
const void *hostPtr(NbElts_t offset = 0) const override {
AIDGE_ASSERT(size() >= mTensor.size(), "accessing uninitialized const hostPtr");
AIDGE_ASSERT(mData.isContinuous(), "CV Matrix not continuous");
return (mData.ptr<T>() + offset);
AIDGE_ASSERT(mData->isContinuous(), "CV Matrix not continuous");
return (mData->ptr<T>() + offset);
};
const cv::Mat& getCvMat() const override { return *mDataOwner.get(); }
void setCvMat(const cv::Mat& mat) override {
mDataOwner.reset(new cv::Mat(std::move(mat)));
mData = *mDataOwner.get();}
mData = mDataOwner.get();}
virtual ~TensorImpl_opencv() = default;
......@@ -192,7 +196,7 @@ private:
void lazyInit() {
if (size() < mTensor.size()) {
// Need more data, a re-allocation will occur
AIDGE_ASSERT(mData.empty() || mDataOwner != nullptr, "trying to enlarge non-owned data");
AIDGE_ASSERT(mData->empty() || mDataOwner != nullptr, "trying to enlarge non-owned data");
cv::Mat myNewMatrix;
if (mTensor.nbDims() < 3) {
......@@ -214,7 +218,7 @@ private:
}
mDataOwner.reset(new cv::Mat(std::forward<cv::Mat>(myNewMatrix)));
mData = *mDataOwner.get();
mData = mDataOwner.get();
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment