From 833ebf419ed59875512b2de33d6e41a261fe121b Mon Sep 17 00:00:00 2001 From: thibault allenet <thibault.allenet@cea.fr> Date: Thu, 7 Dec 2023 14:08:44 +0000 Subject: [PATCH] Instanciate the tensor opencv from cv::mat using the generic function --- .../stimuli/StimuliImpl_opencv_imread.hpp | 2 ++ include/aidge/backend/opencv/utils/Utils.hpp | 2 +- src/operator/StimulImpl_opencv_imread.cpp | 21 +++---------------- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/include/aidge/backend/opencv/stimuli/StimuliImpl_opencv_imread.hpp b/include/aidge/backend/opencv/stimuli/StimuliImpl_opencv_imread.hpp index 26252cf..78590a1 100644 --- a/include/aidge/backend/opencv/stimuli/StimuliImpl_opencv_imread.hpp +++ b/include/aidge/backend/opencv/stimuli/StimuliImpl_opencv_imread.hpp @@ -18,11 +18,13 @@ #include "opencv2/core.hpp" #include <opencv2/imgcodecs.hpp> + #include "aidge/data/Data.hpp" #include "aidge/data/Tensor.hpp" #include "aidge/backend/StimuliImpl.hpp" #include "aidge/stimuli/Stimuli.hpp" #include "aidge/backend/opencv/data/TensorImpl.hpp" +#include "aidge/backend/opencv/utils/Utils.hpp" namespace Aidge { diff --git a/include/aidge/backend/opencv/utils/Utils.hpp b/include/aidge/backend/opencv/utils/Utils.hpp index 4d44626..3caa6f9 100644 --- a/include/aidge/backend/opencv/utils/Utils.hpp +++ b/include/aidge/backend/opencv/utils/Utils.hpp @@ -26,7 +26,7 @@ namespace Aidge { /** - * @brief Instanciate an aidge tensor with backend "opencv" containing an opencv matrix + * @brief Instanciate an aidge tensor with backend "opencv" from an opencv matrix * * @param mat the cv::mat to instanciate the tensor from * @return std::shared_ptr<Tensor> aidge tensor diff --git a/src/operator/StimulImpl_opencv_imread.cpp b/src/operator/StimulImpl_opencv_imread.cpp index 2113db3..cf5b023 100644 --- a/src/operator/StimulImpl_opencv_imread.cpp +++ b/src/operator/StimulImpl_opencv_imread.cpp @@ -1,25 +1,10 @@ #include "aidge/backend/opencv/stimuli/StimuliImpl_opencv_imread.hpp" std::shared_ptr<Aidge::Tensor> Aidge::StimuliImpl_opencv_imread::load() { - cv::Mat cv_img = cv::imread(mDataPath, mColorFlag); - if (cv_img.empty()) { + cv::Mat cvImg = cv::imread(mDataPath, mColorFlag); + if (cvImg.empty()) { throw std::runtime_error("Could not open images file: " + mDataPath); } - // Get Mat dims - std::vector<DimSize_t> matDims = std::vector<DimSize_t>({static_cast<DimSize_t>(cv_img.cols), - static_cast<DimSize_t>(cv_img.rows), - static_cast<DimSize_t>(cv_img.channels())}); - // Create tensor from the dims of the Cv::Mat - std::shared_ptr<Tensor> img = std::make_shared<Tensor>(matDims); - // Set beackend opencv - img->setBackend("opencv"); - // Set Data Type - img->setDataType(DataType::UInt8); - - // Cast the tensorImpl to access setCvMat function - TensorImpl_opencv_* tImpl_opencv = dynamic_cast<TensorImpl_opencv_*>(img->getImpl().get()); - tImpl_opencv->setCvMat(cv_img); - - return img; + return tensorOpencv(cvImg); } -- GitLab