1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
9 #include "opencv2/core.hpp"
10 #include "opencv2/gapi/cpu/core.hpp"
12 #include <gtest/gtest.h>
16 std::ostream& operator<<(std::ostream& o, const cv::GCompileArg& arg)
18 return o << (arg.tag.empty() ? "empty" : arg.tag);
35 void initMatsRandU(int type, cv::Size sz_in, int dtype, bool createOutputMatrices = true)
37 in_mat1 = cv::Mat(sz_in, type);
38 in_mat2 = cv::Mat(sz_in, type);
40 auto& rng = cv::theRNG();
41 sc = cv::Scalar(rng(100),rng(100),rng(100),rng(100));
42 cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255));
43 cv::randu(in_mat2, cv::Scalar::all(0), cv::Scalar::all(255));
45 if (createOutputMatrices && dtype != -1)
47 out_mat_gapi = cv::Mat (sz_in, dtype);
48 out_mat_ocv = cv::Mat (sz_in, dtype);
52 void initMatrixRandU(int type, cv::Size sz_in, int dtype, bool createOutputMatrices = true)
54 in_mat1 = cv::Mat(sz_in, type);
56 auto& rng = cv::theRNG();
57 sc = cv::Scalar(rng(100),rng(100),rng(100),rng(100));
59 cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255));
61 if (createOutputMatrices && dtype != -1)
63 out_mat_gapi = cv::Mat (sz_in, dtype);
64 out_mat_ocv = cv::Mat (sz_in, dtype);
68 void initMatsRandN(int type, cv::Size sz_in, int dtype, bool createOutputMatrices = true)
70 in_mat1 = cv::Mat(sz_in, type);
71 cv::randn(in_mat1, cv::Scalar::all(127), cv::Scalar::all(40.f));
73 if (createOutputMatrices && dtype != -1)
75 out_mat_gapi = cv::Mat(sz_in, dtype);
76 out_mat_ocv = cv::Mat(sz_in, dtype);
80 static cv::Mat nonZeroPixels(const cv::Mat& mat)
82 int channels = mat.channels();
83 std::vector<cv::Mat> split(channels);
84 cv::split(mat, split);
86 for (int c=0; c < channels; c++)
89 result = split[c] != 0;
91 result = result | (split[c] != 0);
96 static int countNonZeroPixels(const cv::Mat& mat)
98 return cv::countNonZero( nonZeroPixels(mat) );
104 class TestParams: public TestFunctional, public testing::TestWithParam<T>{};