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

Instanciate the tensor opencv from cv::mat using the generic function

parent d91f9462
No related branches found
No related tags found
No related merge requests found
...@@ -18,11 +18,13 @@ ...@@ -18,11 +18,13 @@
#include "opencv2/core.hpp" #include "opencv2/core.hpp"
#include <opencv2/imgcodecs.hpp> #include <opencv2/imgcodecs.hpp>
#include "aidge/data/Data.hpp" #include "aidge/data/Data.hpp"
#include "aidge/data/Tensor.hpp" #include "aidge/data/Tensor.hpp"
#include "aidge/backend/StimuliImpl.hpp" #include "aidge/backend/StimuliImpl.hpp"
#include "aidge/stimuli/Stimuli.hpp" #include "aidge/stimuli/Stimuli.hpp"
#include "aidge/backend/opencv/data/TensorImpl.hpp" #include "aidge/backend/opencv/data/TensorImpl.hpp"
#include "aidge/backend/opencv/utils/Utils.hpp"
namespace Aidge { namespace Aidge {
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
namespace Aidge { 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 * @param mat the cv::mat to instanciate the tensor from
* @return std::shared_ptr<Tensor> aidge tensor * @return std::shared_ptr<Tensor> aidge tensor
......
#include "aidge/backend/opencv/stimuli/StimuliImpl_opencv_imread.hpp" #include "aidge/backend/opencv/stimuli/StimuliImpl_opencv_imread.hpp"
std::shared_ptr<Aidge::Tensor> Aidge::StimuliImpl_opencv_imread::load() { std::shared_ptr<Aidge::Tensor> Aidge::StimuliImpl_opencv_imread::load() {
cv::Mat cv_img = cv::imread(mDataPath, mColorFlag); cv::Mat cvImg = cv::imread(mDataPath, mColorFlag);
if (cv_img.empty()) { if (cvImg.empty()) {
throw std::runtime_error("Could not open images file: " + mDataPath); 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 return tensorOpencv(cvImg);
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;
} }
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