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 #ifndef OPENCV_GAPI_IMGPROC_TESTS_INL_HPP
9 #define OPENCV_GAPI_IMGPROC_TESTS_INL_HPP
11 #include "opencv2/gapi/imgproc.hpp"
12 #include "gapi_imgproc_tests.hpp"
16 TEST_P(Filter2DTest, AccuracyTest)
20 int kernSize = 0, borderType = 0, dtype = 0;
23 cv::GCompileArgs compile_args;
24 std::tie(cmpF, type, kernSize, sz, borderType, dtype, initOut, compile_args) = GetParam();
25 initMatsRandN(type, sz, dtype, initOut);
27 cv::Point anchor = {-1, -1};
30 cv::Mat kernel = cv::Mat(kernSize, kernSize, CV_32FC1 );
31 cv::Scalar kernMean = cv::Scalar(1.0);
32 cv::Scalar kernStddev = cv::Scalar(2.0/3);
33 randn(kernel, kernMean, kernStddev);
35 // G-API code //////////////////////////////////////////////////////////////
37 auto out = cv::gapi::filter2D(in, dtype, kernel, anchor, delta, borderType);
39 cv::GComputation c(in, out);
40 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
41 // OpenCV code /////////////////////////////////////////////////////////////
43 cv::filter2D(in_mat1, out_mat_ocv, dtype, kernel, anchor, delta, borderType);
45 // Comparison //////////////////////////////////////////////////////////////
47 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
48 EXPECT_EQ(out_mat_gapi.size(), sz);
52 TEST_P(BoxFilterTest, AccuracyTest)
56 int filterSize = 0, borderType = 0, dtype = 0;
59 cv::GCompileArgs compile_args;
60 std::tie(cmpF, type, filterSize, sz, borderType, dtype, initOut, compile_args) = GetParam();
61 initMatsRandN(type, sz, dtype, initOut);
63 cv::Point anchor = {-1, -1};
64 bool normalize = true;
66 // G-API code //////////////////////////////////////////////////////////////
68 auto out = cv::gapi::boxFilter(in, dtype, cv::Size(filterSize, filterSize), anchor, normalize, borderType);
70 cv::GComputation c(in, out);
71 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
72 // OpenCV code /////////////////////////////////////////////////////////////
74 cv::boxFilter(in_mat1, out_mat_ocv, dtype, cv::Size(filterSize, filterSize), anchor, normalize, borderType);
76 // Comparison //////////////////////////////////////////////////////////////
78 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
79 EXPECT_EQ(out_mat_gapi.size(), sz);
83 TEST_P(SepFilterTest, AccuracyTest)
87 int kernSize = 0, dtype = 0;
90 cv::GCompileArgs compile_args;
91 std::tie(cmpF, type, kernSize, sz, dtype, initOut, compile_args) = GetParam();
93 cv::Mat kernelX(kernSize, 1, CV_32F);
94 cv::Mat kernelY(kernSize, 1, CV_32F);
95 randu(kernelX, -1, 1);
96 randu(kernelY, -1, 1);
97 initMatsRandN(type, sz, dtype, initOut);
99 cv::Point anchor = cv::Point(-1, -1);
101 // G-API code //////////////////////////////////////////////////////////////
103 auto out = cv::gapi::sepFilter(in, dtype, kernelX, kernelY, anchor, cv::Scalar() );
105 cv::GComputation c(in, out);
106 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
107 // OpenCV code /////////////////////////////////////////////////////////////
109 cv::sepFilter2D(in_mat1, out_mat_ocv, dtype, kernelX, kernelY );
111 // Comparison //////////////////////////////////////////////////////////////
113 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
114 EXPECT_EQ(out_mat_gapi.size(), sz);
118 TEST_P(BlurTest, AccuracyTest)
122 int filterSize = 0, borderType = 0;
124 bool initOut = false;
125 cv::GCompileArgs compile_args;
126 std::tie(cmpF, type, filterSize, sz, borderType, initOut, compile_args) = GetParam();
127 initMatsRandN(type, sz, type, initOut);
129 cv::Point anchor = {-1, -1};
131 // G-API code //////////////////////////////////////////////////////////////
133 auto out = cv::gapi::blur(in, cv::Size(filterSize, filterSize), anchor, borderType);
135 cv::GComputation c(in, out);
136 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
137 // OpenCV code /////////////////////////////////////////////////////////////
139 cv::blur(in_mat1, out_mat_ocv, cv::Size(filterSize, filterSize), anchor, borderType);
141 // Comparison //////////////////////////////////////////////////////////////
143 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
144 EXPECT_EQ(out_mat_gapi.size(), sz);
148 TEST_P(GaussianBlurTest, AccuracyTest)
154 bool initOut = false;
155 cv::GCompileArgs compile_args;
156 std::tie(cmpF,type, kernSize, sz, initOut, compile_args) = GetParam();
157 initMatsRandN(type, sz, type, initOut);
159 cv::Size kSize = cv::Size(kernSize, kernSize);
160 double sigmaX = rand();
162 // G-API code //////////////////////////////////////////////////////////////
164 auto out = cv::gapi::gaussianBlur(in, kSize, sigmaX);
166 cv::GComputation c(in, out);
167 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
168 // OpenCV code /////////////////////////////////////////////////////////////
170 cv::GaussianBlur(in_mat1, out_mat_ocv, kSize, sigmaX);
172 // Comparison //////////////////////////////////////////////////////////////
174 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
175 EXPECT_EQ(out_mat_gapi.size(), sz);
179 TEST_P(MedianBlurTest, AccuracyTest)
185 bool initOut = false;
186 cv::GCompileArgs compile_args;
187 std::tie(cmpF, type, kernSize, sz, initOut, compile_args) = GetParam();
188 initMatsRandN(type, sz, type, initOut);
190 // G-API code //////////////////////////////////////////////////////////////
192 auto out = cv::gapi::medianBlur(in, kernSize);
194 cv::GComputation c(in, out);
195 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
196 // OpenCV code /////////////////////////////////////////////////////////////
198 cv::medianBlur(in_mat1, out_mat_ocv, kernSize);
200 // Comparison //////////////////////////////////////////////////////////////
202 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
203 EXPECT_EQ(out_mat_gapi.size(), sz);
207 TEST_P(ErodeTest, AccuracyTest)
211 int kernSize = 0, kernType = 0;
213 bool initOut = false;
214 cv::GCompileArgs compile_args;
215 std::tie(cmpF, type, kernSize, sz, kernType, initOut, compile_args) = GetParam();
216 initMatsRandN(type, sz, type, initOut);
218 cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize));
220 // G-API code //////////////////////////////////////////////////////////////
222 auto out = cv::gapi::erode(in, kernel);
224 cv::GComputation c(in, out);
225 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
226 // OpenCV code /////////////////////////////////////////////////////////////
228 cv::erode(in_mat1, out_mat_ocv, kernel);
230 // Comparison //////////////////////////////////////////////////////////////
232 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
233 EXPECT_EQ(out_mat_gapi.size(), sz);
237 TEST_P(Erode3x3Test, AccuracyTest)
243 bool initOut = false;
244 cv::GCompileArgs compile_args;
245 std::tie(cmpF, type, sz, initOut, numIters, compile_args) = GetParam();
246 initMatsRandN(type, sz, type, initOut);
248 cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3,3));
250 // G-API code //////////////////////////////////////////////////////////////
252 auto out = cv::gapi::erode3x3(in, numIters);
254 cv::GComputation c(in, out);
255 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
256 // OpenCV code /////////////////////////////////////////////////////////////
258 cv::erode(in_mat1, out_mat_ocv, kernel, cv::Point(-1, -1), numIters);
260 // Comparison //////////////////////////////////////////////////////////////
262 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
263 EXPECT_EQ(out_mat_gapi.size(), sz);
267 TEST_P(DilateTest, AccuracyTest)
271 int kernSize = 0, kernType = 0;
273 bool initOut = false;
274 cv::GCompileArgs compile_args;
275 std::tie(cmpF, type, kernSize, sz, kernType, initOut, compile_args) = GetParam();
276 initMatsRandN(type, sz, type, initOut);
278 cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize));
280 // G-API code //////////////////////////////////////////////////////////////
282 auto out = cv::gapi::dilate(in, kernel);
284 cv::GComputation c(in, out);
285 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
286 // OpenCV code /////////////////////////////////////////////////////////////
288 cv::dilate(in_mat1, out_mat_ocv, kernel);
290 // Comparison //////////////////////////////////////////////////////////////
292 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
293 EXPECT_EQ(out_mat_gapi.size(), sz);
297 TEST_P(Dilate3x3Test, AccuracyTest)
303 bool initOut = false;
304 cv::GCompileArgs compile_args;
305 std::tie(cmpF, type, sz, initOut, numIters, compile_args) = GetParam();
306 initMatsRandN(type, sz, type, initOut);
308 cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3,3));
310 // G-API code //////////////////////////////////////////////////////////////
312 auto out = cv::gapi::dilate3x3(in, numIters);
314 cv::GComputation c(in, out);
315 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
316 // OpenCV code /////////////////////////////////////////////////////////////
318 cv::dilate(in_mat1, out_mat_ocv, kernel, cv::Point(-1,-1), numIters);
320 // Comparison //////////////////////////////////////////////////////////////
322 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
323 EXPECT_EQ(out_mat_gapi.size(), sz);
328 TEST_P(SobelTest, AccuracyTest)
332 int kernSize = 0, dtype = 0, dx = 0, dy = 0;
334 bool initOut = false;
335 cv::GCompileArgs compile_args;
336 std::tie(cmpF, type, kernSize, sz, dtype, dx, dy, initOut, compile_args) = GetParam();
337 initMatsRandN(type, sz, dtype, initOut);
339 // G-API code //////////////////////////////////////////////////////////////
341 auto out = cv::gapi::Sobel(in, dtype, dx, dy, kernSize );
343 cv::GComputation c(in, out);
344 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
345 // OpenCV code /////////////////////////////////////////////////////////////
347 cv::Sobel(in_mat1, out_mat_ocv, dtype, dx, dy, kernSize);
349 // Comparison //////////////////////////////////////////////////////////////
351 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
352 EXPECT_EQ(out_mat_gapi.size(), sz);
356 TEST_P(EqHistTest, AccuracyTest)
360 bool initOut = false;
361 cv::GCompileArgs compile_args;
362 std::tie(cmpF, sz, initOut, compile_args) = GetParam();
363 initMatsRandN(CV_8UC1, sz, CV_8UC1, initOut);
365 // G-API code //////////////////////////////////////////////////////////////
367 auto out = cv::gapi::equalizeHist(in);
369 cv::GComputation c(in, out);
370 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
371 // OpenCV code /////////////////////////////////////////////////////////////
373 cv::equalizeHist(in_mat1, out_mat_ocv);
375 // Comparison //////////////////////////////////////////////////////////////
377 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
378 EXPECT_EQ(out_mat_gapi.size(), std::get<1>(GetParam()));
382 TEST_P(CannyTest, AccuracyTest)
387 double thrLow = 0.0, thrUp = 0.0;
389 bool l2gr = false, initOut = false;
390 cv::GCompileArgs compile_args;
391 std::tie(cmpF, type, sz, thrLow, thrUp, apSize, l2gr, initOut, compile_args) = GetParam();
393 initMatsRandN(type, sz, CV_8UC1, initOut);
395 // G-API code //////////////////////////////////////////////////////////////
397 auto out = cv::gapi::Canny(in, thrLow, thrUp, apSize, l2gr);
399 cv::GComputation c(in, out);
400 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
401 // OpenCV code /////////////////////////////////////////////////////////////
403 cv::Canny(in_mat1, out_mat_ocv, thrLow, thrUp, apSize, l2gr);
405 // Comparison //////////////////////////////////////////////////////////////
407 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
408 EXPECT_EQ(out_mat_gapi.size(), sz);
412 TEST_P(RGB2GrayTest, AccuracyTest)
414 auto param = GetParam();
415 auto compile_args = std::get<3>(param);
416 compare_f cmpF = std::get<0>(param);
417 initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC1, std::get<2>(param));
419 // G-API code //////////////////////////////////////////////////////////////
421 auto out = cv::gapi::RGB2Gray(in);
423 cv::GComputation c(in, out);
424 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
425 // OpenCV code /////////////////////////////////////////////////////////////
427 cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2GRAY);
429 // Comparison //////////////////////////////////////////////////////////////
431 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
432 EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));
436 TEST_P(BGR2GrayTest, AccuracyTest)
438 auto param = GetParam();
439 auto compile_args = std::get<3>(param);
440 compare_f cmpF = std::get<0>(param);
441 initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC1, std::get<2>(param));
443 // G-API code //////////////////////////////////////////////////////////////
445 auto out = cv::gapi::BGR2Gray(in);
447 cv::GComputation c(in, out);
448 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
449 // OpenCV code /////////////////////////////////////////////////////////////
451 cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2GRAY);
453 // Comparison //////////////////////////////////////////////////////////////
455 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
456 EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));
460 TEST_P(RGB2YUVTest, AccuracyTest)
462 auto param = GetParam();
463 auto compile_args = std::get<3>(param);
464 compare_f cmpF = std::get<0>(param);
465 initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
467 // G-API code //////////////////////////////////////////////////////////////
469 auto out = cv::gapi::RGB2YUV(in);
471 cv::GComputation c(in, out);
472 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
473 // OpenCV code /////////////////////////////////////////////////////////////
475 cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2YUV);
477 // Comparison //////////////////////////////////////////////////////////////
479 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
480 EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));
484 TEST_P(YUV2RGBTest, AccuracyTest)
486 auto param = GetParam();
487 auto compile_args = std::get<3>(param);
488 compare_f cmpF = std::get<0>(param);
489 initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
492 // G-API code //////////////////////////////////////////////////////////////
494 auto out = cv::gapi::YUV2RGB(in);
496 cv::GComputation c(in, out);
497 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
498 // OpenCV code /////////////////////////////////////////////////////////////
500 cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2RGB);
502 // Comparison //////////////////////////////////////////////////////////////
504 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
505 EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));
509 TEST_P(RGB2LabTest, AccuracyTest)
511 auto param = GetParam();
512 auto compile_args = std::get<3>(param);
513 compare_f cmpF = std::get<0>(param);
514 initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
516 // G-API code //////////////////////////////////////////////////////////////
518 auto out = cv::gapi::RGB2Lab(in);
520 cv::GComputation c(in, out);
521 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
522 // OpenCV code /////////////////////////////////////////////////////////////
524 cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2Lab);
526 // Comparison //////////////////////////////////////////////////////////////
528 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
529 EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));
533 TEST_P(BGR2LUVTest, AccuracyTest)
535 auto param = GetParam();
536 auto compile_args = std::get<3>(param);
537 compare_f cmpF = std::get<0>(param);
538 initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
540 // G-API code //////////////////////////////////////////////////////////////
542 auto out = cv::gapi::BGR2LUV(in);
544 cv::GComputation c(in, out);
545 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
546 // OpenCV code /////////////////////////////////////////////////////////////
548 cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2Luv);
550 // Comparison //////////////////////////////////////////////////////////////
552 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
553 EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));
557 TEST_P(LUV2BGRTest, AccuracyTest)
559 auto param = GetParam();
560 auto compile_args = std::get<3>(param);
561 compare_f cmpF = std::get<0>(param);
562 initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
564 // G-API code //////////////////////////////////////////////////////////////
566 auto out = cv::gapi::LUV2BGR(in);
568 cv::GComputation c(in, out);
569 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
570 // OpenCV code /////////////////////////////////////////////////////////////
572 cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_Luv2BGR);
574 // Comparison //////////////////////////////////////////////////////////////
576 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
577 EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));
581 TEST_P(BGR2YUVTest, AccuracyTest)
583 auto param = GetParam();
584 auto compile_args = std::get<3>(param);
585 compare_f cmpF = std::get<0>(param);
586 initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
588 // G-API code //////////////////////////////////////////////////////////////
590 auto out = cv::gapi::BGR2YUV(in);
592 cv::GComputation c(in, out);
593 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
594 // OpenCV code /////////////////////////////////////////////////////////////
596 cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2YUV);
598 // Comparison //////////////////////////////////////////////////////////////
600 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
601 EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));
605 TEST_P(YUV2BGRTest, AccuracyTest)
607 auto param = GetParam();
608 auto compile_args = std::get<3>(param);
609 compare_f cmpF = std::get<0>(param);
610 initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param));
612 // G-API code //////////////////////////////////////////////////////////////
614 auto out = cv::gapi::YUV2BGR(in);
616 cv::GComputation c(in, out);
617 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
618 // OpenCV code /////////////////////////////////////////////////////////////
620 cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2BGR);
622 // Comparison //////////////////////////////////////////////////////////////
624 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
625 EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param));
630 #endif //OPENCV_GAPI_IMGPROC_TESTS_INL_HPP