From d0b35714d7fa41e6fae054408b6e1b5c8bb0f6d2 Mon Sep 17 00:00:00 2001 From: thibault allenet <thibault.allenet@cea.fr> Date: Mon, 19 Feb 2024 13:29:20 +0000 Subject: [PATCH] Fix layout from [H,W,C] to [C,H,W] --- src/utils/Utils.cpp | 4 ++-- unit_tests/Tests_Utils.cpp | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/utils/Utils.cpp b/src/utils/Utils.cpp index 09df5ec..3be0ab3 100644 --- a/src/utils/Utils.cpp +++ b/src/utils/Utils.cpp @@ -61,9 +61,9 @@ static Aidge::DataType CVtoAidge(const int matDepth) { std::shared_ptr<Aidge::Tensor> Aidge::tensorOpencv(cv::Mat mat) { // Get Mat dims - const std::vector<DimSize_t> matDims = std::vector<DimSize_t>({static_cast<DimSize_t>(mat.cols), + const std::vector<DimSize_t> matDims = std::vector<DimSize_t>({static_cast<DimSize_t>(mat.channels()), static_cast<DimSize_t>(mat.rows), - static_cast<DimSize_t>(mat.channels())}); + static_cast<DimSize_t>(mat.cols)}); // Get the correct Data Type Aidge::DataType type; type = CVtoAidge(mat.depth()); diff --git a/unit_tests/Tests_Utils.cpp b/unit_tests/Tests_Utils.cpp index bd01df9..a623e1b 100644 --- a/unit_tests/Tests_Utils.cpp +++ b/unit_tests/Tests_Utils.cpp @@ -69,9 +69,10 @@ TEMPLATE_TEST_CASE("Opencv Utils", "[Utils][OpenCV]", signed char, unsigned char auto tensorOcv = tensorOpencv(mat); // Check the size of the tensor + REQUIRE(mat.channels() == tensorOcv->dims()[0]); REQUIRE(mat.rows == tensorOcv->dims()[1]); - REQUIRE(mat.cols == tensorOcv->dims()[0]); - REQUIRE(mat.channels() == tensorOcv->dims()[2]); + REQUIRE(mat.cols == tensorOcv->dims()[2]); + // Check the matrix inside the tensor coorresponds to the matrix TensorImpl_opencv_* tImpl_opencv = dynamic_cast<TensorImpl_opencv_*>(tensorOcv->getImpl().get()); -- GitLab