diff --git a/unit_tests/Test_Stimulus.cpp b/unit_tests/Test_Stimulus.cpp index bdfe453fe0ce606d1b895e998b408f0f9adf7274..a02a71180e4cdb5eee1fb539a2c2083567a76cfa 100644 --- a/unit_tests/Test_Stimulus.cpp +++ b/unit_tests/Test_Stimulus.cpp @@ -58,10 +58,21 @@ TEST_CASE("Stimulus creation", "[Stimulus][OpenCV]") { // Access the cv::Mat with the tensor TensorImpl_opencv_* tImpl_opencv = dynamic_cast<TensorImpl_opencv_*>(tensor_load->getImpl().get()); + auto mat_tensor = tImpl_opencv->data(); - REQUIRE((tImpl_opencv->data().total() * tImpl_opencv->data().channels()) == (true_mat.total() * true_mat.channels())); - REQUIRE(cv::countNonZero(tImpl_opencv->data() != true_mat) == 0); + // Check the dimensions + REQUIRE((mat_tensor.total() * mat_tensor.channels()) == (true_mat.total() * true_mat.channels())); + // Split it in channels + std::vector<cv::Mat> channels_tensor; + cv::split(mat_tensor, channels_tensor); + + REQUIRE(channels_tensor.size() == channels.size()); + + // Check the elements + for (size_t i = 0; i < channels_tensor.size(); ++i) { + REQUIRE(cv::countNonZero(channels_tensor[i] != channels[i]) == 0); + } // This time the tensor is already loaded in memory std::shared_ptr<Tensor> tensor_load_2; @@ -69,9 +80,20 @@ TEST_CASE("Stimulus creation", "[Stimulus][OpenCV]") { // Access the cv::Mat with the tensor TensorImpl_opencv_* tImpl_opencv_2 = dynamic_cast<TensorImpl_opencv_*>(tensor_load_2->getImpl().get()); + auto mat_tensor_2 = tImpl_opencv_2->data(); - REQUIRE((tImpl_opencv_2->data().total() * tImpl_opencv_2->data().channels()) == (true_mat.total() * true_mat.channels())); - REQUIRE(cv::countNonZero(tImpl_opencv_2->data() != true_mat) == 0); + // Check the dimensions + REQUIRE((mat_tensor_2.total() * mat_tensor_2.channels()) == (true_mat.total() * true_mat.channels())); + // Split it in channels + std::vector<cv::Mat> channels_tensor_2; + cv::split(mat_tensor_2, channels_tensor_2); + + REQUIRE(channels_tensor_2.size() == channels.size()); + + // Check the elements + for (size_t i = 0; i < channels_tensor_2.size(); ++i) { + REQUIRE(cv::countNonZero(channels_tensor_2[i] != channels[i]) == 0); + } } } diff --git a/unit_tests/Test_StimulusImpl_opencv_imread.cpp b/unit_tests/Test_StimulusImpl_opencv_imread.cpp index b3b2b1999e39ab9512597ae932b72679029adc4d..4fd5a994443278c1cc5dbce11e517fa6235e80b8 100644 --- a/unit_tests/Test_StimulusImpl_opencv_imread.cpp +++ b/unit_tests/Test_StimulusImpl_opencv_imread.cpp @@ -59,9 +59,20 @@ TEST_CASE("StimulusImpl_opencv_imread creation", "[StimulusImpl_opencv_imread][O // Access the cv::Mat with the tensor TensorImpl_opencv_* tImpl_opencv = dynamic_cast<TensorImpl_opencv_*>(tensor_load->getImpl().get()); + auto mat_tensor = tImpl_opencv->data(); - REQUIRE((tImpl_opencv->data().total() * tImpl_opencv->data().channels()) == (true_mat.total() * true_mat.channels())); - REQUIRE(cv::countNonZero(tImpl_opencv->data() != true_mat) == 0); + // Check the dimensions + REQUIRE((mat_tensor.total() * mat_tensor.channels()) == (true_mat.total() * true_mat.channels())); + // Split it in channels + std::vector<cv::Mat> channels_tensor; + cv::split(mat_tensor, channels_tensor); + + REQUIRE(channels_tensor.size() == channels.size()); + + // Check the elements + for (size_t i = 0; i < channels_tensor.size(); ++i) { + REQUIRE(cv::countNonZero(channels_tensor[i] != channels[i]) == 0); + } } }