1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
5 // Copyright (C) 2018-2019 Intel Corporation
8 #include "test_precomp.hpp"
10 #include "gapi_fluid_test_kernels.hpp"
15 using namespace cv::gapi_test_kernels;
17 struct PartialComputation : public TestWithParam <std::tuple<cv::Rect>> {};
18 TEST_P(PartialComputation, Test)
21 std::tie(roi) = GetParam();
23 int borderType = BORDER_REPLICATE;
25 cv::Point anchor = {-1, -1};
28 cv::GMat out = TBlur3x3::on(in, borderType, {});
29 cv::GComputation c(cv::GIn(in), cv::GOut(out));
31 const auto sz = cv::Size(8, 10);
32 cv::Mat in_mat(sz, CV_8UC1);
33 cv::Scalar mean = cv::Scalar(127.0f);
34 cv::Scalar stddev = cv::Scalar(40.f);
35 cv::randn(in_mat, mean, stddev);
37 cv::Mat out_mat_gapi = cv::Mat::zeros(sz, CV_8UC1);
38 cv::Mat out_mat_ocv = cv::Mat::zeros(sz, CV_8UC1);
41 auto cc = c.compile(cv::descr_of(in_mat), cv::compile_args(fluidTestPackage, GFluidOutputRois{{to_own(roi)}}));
42 cc(cv::gin(in_mat), cv::gout(out_mat_gapi));
45 if (roi == cv::Rect{}) roi = cv::Rect{0,0,sz.width,sz.height};
46 cv::blur(in_mat(roi), out_mat_ocv(roi), {kernelSize, kernelSize}, anchor, borderType);
48 EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
51 INSTANTIATE_TEST_CASE_P(Fluid, PartialComputation,
52 Values(cv::Rect{}, cv::Rect{0,0,8,6}, cv::Rect{0,1,8,3},
53 cv::Rect{0,2,8,3}, cv::Rect{0,3,8,5}, cv::Rect{0,4,8,6}));
55 struct PartialComputationAddC : public TestWithParam <std::tuple<cv::Rect>> {};
56 TEST_P(PartialComputationAddC, Test)
59 std::tie(roi) = GetParam();
62 cv::GMat out = TAddCSimple::on(in, 1);
63 cv::GComputation c(cv::GIn(in), cv::GOut(out));
65 const auto sz = cv::Size(8, 10);
66 cv::Mat in_mat(sz, CV_8UC1);
67 cv::Scalar mean = cv::Scalar(127.0f);
68 cv::Scalar stddev = cv::Scalar(40.f);
69 cv::randn(in_mat, mean, stddev);
71 cv::Mat out_mat_gapi = cv::Mat::zeros(sz, CV_8UC1);
72 cv::Mat out_mat_ocv = cv::Mat::zeros(sz, CV_8UC1);
75 auto cc = c.compile(cv::descr_of(in_mat), cv::compile_args(fluidTestPackage, GFluidOutputRois{{to_own(roi)}}));
76 cc(cv::gin(in_mat), cv::gout(out_mat_gapi));
79 if (roi == cv::Rect{}) roi = cv::Rect{0,0,sz.width,sz.height};
80 out_mat_ocv(roi) = in_mat(roi) + 1;
82 EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
85 INSTANTIATE_TEST_CASE_P(FluidRoi, PartialComputationAddC,
86 Values(cv::Rect{}, cv::Rect{0,0,8,6}, cv::Rect{0,1,8,3},
87 cv::Rect{0,2,8,3}, cv::Rect{0,3,8,5}, cv::Rect{0,4,8,6}));
89 struct SequenceOfBlursRoiTest : public TestWithParam <std::tuple<int, cv::Rect>> {};
90 TEST_P(SequenceOfBlursRoiTest, Test)
92 cv::Size sz_in = { 320, 240 };
96 std::tie(borderType, roi) = GetParam();
97 cv::Mat in_mat(sz_in, CV_8UC1);
98 cv::Scalar mean = cv::Scalar(127.0f);
99 cv::Scalar stddev = cv::Scalar(40.f);
101 cv::randn(in_mat, mean, stddev);
103 cv::Point anchor = {-1, -1};
104 cv::Scalar borderValue(0);
107 auto mid = TBlur3x3::on(in, borderType, borderValue);
108 auto out = TBlur5x5::on(mid, borderType, borderValue);
110 Mat out_mat_gapi = Mat::zeros(sz_in, CV_8UC1);
112 GComputation c(GIn(in), GOut(out));
113 auto cc = c.compile(descr_of(in_mat), cv::compile_args(fluidTestPackage, GFluidOutputRois{{to_own(roi)}}));
114 cc(gin(in_mat), gout(out_mat_gapi));
116 cv::Mat mid_mat_ocv = Mat::zeros(sz_in, CV_8UC1);
117 cv::Mat out_mat_ocv = Mat::zeros(sz_in, CV_8UC1);
119 cv::blur(in_mat, mid_mat_ocv, {3,3}, anchor, borderType);
121 if (roi == cv::Rect{})
123 roi = cv::Rect{0, 0, sz_in.width, sz_in.height};
126 cv::blur(mid_mat_ocv(roi), out_mat_ocv(roi), {5,5}, anchor, borderType);
128 EXPECT_EQ(0, countNonZero(out_mat_ocv != out_mat_gapi));
131 INSTANTIATE_TEST_CASE_P(FluidRoi, SequenceOfBlursRoiTest,
132 Combine(Values(BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT_101),
133 Values(cv::Rect{0,0,320,240}, cv::Rect{0,64,320,128}, cv::Rect{0,128,320,112})));
135 struct TwoBlursRoiTest : public TestWithParam <std::tuple<int, int, int, int, int, int, bool, cv::Rect>> {};
136 TEST_P(TwoBlursRoiTest, Test)
138 cv::Size sz_in = { 320, 240 };
140 int kernelSize1 = 0, kernelSize2 = 0;
141 int borderType1 = -1, borderType2 = -1;
142 cv::Scalar borderValue1{}, borderValue2{};
143 bool readFromInput = false;
145 std::tie(kernelSize1, borderType1, borderValue1, kernelSize2, borderType2, borderValue2, readFromInput, outRoi) = GetParam();
146 cv::Mat in_mat(sz_in, CV_8UC1);
147 cv::Scalar mean = cv::Scalar(127.0f);
148 cv::Scalar stddev = cv::Scalar(40.f);
150 cv::randn(in_mat, mean, stddev);
152 cv::Point anchor = {-1, -1};
154 auto blur1 = kernelSize1 == 3 ? &TBlur3x3::on : TBlur5x5::on;
155 auto blur2 = kernelSize2 == 3 ? &TBlur3x3::on : TBlur5x5::on;
160 out1 = blur1(in, borderType1, borderValue1);
161 out2 = blur2(in, borderType2, borderValue2);
165 auto mid = TAddCSimple::on(in, 0);
166 out1 = blur1(mid, borderType1, borderValue1);
167 out2 = blur2(mid, borderType2, borderValue2);
170 Mat out_mat_gapi1 = Mat::zeros(sz_in, CV_8UC1);
171 Mat out_mat_gapi2 = Mat::zeros(sz_in, CV_8UC1);
173 GComputation c(GIn(in), GOut(out1, out2));
174 auto cc = c.compile(descr_of(in_mat), cv::compile_args(fluidTestPackage, GFluidOutputRois{{outRoi, outRoi}}));
175 cc(gin(in_mat), gout(out_mat_gapi1, out_mat_gapi2));
177 cv::Mat out_mat_ocv1 = Mat::zeros(sz_in, CV_8UC1);
178 cv::Mat out_mat_ocv2 = Mat::zeros(sz_in, CV_8UC1);
180 cv::blur(in_mat(outRoi), out_mat_ocv1(outRoi), {kernelSize1, kernelSize1}, anchor, borderType1);
181 cv::blur(in_mat(outRoi), out_mat_ocv2(outRoi), {kernelSize2, kernelSize2}, anchor, borderType2);
183 EXPECT_EQ(0, countNonZero(out_mat_ocv1 != out_mat_gapi1));
184 EXPECT_EQ(0, countNonZero(out_mat_ocv2 != out_mat_gapi2));
187 INSTANTIATE_TEST_CASE_P(FluidRoi, TwoBlursRoiTest,
188 Combine(Values(3, 5),
189 Values(cv::BORDER_CONSTANT, cv::BORDER_REPLICATE, cv::BORDER_REFLECT_101),
192 Values(cv::BORDER_CONSTANT, cv::BORDER_REPLICATE, cv::BORDER_REFLECT_101),
194 testing::Bool(), // Read from input directly or place a copy node at start
195 Values(cv::Rect{0,0,320,240}, cv::Rect{0,64,320,128}, cv::Rect{0,128,320,112})));
197 } // namespace opencv_test