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

Generate random matrix instead of loading a path for CI tests

parent e5532a07
No related branches found
No related tags found
2 merge requests!10Update backend_opencv with modifications from aidge_core,!9Remove dependency of backend CPU and fix CI
Pipeline #39365 failed
...@@ -19,17 +19,37 @@ ...@@ -19,17 +19,37 @@
#include "aidge/backend/opencv/data/TensorImpl.hpp" #include "aidge/backend/opencv/data/TensorImpl.hpp"
#include "aidge/data/Tensor.hpp" #include "aidge/data/Tensor.hpp"
#include "Tools.hpp"
using namespace Aidge; using namespace Aidge;
TEST_CASE("Stimulus creation", "[Stimulus][OpenCV]") { TEST_CASE("Stimulus creation", "[Stimulus][OpenCV]") {
SECTION("Instanciation & load an image") { SECTION("Instanciation & load an image") {
// Load image with imread // // Load image with imread
cv::Mat true_mat = cv::imread("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/train-images-idx3-ubyte[00001].pgm", cv::IMREAD_UNCHANGED); // cv::Mat true_mat = cv::imread("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/train-images-idx3-ubyte[00001].pgm", cv::IMREAD_UNCHANGED);
REQUIRE(true_mat.empty()==false); // REQUIRE(true_mat.empty()==false);
// // Create Stimulus
// Stimulus stimg("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/train-images-idx3-ubyte[00001].pgm", true);
// stimg.setBackend("opencv");
// Generate random matrix and save it
std::vector<cv::Mat> channels;
cv::Mat true_mat;
for (int c = 0; c < 3; ++c){
// Create a random matrix
cv::Mat randomMat = createRandomMat<unsigned char>(224, 224);
// Add each random matrix to the vector
channels.push_back(randomMat);
}
// Merge the vector of cv mat into one cv mat
cv::merge(channels, true_mat);
cv::imwrite("output_image.png", true_mat);
// Create Stimulus // Create Stimulus
Stimulus stimg("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/train-images-idx3-ubyte[00001].pgm", true); Stimulus stimg("output_image.png", true);
stimg.setBackend("opencv"); stimg.setBackend("opencv");
// Load the image in a tensor & save it in memory // Load the image in a tensor & save it in memory
......
...@@ -19,19 +19,41 @@ ...@@ -19,19 +19,41 @@
#include "aidge/backend/opencv/data/TensorImpl.hpp" #include "aidge/backend/opencv/data/TensorImpl.hpp"
#include "aidge/data/Tensor.hpp" #include "aidge/data/Tensor.hpp"
#include "Tools.hpp"
using namespace Aidge; using namespace Aidge;
TEST_CASE("StimulusImpl_opencv_imread creation", "[StimulusImpl_opencv_imread][OpenCV]") { TEST_CASE("StimulusImpl_opencv_imread creation", "[StimulusImpl_opencv_imread][OpenCV]") {
SECTION("Instanciation & load an image") { SECTION("Instanciation & load an image") {
// Load image with imread // // Load image with imread
// cv::Mat true_mat = cv::imread("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/Lenna.png"); // // cv::Mat true_mat = cv::imread("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/Lenna.png");
cv::Mat true_mat = cv::imread("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/train-images-idx3-ubyte[00001].pgm", cv::IMREAD_UNCHANGED); // cv::Mat true_mat = cv::imread("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/train-images-idx3-ubyte[00001].pgm", cv::IMREAD_UNCHANGED);
REQUIRE(true_mat.empty()==false); // REQUIRE(true_mat.empty()==false);
// Create StimulusImpl_opencv_imread // // Create StimulusImpl_opencv_imread
// StimulusImpl_opencv_imread stImpl("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/Lenna.png"); // // StimulusImpl_opencv_imread stImpl("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/Lenna.png");
StimulusImpl_opencv_imread stImpl("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/train-images-idx3-ubyte[00001].pgm"); // StimulusImpl_opencv_imread stImpl("/data1/is156025/tb256203/dev/eclipse_aidge/aidge/user_tests/train-images-idx3-ubyte[00001].pgm");
// Generate random matrix and save it
std::vector<cv::Mat> channels;
cv::Mat true_mat;
for (int c = 0; c < 3; ++c){
// Create a random matrix
cv::Mat randomMat = createRandomMat<unsigned char>(224, 224);
// Add each random matrix to the vector
channels.push_back(randomMat);
}
// Merge the vector of cv mat into one cv mat
cv::merge(channels, true_mat);
// Save image into a png file
cv::imwrite("output_image_stimpl.png", true_mat);
// Instanciate timulusImpl_opencv_imread
StimulusImpl_opencv_imread stImpl("output_image_stimpl.png");
// Load the image as a tensor
std::shared_ptr<Tensor> tensor_load; std::shared_ptr<Tensor> tensor_load;
tensor_load = stImpl.load(); tensor_load = stImpl.load();
......
...@@ -21,18 +21,10 @@ ...@@ -21,18 +21,10 @@
#include "aidge/backend/opencv/data/TensorImpl.hpp" #include "aidge/backend/opencv/data/TensorImpl.hpp"
#include "aidge/backend/cpu/data/TensorImpl.hpp" #include "aidge/backend/cpu/data/TensorImpl.hpp"
#include "Tools.hpp"
using namespace Aidge; using namespace Aidge;
template <typename T>
cv::Mat createRandomMat(int rows, int cols) {
cv::Mat randomMat(rows, cols, cv::DataType<T>::type);
cv::randu(randomMat, cv::Scalar::all(0), cv::Scalar::all(255));
return randomMat;
}
// TEMPLATE_TEST_CASE("Opencv Utils", "[Utils][OpenCV]", char, unsigned char, short, unsigned short, int, float, double) { // TEMPLATE_TEST_CASE("Opencv Utils", "[Utils][OpenCV]", char, unsigned char, short, unsigned short, int, float, double) {
// TODO : perform test for char and double // TODO : perform test for char and double
TEMPLATE_TEST_CASE("Opencv Utils", "[Utils][OpenCV]", signed char, unsigned char, short, unsigned short, int, float, double) { TEMPLATE_TEST_CASE("Opencv Utils", "[Utils][OpenCV]", signed char, unsigned char, short, unsigned short, int, float, double) {
......
/********************************************************************************
* Copyright (c) 2023 CEA-List
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
#ifndef AIDGE_OPENCV_TOOLS_H_
#define AIDGE_OPENCV_TOOLS_H_
#include "opencv2/core.hpp"
template <typename T>
cv::Mat createRandomMat(int rows, int cols) {
cv::Mat randomMat(rows, cols, cv::DataType<T>::type);
cv::randu(randomMat, cv::Scalar::all(0), cv::Scalar::all(255));
return randomMat;
}
#endif // AIDGE_OPENCV_TESTS_UTILS_H_
\ No newline at end of file
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