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_CORE_PERF_TESTS_INL_HPP
9 #define OPENCV_GAPI_CORE_PERF_TESTS_INL_HPP
13 #include "gapi_core_perf_tests.hpp"
19 //------------------------------------------------------------------------------
21 PERF_TEST_P_(AddPerfTest, TestPerformance)
23 Size sz = get<0>(GetParam());
24 MatType type = get<1>(GetParam());
25 int dtype = get<2>(GetParam());
26 cv::GCompileArgs compile_args = get<3>(GetParam());
28 initMatsRandU(type, sz, dtype, false);
30 // OpenCV code ///////////////////////////////////////////////////////////
31 cv::add(in_mat1, in_mat2, out_mat_ocv, cv::noArray(), dtype);
33 // G-API code ////////////////////////////////////////////////////////////
34 cv::GMat in1, in2, out;
35 out = cv::gapi::add(in1, in2, dtype);
36 cv::GComputation c(GIn(in1, in2), GOut(out));
38 // Warm-up graph engine:
39 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
43 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
46 // Comparison ////////////////////////////////////////////////////////////
47 // FIXIT unrealiable check: EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
48 EXPECT_EQ(out_mat_gapi.size(), sz);
50 SANITY_CHECK_NOTHING();
53 //------------------------------------------------------------------------------
55 PERF_TEST_P_(AddCPerfTest, TestPerformance)
57 Size sz = get<0>(GetParam());
58 MatType type = get<1>(GetParam());
59 int dtype = get<2>(GetParam());
60 cv::GCompileArgs compile_args = get<3>(GetParam());
62 initMatsRandU(type, sz, dtype, false);
64 // OpenCV code ///////////////////////////////////////////////////////////
65 cv::add(in_mat1, sc, out_mat_ocv, cv::noArray(), dtype);
67 // G-API code ////////////////////////////////////////////////////////////
70 out = cv::gapi::addC(in1, sc1, dtype);
71 cv::GComputation c(GIn(in1, sc1), GOut(out));
73 // Warm-up graph engine:
74 c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
78 c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
81 // Comparison ////////////////////////////////////////////////////////////
82 // FIXIT unrealiable check: EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
83 EXPECT_EQ(out_mat_gapi.size(), sz);
85 SANITY_CHECK_NOTHING();
88 //------------------------------------------------------------------------------
90 PERF_TEST_P_(SubPerfTest, TestPerformance)
92 Size sz = get<0>(GetParam());
93 MatType type = get<1>(GetParam());
94 int dtype = get<2>(GetParam());
95 cv::GCompileArgs compile_args = get<3>(GetParam());
97 initMatsRandU(type, sz, dtype, false);
99 // OpenCV code ///////////////////////////////////////////////////////////
100 cv::subtract(in_mat1, in_mat2, out_mat_ocv, cv::noArray(), dtype);
102 // G-API code ////////////////////////////////////////////////////////////
103 cv::GMat in1, in2, out;
104 out = cv::gapi::sub(in1, in2, dtype);
105 cv::GComputation c(GIn(in1, in2), GOut(out));
107 // Warm-up graph engine:
108 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
112 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
115 // Comparison ////////////////////////////////////////////////////////////
116 // FIXIT unrealiable check: EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
117 EXPECT_EQ(out_mat_gapi.size(), sz);
119 SANITY_CHECK_NOTHING();
122 //------------------------------------------------------------------------------
124 PERF_TEST_P_(SubCPerfTest, TestPerformance)
126 Size sz = get<0>(GetParam());
127 MatType type = get<1>(GetParam());
128 int dtype = get<2>(GetParam());
129 cv::GCompileArgs compile_args = get<3>(GetParam());
131 initMatsRandU(type, sz, dtype, false);
133 // OpenCV code ///////////////////////////////////////////////////////////
134 cv::subtract(in_mat1, sc, out_mat_ocv, cv::noArray(), dtype);
136 // G-API code ////////////////////////////////////////////////////////////
139 out = cv::gapi::subC(in1, sc1, dtype);
140 cv::GComputation c(GIn(in1, sc1), GOut(out));
142 // Warm-up graph engine:
143 c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
147 c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
150 // Comparison ////////////////////////////////////////////////////////////
151 // FIXIT unrealiable check: EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
152 EXPECT_EQ(out_mat_gapi.size(), sz);
154 SANITY_CHECK_NOTHING();
157 //------------------------------------------------------------------------------
159 PERF_TEST_P_(SubRCPerfTest, TestPerformance)
161 Size sz = get<0>(GetParam());
162 MatType type = get<1>(GetParam());
163 int dtype = get<2>(GetParam());
164 cv::GCompileArgs compile_args = get<3>(GetParam());
166 initMatsRandU(type, sz, dtype, false);
168 // OpenCV code ///////////////////////////////////////////////////////////
169 cv::subtract(sc, in_mat1, out_mat_ocv, cv::noArray(), dtype);
171 // G-API code ////////////////////////////////////////////////////////////
174 out = cv::gapi::subRC(sc1, in1, dtype);
175 cv::GComputation c(GIn(in1, sc1), GOut(out));
177 // Warm-up graph engine:
178 c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
182 c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
185 // Comparison ////////////////////////////////////////////////////////////
186 // FIXIT unrealiable check: EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
187 EXPECT_EQ(out_mat_gapi.size(), sz);
189 SANITY_CHECK_NOTHING();
192 //------------------------------------------------------------------------------
194 PERF_TEST_P_(MulPerfTest, TestPerformance)
196 Size sz = get<0>(GetParam());
197 MatType type = get<1>(GetParam());
198 int dtype = get<2>(GetParam());
199 cv::GCompileArgs compile_args = get<3>(GetParam());
201 initMatsRandU(type, sz, dtype, false);
203 // OpenCV code ///////////////////////////////////////////////////////////
204 cv::multiply(in_mat1, in_mat2, out_mat_ocv, 1.0, dtype);
206 // G-API code ////////////////////////////////////////////////////////////
207 cv::GMat in1, in2, out;
208 out = cv::gapi::mul(in1, in2, 1.0, dtype);
209 cv::GComputation c(GIn(in1, in2), GOut(out));
211 // Warm-up graph engine:
212 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
216 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
219 // Comparison ////////////////////////////////////////////////////////////
220 // FIXIT unrealiable check: EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
221 EXPECT_EQ(out_mat_gapi.size(), sz);
223 SANITY_CHECK_NOTHING();
226 //------------------------------------------------------------------------------
228 PERF_TEST_P_(MulDoublePerfTest, TestPerformance)
230 Size sz = get<0>(GetParam());
231 MatType type = get<1>(GetParam());
232 int dtype = get<2>(GetParam());
233 cv::GCompileArgs compile_args = get<3>(GetParam());
235 auto& rng = cv::theRNG();
236 double d = rng.uniform(0.0, 10.0);
237 initMatrixRandU(type, sz, dtype, false);
239 // OpenCV code ///////////////////////////////////////////////////////////
240 cv::multiply(in_mat1, d, out_mat_ocv, 1, dtype);
242 // G-API code ////////////////////////////////////////////////////////////
244 out = cv::gapi::mulC(in1, d, dtype);
245 cv::GComputation c(in1, out);
247 // Warm-up graph engine:
248 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
252 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
255 // Comparison ////////////////////////////////////////////////////////////
256 // FIXIT unrealiable check: EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
257 EXPECT_EQ(out_mat_gapi.size(), sz);
259 SANITY_CHECK_NOTHING();
262 //------------------------------------------------------------------------------
264 PERF_TEST_P_(MulCPerfTest, TestPerformance)
266 Size sz = get<0>(GetParam());
267 MatType type = get<1>(GetParam());
268 int dtype = get<2>(GetParam());
269 cv::GCompileArgs compile_args = get<3>(GetParam());
271 initMatsRandU(type, sz, dtype, false);
273 // OpenCV code ///////////////////////////////////////////////////////////
274 cv::multiply(in_mat1, sc, out_mat_ocv, 1, dtype);
276 // G-API code ////////////////////////////////////////////////////////////
279 out = cv::gapi::mulC(in1, sc1, dtype);
280 cv::GComputation c(GIn(in1, sc1), GOut(out));
282 // Warm-up graph engine:
283 c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
287 c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
290 // Comparison ////////////////////////////////////////////////////////////
291 // FIXIT unrealiable check: EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
292 EXPECT_EQ(out_mat_gapi.size(), sz);
294 SANITY_CHECK_NOTHING();
297 //------------------------------------------------------------------------------
299 PERF_TEST_P_(DivPerfTest, TestPerformance)
301 compare_f cmpF = get<0>(GetParam());
302 Size sz = get<1>(GetParam());
303 MatType type = get<2>(GetParam());
304 int dtype = get<3>(GetParam());
305 cv::GCompileArgs compile_args = get<4>(GetParam());
307 // FIXIT Unstable input data for divide
308 initMatsRandU(type, sz, dtype, false);
310 // OpenCV code ///////////////////////////////////////////////////////////
311 cv::divide(in_mat1, in_mat2, out_mat_ocv, dtype);
313 // G-API code ////////////////////////////////////////////////////////////
314 cv::GMat in1, in2, out;
315 out = cv::gapi::div(in1, in2, dtype);
316 cv::GComputation c(GIn(in1, in2), GOut(out));
318 // Warm-up graph engine:
319 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
323 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
326 // Comparison ////////////////////////////////////////////////////////////
327 // FIXIT unrealiable check: EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
328 EXPECT_EQ(out_mat_gapi.size(), sz);
330 SANITY_CHECK_NOTHING();
333 //------------------------------------------------------------------------------
335 PERF_TEST_P_(DivCPerfTest, TestPerformance)
337 Size sz = get<0>(GetParam());
338 MatType type = get<1>(GetParam());
339 int dtype = get<2>(GetParam());
340 cv::GCompileArgs compile_args = get<3>(GetParam());
342 // FIXIT Unstable input data for divide
343 initMatsRandU(type, sz, dtype, false);
345 // OpenCV code ///////////////////////////////////////////////////////////
346 cv::divide(in_mat1, sc, out_mat_ocv, 1.0, dtype);
348 // G-API code ////////////////////////////////////////////////////////////
351 out = cv::gapi::divC(in1, sc1, 1.0, dtype);
352 cv::GComputation c(GIn(in1, sc1), GOut(out));
354 // Warm-up graph engine:
355 c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
359 c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
362 // Comparison ////////////////////////////////////////////////////////////
363 // FIXIT unrealiable check: EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
364 EXPECT_EQ(out_mat_gapi.size(), sz);
366 SANITY_CHECK_NOTHING();
369 //------------------------------------------------------------------------------
371 PERF_TEST_P_(DivRCPerfTest, TestPerformance)
373 compare_f cmpF = get<0>(GetParam());
374 Size sz = get<1>(GetParam());
375 MatType type = get<2>(GetParam());
376 int dtype = get<3>(GetParam());
377 cv::GCompileArgs compile_args = get<4>(GetParam());
379 // FIXIT Unstable input data for divide
380 initMatsRandU(type, sz, dtype, false);
382 // FIXIT Unstable input data for divide, don't process zeros
383 sc += Scalar::all(1);
386 // OpenCV code ///////////////////////////////////////////////////////////
387 cv::divide(sc, in_mat1, out_mat_ocv, 1.0, dtype);
389 // G-API code ////////////////////////////////////////////////////////////
392 out = cv::gapi::divRC(sc1, in1, 1.0, dtype);
393 cv::GComputation c(GIn(in1, sc1), GOut(out));
395 // Warm-up graph engine:
396 c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
400 c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
403 // Comparison ////////////////////////////////////////////////////////////
404 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
405 EXPECT_EQ(out_mat_gapi.size(), sz);
407 SANITY_CHECK_NOTHING();
410 //------------------------------------------------------------------------------
412 PERF_TEST_P_(MaskPerfTest, TestPerformance)
414 Size sz_in = get<0>(GetParam());
415 MatType type = get<1>(GetParam());
416 cv::GCompileArgs compile_args = get<2>(GetParam());
418 initMatrixRandU(type, sz_in, type, false);
419 in_mat2 = cv::Mat(sz_in, CV_8UC1);
420 cv::randu(in_mat2, cv::Scalar::all(0), cv::Scalar::all(255));
421 in_mat2 = in_mat2 > 128;
423 // OpenCV code ///////////////////////////////////////////////////////////
424 out_mat_ocv = cv::Mat::zeros(in_mat1.size(), in_mat1.type());
425 in_mat1.copyTo(out_mat_ocv, in_mat2);
427 // G-API code ////////////////////////////////////////////////////////////
429 auto out = cv::gapi::mask(in, m);
430 cv::GComputation c(cv::GIn(in, m), cv::GOut(out));
432 // Warm-up graph engine:
433 c.apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat_gapi), std::move(compile_args));
437 c.apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat_gapi), std::move(compile_args));
440 // Comparison ////////////////////////////////////////////////////////////
441 EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
443 SANITY_CHECK_NOTHING();
446 //------------------------------------------------------------------------------
448 PERF_TEST_P_(MeanPerfTest, TestPerformance)
450 Size sz_in = get<0>(GetParam());
451 MatType type = get<1>(GetParam());
452 cv::GCompileArgs compile_args = get<2>(GetParam());
454 initMatrixRandU(type, sz_in, false);
456 cv::Scalar out_norm_ocv;
458 // OpenCV code ///////////////////////////////////////////////////////////
459 out_norm_ocv = cv::mean(in_mat1);
461 // G-API code ////////////////////////////////////////////////////////////
463 auto out = cv::gapi::mean(in);
464 cv::GComputation c(cv::GIn(in), cv::GOut(out));
466 // Warm-up graph engine:
467 c.apply(cv::gin(in_mat1), cv::gout(out_norm), std::move(compile_args));
471 c.apply(cv::gin(in_mat1), cv::gout(out_norm), std::move(compile_args));
474 // Comparison ////////////////////////////////////////////////////////////
475 // FIXIT unrealiable check: EXPECT_EQ(out_norm[0], out_norm_ocv[0]);
477 SANITY_CHECK_NOTHING();
480 //------------------------------------------------------------------------------
482 PERF_TEST_P_(Polar2CartPerfTest, TestPerformance)
484 compare_f cmpF = get<0>(GetParam());
485 Size sz_in = get<1>(GetParam());
486 cv::GCompileArgs compile_args = get<2>(GetParam());
488 initMatsRandU(CV_32FC1, sz_in, CV_32FC1, false);
490 cv::Mat out_mat_ocv2;
492 // OpenCV code ///////////////////////////////////////////////////////////
493 cv::polarToCart(in_mat1, in_mat2, out_mat_ocv, out_mat_ocv2);
495 // G-API code ////////////////////////////////////////////////////////////
496 cv::GMat in1, in2, out1, out2;
497 std::tie(out1, out2) = cv::gapi::polarToCart(in1, in2);
498 cv::GComputation c(GIn(in1, in2), GOut(out1, out2));
500 // Warm-up graph engine:
501 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi, out_mat2), std::move(compile_args));
505 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi, out_mat2), std::move(compile_args));
507 // Comparison ////////////////////////////////////////////////////////////
508 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
509 EXPECT_TRUE(cmpF(out_mat_ocv2, out_mat2));
510 EXPECT_EQ(out_mat_gapi.size(), sz_in);
512 SANITY_CHECK_NOTHING();
515 //------------------------------------------------------------------------------
517 PERF_TEST_P_(Cart2PolarPerfTest, TestPerformance)
519 compare_f cmpF = get<0>(GetParam());
520 Size sz_in = get<1>(GetParam());
521 cv::GCompileArgs compile_args = get<2>(GetParam());
523 initMatsRandU(CV_32FC1, sz_in, CV_32FC1, false);
524 cv::Mat out_mat2(sz_in, CV_32FC1);
525 cv::Mat out_mat_ocv2(sz_in, CV_32FC1);
527 // OpenCV code ///////////////////////////////////////////////////////////
528 cv::cartToPolar(in_mat1, in_mat2, out_mat_ocv, out_mat_ocv2);
530 // G-API code ////////////////////////////////////////////////////////////
531 cv::GMat in1, in2, out1, out2;
532 std::tie(out1, out2) = cv::gapi::cartToPolar(in1, in2);
533 cv::GComputation c(GIn(in1, in2), GOut(out1, out2));
535 // Warm-up graph engine:
536 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi, out_mat2), std::move(compile_args));
540 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi, out_mat2), std::move(compile_args));
543 // Comparison ////////////////////////////////////////////////////////////
544 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
545 EXPECT_TRUE(cmpF(out_mat_ocv2, out_mat2));
546 EXPECT_EQ(out_mat_gapi.size(), sz_in);
548 SANITY_CHECK_NOTHING();
551 //------------------------------------------------------------------------------
553 PERF_TEST_P_(CmpPerfTest, TestPerformance)
555 CmpTypes opType = get<0>(GetParam());
556 cv::Size sz = get<1>(GetParam());
557 MatType type = get<2>(GetParam());
558 cv::GCompileArgs compile_args = get<3>(GetParam());
560 initMatsRandU(type, sz, CV_8U, false);
562 // OpenCV code ///////////////////////////////////////////////////////////
563 cv::compare(in_mat1, in_mat2, out_mat_ocv, opType);
565 // G-API code ////////////////////////////////////////////////////////////
566 cv::GMat in1, in2, out;
569 case CMP_EQ: out = cv::gapi::cmpEQ(in1, in2); break;
570 case CMP_GT: out = cv::gapi::cmpGT(in1, in2); break;
571 case CMP_GE: out = cv::gapi::cmpGE(in1, in2); break;
572 case CMP_LT: out = cv::gapi::cmpLT(in1, in2); break;
573 case CMP_LE: out = cv::gapi::cmpLE(in1, in2); break;
574 case CMP_NE: out = cv::gapi::cmpNE(in1, in2); break;
575 default: FAIL() << "no such compare operation type for two matrices!";
577 cv::GComputation c(GIn(in1, in2), GOut(out));
579 // Warm-up graph engine:
580 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
584 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
587 // Comparison ////////////////////////////////////////////////////////////
588 EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
589 EXPECT_EQ(out_mat_gapi.size(), sz);
591 SANITY_CHECK_NOTHING();
594 //------------------------------------------------------------------------------
596 PERF_TEST_P_(CmpWithScalarPerfTest, TestPerformance)
598 CmpTypes opType = get<0>(GetParam());
599 cv::Size sz = get<1>(GetParam());
600 MatType type = get<2>(GetParam());
601 cv::GCompileArgs compile_args = get<3>(GetParam());
603 initMatsRandU(type, sz, CV_8U, false);
605 // OpenCV code ///////////////////////////////////////////////////////////
606 cv::compare(in_mat1, sc, out_mat_ocv, opType);
608 // G-API code ////////////////////////////////////////////////////////////
613 case CMP_EQ: out = cv::gapi::cmpEQ(in1, in2); break;
614 case CMP_GT: out = cv::gapi::cmpGT(in1, in2); break;
615 case CMP_GE: out = cv::gapi::cmpGE(in1, in2); break;
616 case CMP_LT: out = cv::gapi::cmpLT(in1, in2); break;
617 case CMP_LE: out = cv::gapi::cmpLE(in1, in2); break;
618 case CMP_NE: out = cv::gapi::cmpNE(in1, in2); break;
619 default: FAIL() << "no such compare operation type for matrix and scalar!";
621 cv::GComputation c(GIn(in1, in2), GOut(out));
623 // Warm-up graph engine:
624 c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
628 c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
631 // Comparison ////////////////////////////////////////////////////////////
632 EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
633 EXPECT_EQ(out_mat_gapi.size(), sz);
635 SANITY_CHECK_NOTHING();
638 //------------------------------------------------------------------------------
640 PERF_TEST_P_(BitwisePerfTest, TestPerformance)
642 bitwiseOp opType = get<0>(GetParam());
643 cv::Size sz = get<1>(GetParam());
644 MatType type = get<2>(GetParam());
645 cv::GCompileArgs compile_args = get<3>(GetParam());
647 initMatsRandU(type, sz, type, false);
649 // G-API code & corresponding OpenCV code ////////////////////////////////
650 cv::GMat in1, in2, out;
655 out = cv::gapi::bitwise_and(in1, in2);
656 cv::bitwise_and(in_mat1, in_mat2, out_mat_ocv);
661 out = cv::gapi::bitwise_or(in1, in2);
662 cv::bitwise_or(in_mat1, in_mat2, out_mat_ocv);
667 out = cv::gapi::bitwise_xor(in1, in2);
668 cv::bitwise_xor(in_mat1, in_mat2, out_mat_ocv);
673 FAIL() << "no such bitwise operation type!";
676 cv::GComputation c(GIn(in1, in2), GOut(out));
678 // Warm-up graph engine:
679 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
683 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
686 // Comparison ////////////////////////////////////////////////////////////
687 EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
688 EXPECT_EQ(out_mat_gapi.size(), sz);
690 SANITY_CHECK_NOTHING();
693 //------------------------------------------------------------------------------
695 PERF_TEST_P_(BitwiseNotPerfTest, TestPerformance)
697 cv::Size sz_in = get<0>(GetParam());
698 MatType type = get<1>(GetParam());
699 cv::GCompileArgs compile_args = get<2>(GetParam());
701 initMatrixRandU(type, sz_in, type, false);
703 // OpenCV code ///////////////////////////////////////////////////////////
704 cv::bitwise_not(in_mat1, out_mat_ocv);
706 // G-API code ////////////////////////////////////////////////////////////
708 out = cv::gapi::bitwise_not(in);
709 cv::GComputation c(in, out);
711 // Warm-up graph engine:
712 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
716 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
719 // Comparison ////////////////////////////////////////////////////////////
720 EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
721 EXPECT_EQ(out_mat_gapi.size(), sz_in);
723 SANITY_CHECK_NOTHING();
726 //------------------------------------------------------------------------------
728 PERF_TEST_P_(SelectPerfTest, TestPerformance)
730 cv::Size sz_in = get<0>(GetParam());
731 MatType type = get<1>(GetParam());
732 cv::GCompileArgs compile_args = get<2>(GetParam());
734 initMatsRandU(type, sz_in, type, false);
735 cv::Mat in_mask(sz_in, CV_8UC1);
736 cv::randu(in_mask, cv::Scalar::all(0), cv::Scalar::all(255));
738 // OpenCV code ///////////////////////////////////////////////////////////
739 in_mat2.copyTo(out_mat_ocv);
740 in_mat1.copyTo(out_mat_ocv, in_mask);
742 // G-API code ////////////////////////////////////////////////////////////
743 cv::GMat in1, in2, in3, out;
744 out = cv::gapi::select(in1, in2, in3);
745 cv::GComputation c(GIn(in1, in2, in3), GOut(out));
747 // Warm-up graph engine:
748 c.apply(gin(in_mat1, in_mat2, in_mask), gout(out_mat_gapi), std::move(compile_args));
752 c.apply(gin(in_mat1, in_mat2, in_mask), gout(out_mat_gapi), std::move(compile_args));
755 // Comparison ////////////////////////////////////////////////////////////
756 EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
757 EXPECT_EQ(out_mat_gapi.size(), sz_in);
759 SANITY_CHECK_NOTHING();
762 //------------------------------------------------------------------------------
764 PERF_TEST_P_(MinPerfTest, TestPerformance)
766 cv::Size sz_in = get<0>(GetParam());
767 MatType type = get<1>(GetParam());
768 cv::GCompileArgs compile_args = get<2>(GetParam());
771 initMatsRandU(type, sz_in, type, false);
773 // OpenCV code ///////////////////////////////////////////////////////////
774 cv::min(in_mat1, in_mat2, out_mat_ocv);
776 // G-API code ////////////////////////////////////////////////////////////
777 cv::GMat in1, in2, out;
778 out = cv::gapi::min(in1, in2);
779 cv::GComputation c(GIn(in1, in2), GOut(out));
781 // Warm-up graph engine:
782 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
786 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
789 // Comparison ////////////////////////////////////////////////////////////
790 EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
791 EXPECT_EQ(out_mat_gapi.size(), sz_in);
793 SANITY_CHECK_NOTHING();
796 //------------------------------------------------------------------------------
798 PERF_TEST_P_(MaxPerfTest, TestPerformance)
800 cv::Size sz_in = get<0>(GetParam());
801 MatType type = get<1>(GetParam());
802 cv::GCompileArgs compile_args = get<2>(GetParam());
805 initMatsRandU(type, sz_in, type, false);
807 // OpenCV code ///////////////////////////////////////////////////////////
808 cv::max(in_mat1, in_mat2, out_mat_ocv);
810 // G-API code ////////////////////////////////////////////////////////////
811 cv::GMat in1, in2, out;
812 out = cv::gapi::max(in1, in2);
813 cv::GComputation c(GIn(in1, in2), GOut(out));
815 // Warm-up graph engine:
816 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
820 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
823 // Comparison ////////////////////////////////////////////////////////////
824 EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
825 EXPECT_EQ(out_mat_gapi.size(), sz_in);
827 SANITY_CHECK_NOTHING();
830 //------------------------------------------------------------------------------
832 PERF_TEST_P_(AbsDiffPerfTest, TestPerformance)
834 cv::Size sz_in = get<0>(GetParam());
835 MatType type = get<1>(GetParam());
836 cv::GCompileArgs compile_args = get<2>(GetParam());
839 initMatsRandU(type, sz_in, type, false);
841 // OpenCV code ///////////////////////////////////////////////////////////
842 cv::absdiff(in_mat1, in_mat2, out_mat_ocv);
844 // G-API code ////////////////////////////////////////////////////////////
845 cv::GMat in1, in2, out;
846 out = cv::gapi::absDiff(in1, in2);
847 cv::GComputation c(GIn(in1, in2), GOut(out));
849 // Warm-up graph engine:
850 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
854 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
857 // Comparison ////////////////////////////////////////////////////////////
858 // FIXIT unrealiable check: EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
859 EXPECT_EQ(out_mat_gapi.size(), sz_in);
861 SANITY_CHECK_NOTHING();
864 //------------------------------------------------------------------------------
866 PERF_TEST_P_(AbsDiffCPerfTest, TestPerformance)
868 cv::Size sz_in = get<0>(GetParam());
869 MatType type = get<1>(GetParam());
870 cv::GCompileArgs compile_args = get<2>(GetParam());
873 initMatsRandU(type, sz_in, type, false);
875 // OpenCV code ///////////////////////////////////////////////////////////
876 cv::absdiff(in_mat1, sc, out_mat_ocv);
878 // G-API code ////////////////////////////////////////////////////////////
881 out = cv::gapi::absDiffC(in1, sc1);
882 cv::GComputation c(cv::GIn(in1, sc1), cv::GOut(out));
884 // Warm-up graph engine:
885 c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
889 c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
892 // Comparison ////////////////////////////////////////////////////////////
893 // FIXIT unrealiable check: EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
894 EXPECT_EQ(out_mat_gapi.size(), sz_in);
896 SANITY_CHECK_NOTHING();
899 //------------------------------------------------------------------------------
901 PERF_TEST_P_(SumPerfTest, TestPerformance)
903 compare_scalar_f cmpF = get<0>(GetParam());
904 cv::Size sz_in = get<1>(GetParam());
905 MatType type = get<2>(GetParam());
906 cv::GCompileArgs compile_args = get<3>(GetParam());
909 initMatrixRandU(type, sz_in, type, false);
911 cv::Scalar out_sum_ocv;
913 // OpenCV code ///////////////////////////////////////////////////////////
914 out_sum_ocv = cv::sum(in_mat1);
916 // G-API code ////////////////////////////////////////////////////////////
918 auto out = cv::gapi::sum(in);
919 cv::GComputation c(cv::GIn(in), cv::GOut(out));
921 // Warm-up graph engine:
922 c.apply(cv::gin(in_mat1), cv::gout(out_sum), std::move(compile_args));
926 c.apply(cv::gin(in_mat1), cv::gout(out_sum), std::move(compile_args));
929 // Comparison ////////////////////////////////////////////////////////////
931 EXPECT_TRUE(cmpF(out_sum, out_sum_ocv));
934 SANITY_CHECK_NOTHING();
937 //------------------------------------------------------------------------------
939 PERF_TEST_P_(AddWeightedPerfTest, TestPerformance)
941 compare_f cmpF = get<0>(GetParam());
942 cv::Size sz_in = get<1>(GetParam());
943 MatType type = get<2>(GetParam());
944 int dtype = get<3>(GetParam());
945 cv::GCompileArgs compile_args = get<4>(GetParam());
947 auto& rng = cv::theRNG();
948 double alpha = rng.uniform(0.0, 1.0);
949 double beta = rng.uniform(0.0, 1.0);
950 double gamma = rng.uniform(0.0, 1.0);
951 initMatsRandU(type, sz_in, dtype, false);
953 // OpenCV code ///////////////////////////////////////////////////////////
954 cv::addWeighted(in_mat1, alpha, in_mat2, beta, gamma, out_mat_ocv, dtype);
956 // G-API code ////////////////////////////////////////////////////////////
958 auto out = cv::gapi::addWeighted(in1, alpha, in2, beta, gamma, dtype);
959 cv::GComputation c(GIn(in1, in2), GOut(out));
961 // Warm-up graph engine:
962 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
966 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
969 // Comparison ////////////////////////////////////////////////////////////
970 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
971 EXPECT_EQ(out_mat_gapi.size(), sz_in);
974 SANITY_CHECK_NOTHING();
977 //------------------------------------------------------------------------------
979 PERF_TEST_P_(NormPerfTest, TestPerformance)
981 compare_scalar_f cmpF = get<0>(GetParam());
982 NormTypes opType = get<1>(GetParam());
983 cv::Size sz = get<2>(GetParam());
984 MatType type = get<3>(GetParam());
985 cv::GCompileArgs compile_args = get<4>(GetParam());
988 initMatrixRandU(type, sz, type, false);
990 cv::Scalar out_norm_ocv;
992 // OpenCV code ///////////////////////////////////////////////////////////
993 out_norm_ocv = cv::norm(in_mat1, opType);
995 // G-API code ////////////////////////////////////////////////////////////
1000 case NORM_L1: out = cv::gapi::normL1(in1); break;
1001 case NORM_L2: out = cv::gapi::normL2(in1); break;
1002 case NORM_INF: out = cv::gapi::normInf(in1); break;
1003 default: FAIL() << "no such norm operation type!";
1005 cv::GComputation c(GIn(in1), GOut(out));
1007 // Warm-up graph engine:
1008 c.apply(gin(in_mat1), gout(out_norm), std::move(compile_args));
1012 c.apply(gin(in_mat1), gout(out_norm), std::move(compile_args));
1015 // Comparison ////////////////////////////////////////////////////////////
1017 EXPECT_TRUE(cmpF(out_norm, out_norm_ocv));
1020 SANITY_CHECK_NOTHING();
1023 //------------------------------------------------------------------------------
1025 PERF_TEST_P_(IntegralPerfTest, TestPerformance)
1027 cv::Size sz_in = get<0>(GetParam());
1028 MatType type = get<1>(GetParam());
1029 cv::GCompileArgs compile_args = get<2>(GetParam());
1032 MatType type_out = (type == CV_8U) ? CV_32SC1 : CV_64FC1;
1035 in_mat1 = cv::Mat(sz_in, type);
1036 cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255));
1038 cv::Size sz_out = cv::Size(sz_in.width + 1, sz_in.height + 1);
1039 cv::Mat out_mat1(sz_out, type_out);
1040 cv::Mat out_mat_ocv1(sz_out, type_out);
1042 cv::Mat out_mat2(sz_out, CV_64FC1);
1043 cv::Mat out_mat_ocv2(sz_out, CV_64FC1);
1045 // OpenCV code ///////////////////////////////////////////////////////////
1046 cv::integral(in_mat1, out_mat_ocv1, out_mat_ocv2);
1048 // G-API code ////////////////////////////////////////////////////////////
1049 cv::GMat in1, out1, out2;
1050 std::tie(out1, out2) = cv::gapi::integral(in1, type_out, CV_64FC1);
1051 cv::GComputation c(cv::GIn(in1), cv::GOut(out1, out2));
1053 // Warm-up graph engine:
1054 c.apply(cv::gin(in_mat1), cv::gout(out_mat1, out_mat2), std::move(compile_args));
1058 c.apply(cv::gin(in_mat1), cv::gout(out_mat1, out_mat2), std::move(compile_args));
1061 // Comparison ////////////////////////////////////////////////////////////
1062 // FIXIT unrealiable check: EXPECT_EQ(0, cv::countNonZero(out_mat_ocv1 != out_mat1));
1063 // FIXIT unrealiable check: EXPECT_EQ(0, cv::countNonZero(out_mat_ocv2 != out_mat2));
1065 SANITY_CHECK_NOTHING();
1068 //------------------------------------------------------------------------------
1070 PERF_TEST_P_(ThresholdPerfTest, TestPerformance)
1072 cv::Size sz_in = get<0>(GetParam());
1073 MatType type = get<1>(GetParam());
1074 int tt = get<2>(GetParam());
1075 cv::GCompileArgs compile_args = get<3>(GetParam());
1077 cv::Scalar thr = initScalarRandU(50);
1078 cv::Scalar maxval = initScalarRandU(50) + cv::Scalar(50, 50, 50, 50);
1079 initMatrixRandU(type, sz_in, type, false);
1080 cv::Scalar out_scalar;
1082 // OpenCV code ///////////////////////////////////////////////////////////
1083 cv::threshold(in_mat1, out_mat_ocv, thr.val[0], maxval.val[0], tt);
1085 // G-API code ////////////////////////////////////////////////////////////
1087 cv::GScalar th1, mv1;
1088 out = cv::gapi::threshold(in1, th1, mv1, tt);
1089 cv::GComputation c(GIn(in1, th1, mv1), GOut(out));
1091 // Warm-up graph engine:
1092 c.apply(gin(in_mat1, thr, maxval), gout(out_mat_gapi), std::move(compile_args));
1096 c.apply(gin(in_mat1, thr, maxval), gout(out_mat_gapi), std::move(compile_args));
1099 // Comparison ////////////////////////////////////////////////////////////
1100 EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
1101 EXPECT_EQ(out_mat_gapi.size(), sz_in);
1103 SANITY_CHECK_NOTHING();
1106 //------------------------------------------------------------------------------
1108 PERF_TEST_P_(ThresholdOTPerfTest, TestPerformance)
1110 cv::Size sz_in = get<0>(GetParam());
1111 MatType type = get<1>(GetParam());
1112 int tt = get<2>(GetParam());
1113 cv::GCompileArgs compile_args = get<3>(GetParam());
1115 cv::Scalar maxval = initScalarRandU(50) + cv::Scalar(50, 50, 50, 50);
1116 initMatrixRandU(type, sz_in, type, false);
1117 cv::Scalar out_gapi_scalar;
1120 // OpenCV code ///////////////////////////////////////////////////////////
1121 ocv_res = cv::threshold(in_mat1, out_mat_ocv, maxval.val[0], maxval.val[0], tt);
1123 // G-API code ////////////////////////////////////////////////////////////
1125 cv::GScalar mv1, scout;
1126 std::tie<cv::GMat, cv::GScalar>(out, scout) = cv::gapi::threshold(in1, mv1, tt);
1127 cv::GComputation c(cv::GIn(in1, mv1), cv::GOut(out, scout));
1129 // Warm-up graph engine:
1130 c.apply(gin(in_mat1, maxval), gout(out_mat_gapi, out_gapi_scalar), std::move(compile_args));
1134 c.apply(gin(in_mat1, maxval), gout(out_mat_gapi, out_gapi_scalar), std::move(compile_args));
1137 // Comparison ////////////////////////////////////////////////////////////
1138 // FIXIT unrealiable check: EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi));
1139 EXPECT_EQ(out_mat_gapi.size(), sz_in);
1140 EXPECT_EQ(ocv_res, out_gapi_scalar.val[0]);
1142 SANITY_CHECK_NOTHING();
1145 //------------------------------------------------------------------------------
1147 PERF_TEST_P_(InRangePerfTest, TestPerformance)
1149 cv::Size sz_in = get<0>(GetParam());
1150 MatType type = get<1>(GetParam());
1151 cv::GCompileArgs compile_args = get<2>(GetParam());
1153 cv::Scalar thrLow = initScalarRandU(100);
1154 cv::Scalar thrUp = initScalarRandU(100) + cv::Scalar(100, 100, 100, 100);
1155 initMatrixRandU(type, sz_in, type, false);
1157 // OpenCV code ///////////////////////////////////////////////////////////
1158 cv::inRange(in_mat1, thrLow, thrUp, out_mat_ocv);
1160 // G-API code ////////////////////////////////////////////////////////////
1162 cv::GScalar th1, mv1;
1163 auto out = cv::gapi::inRange(in1, th1, mv1);
1164 cv::GComputation c(GIn(in1, th1, mv1), GOut(out));
1166 // Warm-up graph engine:
1167 c.apply(gin(in_mat1, thrLow, thrUp), gout(out_mat_gapi), std::move(compile_args));
1171 c.apply(gin(in_mat1, thrLow, thrUp), gout(out_mat_gapi), std::move(compile_args));
1174 // Comparison ////////////////////////////////////////////////////////////
1175 EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
1176 EXPECT_EQ(out_mat_gapi.size(), sz_in);
1178 SANITY_CHECK_NOTHING();
1181 //------------------------------------------------------------------------------
1183 PERF_TEST_P_(Split3PerfTest, TestPerformance)
1185 Size sz_in = get<0>(GetParam());
1186 cv::GCompileArgs compile_args = get<1>(GetParam());
1189 initMatrixRandU(CV_8UC3, sz_in, CV_8UC1);
1190 cv::Mat out_mat2 = cv::Mat(sz_in, CV_8UC1);
1191 cv::Mat out_mat3 = cv::Mat(sz_in, CV_8UC1);
1192 cv::Mat out_mat_ocv2 = cv::Mat(sz_in, CV_8UC1);
1193 cv::Mat out_mat_ocv3 = cv::Mat(sz_in, CV_8UC1);
1195 // OpenCV code ///////////////////////////////////////////////////////////
1196 std::vector<cv::Mat> out_mats_ocv = { out_mat_ocv, out_mat_ocv2, out_mat_ocv3 };
1197 cv::split(in_mat1, out_mats_ocv);
1199 // G-API code ////////////////////////////////////////////////////////////
1200 cv::GMat in1, out1, out2, out3;
1201 std::tie(out1, out2, out3) = cv::gapi::split3(in1);
1202 cv::GComputation c(cv::GIn(in1), cv::GOut(out1, out2, out3));
1204 // Warm-up graph engine:
1205 c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat2, out_mat3), std::move(compile_args));
1209 c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat2, out_mat3), std::move(compile_args));
1212 // Comparison ////////////////////////////////////////////////////////////
1213 EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
1214 EXPECT_EQ(0, cv::norm(out_mat_ocv2, out_mat2, NORM_INF));
1215 EXPECT_EQ(0, cv::norm(out_mat_ocv3, out_mat3, NORM_INF));
1217 SANITY_CHECK_NOTHING();
1220 //------------------------------------------------------------------------------
1222 PERF_TEST_P_(Split4PerfTest, TestPerformance)
1224 Size sz_in = get<0>(GetParam());
1225 cv::GCompileArgs compile_args = get<1>(GetParam());
1227 initMatrixRandU(CV_8UC4, sz_in, CV_8UC1);
1228 cv::Mat out_mat2 = cv::Mat(sz_in, CV_8UC1);
1229 cv::Mat out_mat3 = cv::Mat(sz_in, CV_8UC1);
1230 cv::Mat out_mat4 = cv::Mat(sz_in, CV_8UC1);
1231 cv::Mat out_mat_ocv2 = cv::Mat(sz_in, CV_8UC1);
1232 cv::Mat out_mat_ocv3 = cv::Mat(sz_in, CV_8UC1);
1233 cv::Mat out_mat_ocv4 = cv::Mat(sz_in, CV_8UC1);
1235 // OpenCV code ///////////////////////////////////////////////////////////
1236 std::vector<cv::Mat> out_mats_ocv = { out_mat_ocv, out_mat_ocv2, out_mat_ocv3, out_mat_ocv4 };
1237 cv::split(in_mat1, out_mats_ocv);
1239 // G-API code ////////////////////////////////////////////////////////////
1240 cv::GMat in1, out1, out2, out3, out4;
1241 std::tie(out1, out2, out3, out4) = cv::gapi::split4(in1);
1242 cv::GComputation c(cv::GIn(in1), cv::GOut(out1, out2, out3, out4));
1244 // Warm-up graph engine:
1245 c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat2, out_mat3, out_mat4), std::move(compile_args));
1249 c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat2, out_mat3, out_mat4), std::move(compile_args));
1252 // Comparison ////////////////////////////////////////////////////////////
1253 EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
1254 EXPECT_EQ(0, cv::norm(out_mat_ocv2, out_mat2, NORM_INF));
1255 EXPECT_EQ(0, cv::norm(out_mat_ocv3, out_mat3, NORM_INF));
1256 EXPECT_EQ(0, cv::norm(out_mat_ocv4, out_mat4, NORM_INF));
1258 SANITY_CHECK_NOTHING();
1261 //------------------------------------------------------------------------------
1263 PERF_TEST_P_(Merge3PerfTest, TestPerformance)
1265 Size sz_in = get<0>(GetParam());
1266 cv::GCompileArgs compile_args = get<1>(GetParam());
1268 initMatsRandU(CV_8UC1, sz_in, CV_8UC3);
1269 cv::Mat in_mat3(sz_in, CV_8UC1);
1270 cv::Scalar mean = cv::Scalar::all(127);
1271 cv::Scalar stddev = cv::Scalar::all(40.f);
1272 cv::randn(in_mat3, mean, stddev);
1274 // OpenCV code ///////////////////////////////////////////////////////////
1275 std::vector<cv::Mat> in_mats_ocv = { in_mat1, in_mat2, in_mat3 };
1276 cv::merge(in_mats_ocv, out_mat_ocv);
1278 // G-API code ////////////////////////////////////////////////////////////
1279 cv::GMat in1, in2, in3;
1280 auto out = cv::gapi::merge3(in1, in2, in3);
1281 cv::GComputation c(cv::GIn(in1, in2, in3), cv::GOut(out));
1283 // Warm-up graph engine:
1284 c.apply(cv::gin(in_mat1, in_mat2, in_mat3), cv::gout(out_mat_gapi), std::move(compile_args));
1288 c.apply(cv::gin(in_mat1, in_mat2, in_mat3), cv::gout(out_mat_gapi), std::move(compile_args));
1291 // Comparison ////////////////////////////////////////////////////////////
1292 EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
1294 SANITY_CHECK_NOTHING();
1297 //------------------------------------------------------------------------------
1299 PERF_TEST_P_(Merge4PerfTest, TestPerformance)
1301 Size sz_in = get<0>(GetParam());
1302 cv::GCompileArgs compile_args = get<1>(GetParam());
1304 initMatsRandU(CV_8UC1, sz_in, CV_8UC3);
1305 cv::Mat in_mat3(sz_in, CV_8UC1);
1306 cv::Mat in_mat4(sz_in, CV_8UC1);
1307 cv::Scalar mean = cv::Scalar::all(127);
1308 cv::Scalar stddev = cv::Scalar::all(40.f);
1309 cv::randn(in_mat3, mean, stddev);
1310 cv::randn(in_mat4, mean, stddev);
1312 // OpenCV code ///////////////////////////////////////////////////////////
1313 std::vector<cv::Mat> in_mats_ocv = { in_mat1, in_mat2, in_mat3, in_mat4 };
1314 cv::merge(in_mats_ocv, out_mat_ocv);
1316 // G-API code ////////////////////////////////////////////////////////////
1317 cv::GMat in1, in2, in3, in4;
1318 auto out = cv::gapi::merge4(in1, in2, in3, in4);
1319 cv::GComputation c(cv::GIn(in1, in2, in3, in4), cv::GOut(out));
1321 // Warm-up graph engine:
1322 c.apply(cv::gin(in_mat1, in_mat2, in_mat3, in_mat4), cv::gout(out_mat_gapi), std::move(compile_args));
1326 c.apply(cv::gin(in_mat1, in_mat2, in_mat3, in_mat4), cv::gout(out_mat_gapi), std::move(compile_args));
1329 // Comparison ////////////////////////////////////////////////////////////
1330 EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
1332 SANITY_CHECK_NOTHING();
1335 //------------------------------------------------------------------------------
1337 PERF_TEST_P_(RemapPerfTest, TestPerformance)
1339 cv::Size sz_in = get<0>(GetParam());
1340 MatType type = get<1>(GetParam());
1341 cv::GCompileArgs compile_args = get<2>(GetParam());
1343 initMatrixRandU(type, sz_in, type, false);
1344 cv::Mat in_map1(sz_in, CV_16SC2);
1345 cv::Mat in_map2 = cv::Mat();
1346 cv::randu(in_map1, cv::Scalar::all(0), cv::Scalar::all(255));
1347 cv::Scalar bv = cv::Scalar();
1349 // OpenCV code ///////////////////////////////////////////////////////////
1350 cv::remap(in_mat1, out_mat_ocv, in_map1, in_map2, cv::INTER_NEAREST, cv::BORDER_REPLICATE, bv);
1352 // G-API code ////////////////////////////////////////////////////////////
1354 auto out = cv::gapi::remap(in1, in_map1, in_map2, cv::INTER_NEAREST, cv::BORDER_REPLICATE, bv);
1355 cv::GComputation c(in1, out);
1357 // Warm-up graph engine:
1358 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1362 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1365 // Comparison ////////////////////////////////////////////////////////////
1366 // FIXIT unrealiable check: EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi));
1367 EXPECT_EQ(out_mat_gapi.size(), sz_in);
1369 SANITY_CHECK_NOTHING();
1372 //------------------------------------------------------------------------------
1374 PERF_TEST_P_(FlipPerfTest, TestPerformance)
1376 cv::Size sz_in = get<0>(GetParam());
1377 MatType type = get<1>(GetParam());
1378 int flipCode = get<2>(GetParam());
1379 cv::GCompileArgs compile_args = get<3>(GetParam());
1381 initMatrixRandU(type, sz_in, type, false);
1383 // OpenCV code ///////////////////////////////////////////////////////////
1384 cv::flip(in_mat1, out_mat_ocv, flipCode);
1386 // G-API code ////////////////////////////////////////////////////////////
1388 auto out = cv::gapi::flip(in, flipCode);
1389 cv::GComputation c(in, out);
1391 // Warm-up graph engine:
1392 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1396 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1399 // Comparison ////////////////////////////////////////////////////////////
1400 EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
1401 EXPECT_EQ(out_mat_gapi.size(), sz_in);
1403 SANITY_CHECK_NOTHING();
1406 //------------------------------------------------------------------------------
1408 PERF_TEST_P_(CropPerfTest, TestPerformance)
1410 cv::Size sz_in = get<0>(GetParam());
1411 MatType type = get<1>(GetParam());
1412 cv::Rect rect_to = get<2>(GetParam());
1413 cv::GCompileArgs compile_args = get<3>(GetParam());
1415 initMatrixRandU(type, sz_in, type, false);
1416 cv::Size sz_out = cv::Size(rect_to.width, rect_to.height);
1418 // OpenCV code ///////////////////////////////////////////////////////////
1419 cv::Mat(in_mat1, rect_to).copyTo(out_mat_ocv);
1421 // G-API code ////////////////////////////////////////////////////////////
1423 auto out = cv::gapi::crop(in, rect_to);
1424 cv::GComputation c(in, out);
1426 // Warm-up graph engine:
1427 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1431 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1434 // Comparison ////////////////////////////////////////////////////////////
1435 EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
1436 EXPECT_EQ(out_mat_gapi.size(), sz_out);
1438 SANITY_CHECK_NOTHING();
1441 //------------------------------------------------------------------------------
1443 PERF_TEST_P_(ConcatHorPerfTest, TestPerformance)
1445 cv::Size sz_out = get<0>(GetParam());
1446 MatType type = get<1>(GetParam());
1447 cv::GCompileArgs compile_args = get<2>(GetParam());
1449 int wpart = sz_out.width / 4;
1451 cv::Size sz_in1 = cv::Size(wpart, sz_out.height);
1452 cv::Size sz_in2 = cv::Size(sz_out.width - wpart, sz_out.height);
1454 in_mat1 = cv::Mat(sz_in1, type);
1455 in_mat2 = cv::Mat(sz_in2, type);
1457 cv::Scalar mean = cv::Scalar::all(127);
1458 cv::Scalar stddev = cv::Scalar::all(40.f);
1460 cv::randn(in_mat1, mean, stddev);
1461 cv::randn(in_mat2, mean, stddev);
1463 out_mat_gapi = cv::Mat(sz_out, type);
1464 out_mat_ocv = cv::Mat(sz_out, type);
1466 // OpenCV code ///////////////////////////////////////////////////////////
1467 cv::hconcat(in_mat1, in_mat2, out_mat_ocv);
1469 // G-API code ////////////////////////////////////////////////////////////
1471 auto out = cv::gapi::concatHor(in1, in2);
1472 cv::GComputation c(GIn(in1, in2), GOut(out));
1474 // Warm-up graph engine:
1475 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
1479 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
1482 // Comparison ////////////////////////////////////////////////////////////
1483 EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
1485 SANITY_CHECK_NOTHING();
1488 //------------------------------------------------------------------------------
1490 PERF_TEST_P_(ConcatHorVecPerfTest, TestPerformance)
1492 cv::Size sz_out = get<0>(GetParam());
1493 MatType type = get<1>(GetParam());
1494 cv::GCompileArgs compile_args = get<2>(GetParam());
1496 int wpart1 = sz_out.width / 3;
1497 int wpart2 = sz_out.width / 2;
1499 cv::Size sz_in1 = cv::Size(wpart1, sz_out.height);
1500 cv::Size sz_in2 = cv::Size(wpart2, sz_out.height);
1501 cv::Size sz_in3 = cv::Size(sz_out.width - wpart1 - wpart2, sz_out.height);
1503 in_mat1 = cv::Mat(sz_in1, type);
1504 in_mat2 = cv::Mat(sz_in2, type);
1505 cv::Mat in_mat3(sz_in3, type);
1507 cv::Scalar mean = cv::Scalar::all(127);
1508 cv::Scalar stddev = cv::Scalar::all(40.f);
1510 cv::randn(in_mat1, mean, stddev);
1511 cv::randn(in_mat2, mean, stddev);
1512 cv::randn(in_mat3, mean, stddev);
1514 out_mat_gapi = cv::Mat(sz_out, type);
1515 out_mat_ocv = cv::Mat(sz_out, type);
1517 std::vector <cv::Mat> cvmats = { in_mat1, in_mat2, in_mat3 };
1519 // OpenCV code ///////////////////////////////////////////////////////////
1520 cv::hconcat(cvmats, out_mat_ocv);
1522 // G-API code //////////////////////////////////////////////////////////////
1523 std::vector <cv::GMat> mats(3);
1524 auto out = cv::gapi::concatHor(mats);
1525 cv::GComputation c({ mats[0], mats[1], mats[2] }, { out });
1527 // Warm-up graph engine:
1528 c.apply(gin(in_mat1, in_mat2, in_mat3), gout(out_mat_gapi), std::move(compile_args));
1532 c.apply(gin(in_mat1, in_mat2, in_mat3), gout(out_mat_gapi), std::move(compile_args));
1535 // Comparison ////////////////////////////////////////////////////////////
1536 EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
1538 SANITY_CHECK_NOTHING();
1541 //------------------------------------------------------------------------------
1543 PERF_TEST_P_(ConcatVertPerfTest, TestPerformance)
1545 cv::Size sz_out = get<0>(GetParam());
1546 MatType type = get<1>(GetParam());
1547 cv::GCompileArgs compile_args = get<2>(GetParam());
1549 int hpart = sz_out.height * 2 / 3;
1551 cv::Size sz_in1 = cv::Size(sz_out.width, hpart);
1552 cv::Size sz_in2 = cv::Size(sz_out.width, sz_out.height - hpart);
1554 in_mat1 = cv::Mat(sz_in1, type);
1555 in_mat2 = cv::Mat(sz_in2, type);
1557 cv::Scalar mean = cv::Scalar::all(127);
1558 cv::Scalar stddev = cv::Scalar::all(40.f);
1560 cv::randn(in_mat1, mean, stddev);
1561 cv::randn(in_mat2, mean, stddev);
1563 out_mat_gapi = cv::Mat(sz_out, type);
1564 out_mat_ocv = cv::Mat(sz_out, type);
1566 // OpenCV code ///////////////////////////////////////////////////////////
1567 cv::vconcat(in_mat1, in_mat2, out_mat_ocv);
1569 // G-API code //////////////////////////////////////////////////////////////
1571 auto out = cv::gapi::concatVert(in1, in2);
1572 cv::GComputation c(GIn(in1, in2), GOut(out));
1574 // Warm-up graph engine:
1575 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
1579 c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
1582 // Comparison ////////////////////////////////////////////////////////////
1583 EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
1585 SANITY_CHECK_NOTHING();
1588 //------------------------------------------------------------------------------
1590 PERF_TEST_P_(ConcatVertVecPerfTest, TestPerformance)
1592 cv::Size sz_out = get<0>(GetParam());
1593 MatType type = get<1>(GetParam());
1594 cv::GCompileArgs compile_args = get<2>(GetParam());
1596 int hpart1 = sz_out.height * 2 / 5;
1597 int hpart2 = sz_out.height / 5;
1599 cv::Size sz_in1 = cv::Size(sz_out.width, hpart1);
1600 cv::Size sz_in2 = cv::Size(sz_out.width, hpart2);
1601 cv::Size sz_in3 = cv::Size(sz_out.width, sz_out.height - hpart1 - hpart2);
1603 in_mat1 = cv::Mat(sz_in1, type);
1604 in_mat2 = cv::Mat(sz_in2, type);
1605 cv::Mat in_mat3(sz_in3, type);
1607 cv::Scalar mean = cv::Scalar::all(127);
1608 cv::Scalar stddev = cv::Scalar::all(40.f);
1610 cv::randn(in_mat1, mean, stddev);
1611 cv::randn(in_mat2, mean, stddev);
1612 cv::randn(in_mat3, mean, stddev);
1614 out_mat_gapi = cv::Mat(sz_out, type);
1615 out_mat_ocv = cv::Mat(sz_out, type);
1617 std::vector <cv::Mat> cvmats = { in_mat1, in_mat2, in_mat3 };
1619 // OpenCV code ///////////////////////////////////////////////////////////
1620 cv::vconcat(cvmats, out_mat_ocv);
1622 // G-API code //////////////////////////////////////////////////////////////
1623 std::vector <cv::GMat> mats(3);
1624 auto out = cv::gapi::concatVert(mats);
1625 cv::GComputation c({ mats[0], mats[1], mats[2] }, { out });
1627 // Warm-up graph engine:
1628 c.apply(gin(in_mat1, in_mat2, in_mat3), gout(out_mat_gapi), std::move(compile_args));
1632 c.apply(gin(in_mat1, in_mat2, in_mat3), gout(out_mat_gapi), std::move(compile_args));
1635 // Comparison ////////////////////////////////////////////////////////////
1636 EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
1638 SANITY_CHECK_NOTHING();
1641 //------------------------------------------------------------------------------
1643 PERF_TEST_P_(LUTPerfTest, TestPerformance)
1645 MatType type_mat = get<0>(GetParam());
1646 MatType type_lut = get<1>(GetParam());
1647 MatType type_out = CV_MAKETYPE(CV_MAT_DEPTH(type_lut), CV_MAT_CN(type_mat));
1648 cv::Size sz_in = get<2>(GetParam());
1649 cv::GCompileArgs compile_args = get<3>(GetParam());
1651 initMatrixRandU(type_mat, sz_in, type_out);
1652 cv::Size sz_lut = cv::Size(1, 256);
1653 cv::Mat in_lut(sz_lut, type_lut);
1654 cv::randu(in_lut, cv::Scalar::all(0), cv::Scalar::all(255));
1656 // OpenCV code ///////////////////////////////////////////////////////////
1657 cv::LUT(in_mat1, in_lut, out_mat_ocv);
1659 // G-API code //////////////////////////////////////////////////////////////
1661 auto out = cv::gapi::LUT(in, in_lut);
1662 cv::GComputation c(in, out);
1664 // Warm-up graph engine:
1665 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1669 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1672 // Comparison ////////////////////////////////////////////////////////////
1673 EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
1674 EXPECT_EQ(out_mat_gapi.size(), sz_in);
1676 SANITY_CHECK_NOTHING();
1679 //------------------------------------------------------------------------------
1681 PERF_TEST_P_(ConvertToPerfTest, TestPerformance)
1683 MatType type_mat = get<0>(GetParam());
1684 int depth_to = get<1>(GetParam());
1685 cv::Size sz_in = get<2>(GetParam());
1686 cv::GCompileArgs compile_args = get<3>(GetParam());
1687 MatType type_out = CV_MAKETYPE(depth_to, CV_MAT_CN(type_mat));
1689 initMatrixRandU(type_mat, sz_in, type_out);
1691 // OpenCV code ///////////////////////////////////////////////////////////
1692 in_mat1.convertTo(out_mat_ocv, depth_to);
1694 // G-API code //////////////////////////////////////////////////////////////
1696 auto out = cv::gapi::convertTo(in, depth_to);
1697 cv::GComputation c(in, out);
1699 // Warm-up graph engine:
1700 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1704 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1707 // Comparison ////////////////////////////////////////////////////////////
1708 // FIXIT unrealiable check: EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi));
1709 EXPECT_EQ(out_mat_gapi.size(), sz_in);
1711 SANITY_CHECK_NOTHING();
1714 //------------------------------------------------------------------------------
1716 PERF_TEST_P_(ResizePerfTest, TestPerformance)
1718 compare_f cmpF = get<0>(GetParam());
1719 MatType type = get<1>(GetParam());
1720 int interp = get<2>(GetParam());
1721 cv::Size sz_in = get<3>(GetParam());
1722 cv::Size sz_out = get<4>(GetParam());
1723 cv::GCompileArgs compile_args = get<5>(GetParam());
1725 in_mat1 = cv::Mat(sz_in, type);
1726 cv::Scalar mean = cv::Scalar::all(127);
1727 cv::Scalar stddev = cv::Scalar::all(40.f);
1728 cv::randn(in_mat1, mean, stddev);
1729 out_mat_gapi = cv::Mat(sz_out, type);
1730 out_mat_ocv = cv::Mat(sz_out, type);
1732 // OpenCV code ///////////////////////////////////////////////////////////
1733 cv::resize(in_mat1, out_mat_ocv, sz_out, 0.0, 0.0, interp);
1735 // G-API code //////////////////////////////////////////////////////////////
1737 auto out = cv::gapi::resize(in, sz_out, 0.0, 0.0, interp);
1738 cv::GComputation c(in, out);
1740 // Warm-up graph engine:
1741 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1745 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1748 // Comparison ////////////////////////////////////////////////////////////
1750 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
1753 SANITY_CHECK_NOTHING();
1756 //------------------------------------------------------------------------------
1758 PERF_TEST_P_(ResizeFxFyPerfTest, TestPerformance)
1760 compare_f cmpF = get<0>(GetParam());
1761 MatType type = get<1>(GetParam());
1762 int interp = get<2>(GetParam());
1763 cv::Size sz_in = get<3>(GetParam());
1764 double fx = get<4>(GetParam());
1765 double fy = get<5>(GetParam());
1766 cv::GCompileArgs compile_args = get<6>(GetParam());
1768 in_mat1 = cv::Mat(sz_in, type);
1769 cv::Scalar mean = cv::Scalar::all(127);
1770 cv::Scalar stddev = cv::Scalar::all(40.f);
1771 cv::randn(in_mat1, mean, stddev);
1772 cv::Size sz_out = cv::Size(saturate_cast<int>(sz_in.width *fx), saturate_cast<int>(sz_in.height*fy));
1773 out_mat_gapi = cv::Mat(sz_out, type);
1774 out_mat_ocv = cv::Mat(sz_out, type);
1776 // OpenCV code ///////////////////////////////////////////////////////////
1777 cv::resize(in_mat1, out_mat_ocv, sz_out, fx, fy, interp);
1779 // G-API code //////////////////////////////////////////////////////////////
1781 auto out = cv::gapi::resize(in, sz_out, fx, fy, interp);
1782 cv::GComputation c(in, out);
1784 // Warm-up graph engine:
1785 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1789 c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1792 // Comparison ////////////////////////////////////////////////////////////
1794 EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
1797 SANITY_CHECK_NOTHING();
1800 //------------------------------------------------------------------------------
1803 #endif // OPENCV_GAPI_CORE_PERF_TESTS_INL_HPP