Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / fluid / modules / gapi / perf / common / gapi_core_perf_tests_inl.hpp
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.
4 //
5 // Copyright (C) 2018-2019 Intel Corporation
6
7
8 #ifndef OPENCV_GAPI_CORE_PERF_TESTS_INL_HPP
9 #define OPENCV_GAPI_CORE_PERF_TESTS_INL_HPP
10
11 #include <iostream>
12
13 #include "gapi_core_perf_tests.hpp"
14
15 namespace opencv_test
16 {
17 using namespace perf;
18
19 //------------------------------------------------------------------------------
20
21 PERF_TEST_P_(AddPerfTest, TestPerformance)
22 {
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());
27
28     initMatsRandU(type, sz, dtype, false);
29
30     // OpenCV code ///////////////////////////////////////////////////////////
31     cv::add(in_mat1, in_mat2, out_mat_ocv, cv::noArray(), dtype);
32
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));
37
38     // Warm-up graph engine:
39     c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
40
41     TEST_CYCLE()
42     {
43         c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
44     }
45
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);
49
50     SANITY_CHECK_NOTHING();
51 }
52
53 //------------------------------------------------------------------------------
54
55 PERF_TEST_P_(AddCPerfTest, TestPerformance)
56 {
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());
61
62     initMatsRandU(type, sz, dtype, false);
63
64     // OpenCV code ///////////////////////////////////////////////////////////
65     cv::add(in_mat1, sc, out_mat_ocv, cv::noArray(), dtype);
66
67     // G-API code ////////////////////////////////////////////////////////////
68     cv::GMat in1, out;
69     cv::GScalar sc1;
70     out = cv::gapi::addC(in1, sc1, dtype);
71     cv::GComputation c(GIn(in1, sc1), GOut(out));
72
73     // Warm-up graph engine:
74     c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
75
76     TEST_CYCLE()
77     {
78         c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
79     }
80
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);
84
85     SANITY_CHECK_NOTHING();
86 }
87
88 //------------------------------------------------------------------------------
89
90 PERF_TEST_P_(SubPerfTest, TestPerformance)
91 {
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());
96
97     initMatsRandU(type, sz, dtype, false);
98
99     // OpenCV code ///////////////////////////////////////////////////////////
100     cv::subtract(in_mat1, in_mat2, out_mat_ocv, cv::noArray(), dtype);
101
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));
106
107     // Warm-up graph engine:
108     c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
109
110     TEST_CYCLE()
111     {
112         c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
113     }
114
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);
118
119     SANITY_CHECK_NOTHING();
120 }
121
122 //------------------------------------------------------------------------------
123
124 PERF_TEST_P_(SubCPerfTest, TestPerformance)
125 {
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());
130
131     initMatsRandU(type, sz, dtype, false);
132
133     // OpenCV code ///////////////////////////////////////////////////////////
134     cv::subtract(in_mat1, sc, out_mat_ocv, cv::noArray(), dtype);
135
136     // G-API code ////////////////////////////////////////////////////////////
137     cv::GMat in1, out;
138     cv::GScalar sc1;
139     out = cv::gapi::subC(in1, sc1, dtype);
140     cv::GComputation c(GIn(in1, sc1), GOut(out));
141
142     // Warm-up graph engine:
143     c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
144
145     TEST_CYCLE()
146     {
147         c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
148     }
149
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);
153
154     SANITY_CHECK_NOTHING();
155 }
156
157 //------------------------------------------------------------------------------
158
159 PERF_TEST_P_(SubRCPerfTest, TestPerformance)
160 {
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());
165
166     initMatsRandU(type, sz, dtype, false);
167
168     // OpenCV code ///////////////////////////////////////////////////////////
169     cv::subtract(sc, in_mat1, out_mat_ocv, cv::noArray(), dtype);
170
171     // G-API code ////////////////////////////////////////////////////////////
172     cv::GMat in1, out;
173     cv::GScalar sc1;
174     out = cv::gapi::subRC(sc1, in1, dtype);
175     cv::GComputation c(GIn(in1, sc1), GOut(out));
176
177     // Warm-up graph engine:
178     c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
179
180     TEST_CYCLE()
181     {
182         c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
183     }
184
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);
188
189     SANITY_CHECK_NOTHING();
190 }
191
192 //------------------------------------------------------------------------------
193
194 PERF_TEST_P_(MulPerfTest, TestPerformance)
195 {
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());
200
201     initMatsRandU(type, sz, dtype, false);
202
203     // OpenCV code ///////////////////////////////////////////////////////////
204     cv::multiply(in_mat1, in_mat2, out_mat_ocv, 1.0, dtype);
205
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));
210
211     // Warm-up graph engine:
212     c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
213
214     TEST_CYCLE()
215     {
216         c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
217     }
218
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);
222
223     SANITY_CHECK_NOTHING();
224 }
225
226 //------------------------------------------------------------------------------
227
228 PERF_TEST_P_(MulDoublePerfTest, TestPerformance)
229 {
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());
234
235     auto& rng = cv::theRNG();
236     double d = rng.uniform(0.0, 10.0);
237     initMatrixRandU(type, sz, dtype, false);
238
239     // OpenCV code ///////////////////////////////////////////////////////////
240     cv::multiply(in_mat1, d, out_mat_ocv, 1, dtype);
241
242     // G-API code ////////////////////////////////////////////////////////////
243     cv::GMat in1, out;
244     out = cv::gapi::mulC(in1, d, dtype);
245     cv::GComputation c(in1, out);
246
247     // Warm-up graph engine:
248     c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
249
250     TEST_CYCLE()
251     {
252         c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
253     }
254
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);
258
259     SANITY_CHECK_NOTHING();
260 }
261
262 //------------------------------------------------------------------------------
263
264 PERF_TEST_P_(MulCPerfTest, TestPerformance)
265 {
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());
270
271     initMatsRandU(type, sz, dtype, false);
272
273     // OpenCV code ///////////////////////////////////////////////////////////
274     cv::multiply(in_mat1, sc, out_mat_ocv, 1, dtype);
275
276     // G-API code ////////////////////////////////////////////////////////////
277     cv::GMat in1, out;
278     cv::GScalar sc1;
279     out = cv::gapi::mulC(in1, sc1, dtype);
280     cv::GComputation c(GIn(in1, sc1), GOut(out));
281
282     // Warm-up graph engine:
283     c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
284
285     TEST_CYCLE()
286     {
287         c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
288     }
289
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);
293
294     SANITY_CHECK_NOTHING();
295 }
296
297 //------------------------------------------------------------------------------
298
299 PERF_TEST_P_(DivPerfTest, TestPerformance)
300 {
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());
306
307     // FIXIT Unstable input data for divide
308     initMatsRandU(type, sz, dtype, false);
309
310     // OpenCV code ///////////////////////////////////////////////////////////
311     cv::divide(in_mat1, in_mat2, out_mat_ocv, dtype);
312
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));
317
318     // Warm-up graph engine:
319     c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
320
321     TEST_CYCLE()
322     {
323         c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
324     }
325
326     // Comparison ////////////////////////////////////////////////////////////
327     // FIXIT unrealiable check: EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
328     EXPECT_EQ(out_mat_gapi.size(), sz);
329
330     SANITY_CHECK_NOTHING();
331 }
332
333 //------------------------------------------------------------------------------
334
335 PERF_TEST_P_(DivCPerfTest, TestPerformance)
336 {
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());
341
342     // FIXIT Unstable input data for divide
343     initMatsRandU(type, sz, dtype, false);
344
345     // OpenCV code ///////////////////////////////////////////////////////////
346     cv::divide(in_mat1, sc, out_mat_ocv, 1.0, dtype);
347
348     // G-API code ////////////////////////////////////////////////////////////
349     cv::GMat in1, out;
350     cv::GScalar sc1;
351     out = cv::gapi::divC(in1, sc1, 1.0, dtype);
352     cv::GComputation c(GIn(in1, sc1), GOut(out));
353
354     // Warm-up graph engine:
355     c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
356
357     TEST_CYCLE()
358     {
359         c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
360     }
361
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);
365
366     SANITY_CHECK_NOTHING();
367 }
368
369 //------------------------------------------------------------------------------
370
371 PERF_TEST_P_(DivRCPerfTest, TestPerformance)
372 {
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());
378
379     // FIXIT Unstable input data for divide
380     initMatsRandU(type, sz, dtype, false);
381
382     // FIXIT Unstable input data for divide, don't process zeros
383     sc += Scalar::all(1);
384     in_mat1 += 1;
385
386     // OpenCV code ///////////////////////////////////////////////////////////
387     cv::divide(sc, in_mat1, out_mat_ocv, 1.0, dtype);
388
389     // G-API code ////////////////////////////////////////////////////////////
390     cv::GMat in1, out;
391     cv::GScalar sc1;
392     out = cv::gapi::divRC(sc1, in1, 1.0, dtype);
393     cv::GComputation c(GIn(in1, sc1), GOut(out));
394
395     // Warm-up graph engine:
396     c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
397
398     TEST_CYCLE()
399     {
400         c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
401     }
402
403     // Comparison ////////////////////////////////////////////////////////////
404     EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
405     EXPECT_EQ(out_mat_gapi.size(), sz);
406
407     SANITY_CHECK_NOTHING();
408 }
409
410 //------------------------------------------------------------------------------
411
412 PERF_TEST_P_(MaskPerfTest, TestPerformance)
413 {
414     Size sz_in = get<0>(GetParam());
415     MatType type = get<1>(GetParam());
416     cv::GCompileArgs compile_args = get<2>(GetParam());
417
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;
422
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);
426
427     // G-API code ////////////////////////////////////////////////////////////
428     cv::GMat in, m;
429     auto out = cv::gapi::mask(in, m);
430     cv::GComputation c(cv::GIn(in, m), cv::GOut(out));
431
432     // Warm-up graph engine:
433     c.apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat_gapi), std::move(compile_args));
434
435     TEST_CYCLE()
436     {
437         c.apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat_gapi), std::move(compile_args));
438     }
439
440     // Comparison ////////////////////////////////////////////////////////////
441     EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
442
443     SANITY_CHECK_NOTHING();
444 }
445
446 //------------------------------------------------------------------------------
447
448 PERF_TEST_P_(MeanPerfTest, TestPerformance)
449 {
450     Size sz_in = get<0>(GetParam());
451     MatType type = get<1>(GetParam());
452     cv::GCompileArgs compile_args = get<2>(GetParam());
453
454     initMatrixRandU(type, sz_in, false);
455     cv::Scalar out_norm;
456     cv::Scalar out_norm_ocv;
457
458     // OpenCV code ///////////////////////////////////////////////////////////
459     out_norm_ocv = cv::mean(in_mat1);
460
461     // G-API code ////////////////////////////////////////////////////////////
462     cv::GMat in;
463     auto out = cv::gapi::mean(in);
464     cv::GComputation c(cv::GIn(in), cv::GOut(out));
465
466     // Warm-up graph engine:
467     c.apply(cv::gin(in_mat1), cv::gout(out_norm), std::move(compile_args));
468
469     TEST_CYCLE()
470     {
471         c.apply(cv::gin(in_mat1), cv::gout(out_norm), std::move(compile_args));
472     }
473
474     // Comparison ////////////////////////////////////////////////////////////
475     // FIXIT unrealiable check: EXPECT_EQ(out_norm[0], out_norm_ocv[0]);
476
477     SANITY_CHECK_NOTHING();
478 }
479
480 //------------------------------------------------------------------------------
481
482 PERF_TEST_P_(Polar2CartPerfTest, TestPerformance)
483 {
484     compare_f cmpF = get<0>(GetParam());
485     Size sz_in = get<1>(GetParam());
486     cv::GCompileArgs compile_args = get<2>(GetParam());
487
488     initMatsRandU(CV_32FC1, sz_in, CV_32FC1, false);
489     cv::Mat out_mat2;
490     cv::Mat out_mat_ocv2;
491
492     // OpenCV code ///////////////////////////////////////////////////////////
493     cv::polarToCart(in_mat1, in_mat2, out_mat_ocv, out_mat_ocv2);
494
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));
499
500     // Warm-up graph engine:
501     c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi, out_mat2), std::move(compile_args));
502
503     TEST_CYCLE()
504     {
505         c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi, out_mat2), std::move(compile_args));
506     }
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);
511
512     SANITY_CHECK_NOTHING();
513 }
514
515 //------------------------------------------------------------------------------
516
517 PERF_TEST_P_(Cart2PolarPerfTest, TestPerformance)
518 {
519     compare_f cmpF = get<0>(GetParam());
520     Size sz_in = get<1>(GetParam());
521     cv::GCompileArgs compile_args = get<2>(GetParam());
522
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);
526
527     // OpenCV code ///////////////////////////////////////////////////////////
528     cv::cartToPolar(in_mat1, in_mat2, out_mat_ocv, out_mat_ocv2);
529
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));
534
535     // Warm-up graph engine:
536     c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi, out_mat2), std::move(compile_args));
537
538     TEST_CYCLE()
539     {
540         c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi, out_mat2), std::move(compile_args));
541     }
542
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);
547
548     SANITY_CHECK_NOTHING();
549 }
550
551 //------------------------------------------------------------------------------
552
553 PERF_TEST_P_(CmpPerfTest, TestPerformance)
554 {
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());
559
560     initMatsRandU(type, sz, CV_8U, false);
561
562     // OpenCV code ///////////////////////////////////////////////////////////
563     cv::compare(in_mat1, in_mat2, out_mat_ocv, opType);
564
565     // G-API code ////////////////////////////////////////////////////////////
566     cv::GMat in1, in2, out;
567     switch (opType)
568     {
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!";
576     }
577     cv::GComputation c(GIn(in1, in2), GOut(out));
578
579     // Warm-up graph engine:
580     c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
581
582     TEST_CYCLE()
583     {
584         c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
585     }
586
587     // Comparison ////////////////////////////////////////////////////////////
588     EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
589     EXPECT_EQ(out_mat_gapi.size(), sz);
590
591     SANITY_CHECK_NOTHING();
592 }
593
594 //------------------------------------------------------------------------------
595
596 PERF_TEST_P_(CmpWithScalarPerfTest, TestPerformance)
597 {
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());
602
603     initMatsRandU(type, sz, CV_8U, false);
604
605     // OpenCV code ///////////////////////////////////////////////////////////
606     cv::compare(in_mat1, sc, out_mat_ocv, opType);
607
608     // G-API code ////////////////////////////////////////////////////////////
609     cv::GMat in1, out;
610     cv::GScalar in2;
611     switch (opType)
612     {
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!";
620     }
621     cv::GComputation c(GIn(in1, in2), GOut(out));
622
623     // Warm-up graph engine:
624     c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
625
626     TEST_CYCLE()
627     {
628         c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
629     }
630
631     // Comparison ////////////////////////////////////////////////////////////
632     EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv));
633     EXPECT_EQ(out_mat_gapi.size(), sz);
634
635     SANITY_CHECK_NOTHING();
636 }
637
638 //------------------------------------------------------------------------------
639
640 PERF_TEST_P_(BitwisePerfTest, TestPerformance)
641 {
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());
646
647     initMatsRandU(type, sz, type, false);
648
649     // G-API code & corresponding OpenCV code ////////////////////////////////
650     cv::GMat in1, in2, out;
651     switch (opType)
652     {
653     case AND:
654     {
655         out = cv::gapi::bitwise_and(in1, in2);
656         cv::bitwise_and(in_mat1, in_mat2, out_mat_ocv);
657         break;
658     }
659     case OR:
660     {
661         out = cv::gapi::bitwise_or(in1, in2);
662         cv::bitwise_or(in_mat1, in_mat2, out_mat_ocv);
663         break;
664     }
665     case XOR:
666     {
667         out = cv::gapi::bitwise_xor(in1, in2);
668         cv::bitwise_xor(in_mat1, in_mat2, out_mat_ocv);
669         break;
670     }
671     default:
672     {
673         FAIL() << "no such bitwise operation type!";
674     }
675     }
676     cv::GComputation c(GIn(in1, in2), GOut(out));
677
678     // Warm-up graph engine:
679     c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
680
681     TEST_CYCLE()
682     {
683         c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
684     }
685
686     // Comparison ////////////////////////////////////////////////////////////
687     EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
688     EXPECT_EQ(out_mat_gapi.size(), sz);
689
690     SANITY_CHECK_NOTHING();
691 }
692
693 //------------------------------------------------------------------------------
694
695 PERF_TEST_P_(BitwiseNotPerfTest, TestPerformance)
696 {
697     cv::Size sz_in = get<0>(GetParam());
698     MatType type = get<1>(GetParam());
699     cv::GCompileArgs compile_args = get<2>(GetParam());
700
701     initMatrixRandU(type, sz_in, type, false);
702
703     // OpenCV code ///////////////////////////////////////////////////////////
704     cv::bitwise_not(in_mat1, out_mat_ocv);
705
706     // G-API code ////////////////////////////////////////////////////////////
707     cv::GMat in, out;
708     out = cv::gapi::bitwise_not(in);
709     cv::GComputation c(in, out);
710
711     // Warm-up graph engine:
712     c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
713
714     TEST_CYCLE()
715     {
716         c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
717     }
718
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);
722
723     SANITY_CHECK_NOTHING();
724 }
725
726 //------------------------------------------------------------------------------
727
728 PERF_TEST_P_(SelectPerfTest, TestPerformance)
729 {
730     cv::Size sz_in = get<0>(GetParam());
731     MatType type = get<1>(GetParam());
732     cv::GCompileArgs compile_args = get<2>(GetParam());
733
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));
737
738     // OpenCV code ///////////////////////////////////////////////////////////
739     in_mat2.copyTo(out_mat_ocv);
740     in_mat1.copyTo(out_mat_ocv, in_mask);
741
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));
746
747     // Warm-up graph engine:
748     c.apply(gin(in_mat1, in_mat2, in_mask), gout(out_mat_gapi), std::move(compile_args));
749
750     TEST_CYCLE()
751     {
752         c.apply(gin(in_mat1, in_mat2, in_mask), gout(out_mat_gapi), std::move(compile_args));
753     }
754
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);
758
759     SANITY_CHECK_NOTHING();
760 }
761
762 //------------------------------------------------------------------------------
763
764 PERF_TEST_P_(MinPerfTest, TestPerformance)
765 {
766     cv::Size sz_in = get<0>(GetParam());
767     MatType type = get<1>(GetParam());
768     cv::GCompileArgs compile_args = get<2>(GetParam());
769
770
771     initMatsRandU(type, sz_in, type, false);
772
773     // OpenCV code ///////////////////////////////////////////////////////////
774     cv::min(in_mat1, in_mat2, out_mat_ocv);
775
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));
780
781     // Warm-up graph engine:
782     c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
783
784     TEST_CYCLE()
785     {
786         c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
787     }
788
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);
792
793     SANITY_CHECK_NOTHING();
794 }
795
796 //------------------------------------------------------------------------------
797
798 PERF_TEST_P_(MaxPerfTest, TestPerformance)
799 {
800     cv::Size sz_in = get<0>(GetParam());
801     MatType type = get<1>(GetParam());
802     cv::GCompileArgs compile_args = get<2>(GetParam());
803
804
805     initMatsRandU(type, sz_in, type, false);
806
807     // OpenCV code ///////////////////////////////////////////////////////////
808     cv::max(in_mat1, in_mat2, out_mat_ocv);
809
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));
814
815     // Warm-up graph engine:
816     c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
817
818     TEST_CYCLE()
819     {
820         c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
821     }
822
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);
826
827     SANITY_CHECK_NOTHING();
828 }
829
830 //------------------------------------------------------------------------------
831
832 PERF_TEST_P_(AbsDiffPerfTest, TestPerformance)
833 {
834     cv::Size sz_in = get<0>(GetParam());
835     MatType type = get<1>(GetParam());
836     cv::GCompileArgs compile_args = get<2>(GetParam());
837
838
839     initMatsRandU(type, sz_in, type, false);
840
841     // OpenCV code ///////////////////////////////////////////////////////////
842     cv::absdiff(in_mat1, in_mat2, out_mat_ocv);
843
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));
848
849     // Warm-up graph engine:
850     c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
851
852     TEST_CYCLE()
853     {
854         c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
855     }
856
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);
860
861     SANITY_CHECK_NOTHING();
862 }
863
864 //------------------------------------------------------------------------------
865
866 PERF_TEST_P_(AbsDiffCPerfTest, TestPerformance)
867 {
868     cv::Size sz_in = get<0>(GetParam());
869     MatType type = get<1>(GetParam());
870     cv::GCompileArgs compile_args = get<2>(GetParam());
871
872
873     initMatsRandU(type, sz_in, type, false);
874
875     // OpenCV code ///////////////////////////////////////////////////////////
876     cv::absdiff(in_mat1, sc, out_mat_ocv);
877
878     // G-API code ////////////////////////////////////////////////////////////
879     cv::GMat in1, out;
880     cv::GScalar sc1;
881     out = cv::gapi::absDiffC(in1, sc1);
882     cv::GComputation c(cv::GIn(in1, sc1), cv::GOut(out));
883
884     // Warm-up graph engine:
885     c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
886
887     TEST_CYCLE()
888     {
889         c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args));
890     }
891
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);
895
896     SANITY_CHECK_NOTHING();
897 }
898
899 //------------------------------------------------------------------------------
900
901 PERF_TEST_P_(SumPerfTest, TestPerformance)
902 {
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());
907
908
909     initMatrixRandU(type, sz_in, type, false);
910     cv::Scalar out_sum;
911     cv::Scalar out_sum_ocv;
912
913     // OpenCV code ///////////////////////////////////////////////////////////
914     out_sum_ocv = cv::sum(in_mat1);
915
916     // G-API code ////////////////////////////////////////////////////////////
917     cv::GMat in;
918     auto out = cv::gapi::sum(in);
919     cv::GComputation c(cv::GIn(in), cv::GOut(out));
920
921     // Warm-up graph engine:
922     c.apply(cv::gin(in_mat1), cv::gout(out_sum), std::move(compile_args));
923
924     TEST_CYCLE()
925     {
926         c.apply(cv::gin(in_mat1), cv::gout(out_sum), std::move(compile_args));
927     }
928
929     // Comparison ////////////////////////////////////////////////////////////
930     {
931         EXPECT_TRUE(cmpF(out_sum, out_sum_ocv));
932     }
933
934     SANITY_CHECK_NOTHING();
935 }
936
937 //------------------------------------------------------------------------------
938
939 PERF_TEST_P_(AddWeightedPerfTest, TestPerformance)
940 {
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());
946
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);
952
953     // OpenCV code ///////////////////////////////////////////////////////////
954     cv::addWeighted(in_mat1, alpha, in_mat2, beta, gamma, out_mat_ocv, dtype);
955
956     // G-API code ////////////////////////////////////////////////////////////
957     cv::GMat in1, in2;
958     auto out = cv::gapi::addWeighted(in1, alpha, in2, beta, gamma, dtype);
959     cv::GComputation c(GIn(in1, in2), GOut(out));
960
961     // Warm-up graph engine:
962     c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
963
964     TEST_CYCLE()
965     {
966         c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
967     }
968
969     // Comparison ////////////////////////////////////////////////////////////
970     EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
971     EXPECT_EQ(out_mat_gapi.size(), sz_in);
972
973
974     SANITY_CHECK_NOTHING();
975 }
976
977 //------------------------------------------------------------------------------
978
979 PERF_TEST_P_(NormPerfTest, TestPerformance)
980 {
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());
986
987
988     initMatrixRandU(type, sz, type, false);
989     cv::Scalar out_norm;
990     cv::Scalar out_norm_ocv;
991
992     // OpenCV code ///////////////////////////////////////////////////////////
993     out_norm_ocv = cv::norm(in_mat1, opType);
994
995     // G-API code ////////////////////////////////////////////////////////////
996     cv::GMat in1;
997     cv::GScalar out;
998     switch (opType)
999     {
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!";
1004     }
1005     cv::GComputation c(GIn(in1), GOut(out));
1006
1007     // Warm-up graph engine:
1008     c.apply(gin(in_mat1), gout(out_norm), std::move(compile_args));
1009
1010     TEST_CYCLE()
1011     {
1012         c.apply(gin(in_mat1), gout(out_norm), std::move(compile_args));
1013     }
1014
1015     // Comparison ////////////////////////////////////////////////////////////
1016     {
1017         EXPECT_TRUE(cmpF(out_norm, out_norm_ocv));
1018     }
1019
1020     SANITY_CHECK_NOTHING();
1021 }
1022
1023 //------------------------------------------------------------------------------
1024
1025 PERF_TEST_P_(IntegralPerfTest, TestPerformance)
1026 {
1027     cv::Size sz_in = get<0>(GetParam());
1028     MatType type = get<1>(GetParam());
1029     cv::GCompileArgs compile_args = get<2>(GetParam());
1030
1031
1032     MatType type_out = (type == CV_8U) ? CV_32SC1 : CV_64FC1;
1033
1034
1035     in_mat1 = cv::Mat(sz_in, type);
1036     cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255));
1037
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);
1041
1042     cv::Mat out_mat2(sz_out, CV_64FC1);
1043     cv::Mat out_mat_ocv2(sz_out, CV_64FC1);
1044
1045     // OpenCV code ///////////////////////////////////////////////////////////
1046     cv::integral(in_mat1, out_mat_ocv1, out_mat_ocv2);
1047
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));
1052
1053     // Warm-up graph engine:
1054     c.apply(cv::gin(in_mat1), cv::gout(out_mat1, out_mat2), std::move(compile_args));
1055
1056     TEST_CYCLE()
1057     {
1058         c.apply(cv::gin(in_mat1), cv::gout(out_mat1, out_mat2), std::move(compile_args));
1059     }
1060
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));
1064
1065     SANITY_CHECK_NOTHING();
1066 }
1067
1068 //------------------------------------------------------------------------------
1069
1070 PERF_TEST_P_(ThresholdPerfTest, TestPerformance)
1071 {
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());
1076
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;
1081
1082     // OpenCV code ///////////////////////////////////////////////////////////
1083     cv::threshold(in_mat1, out_mat_ocv, thr.val[0], maxval.val[0], tt);
1084
1085     // G-API code ////////////////////////////////////////////////////////////
1086     cv::GMat in1, out;
1087     cv::GScalar th1, mv1;
1088     out = cv::gapi::threshold(in1, th1, mv1, tt);
1089     cv::GComputation c(GIn(in1, th1, mv1), GOut(out));
1090
1091     // Warm-up graph engine:
1092     c.apply(gin(in_mat1, thr, maxval), gout(out_mat_gapi), std::move(compile_args));
1093
1094     TEST_CYCLE()
1095     {
1096         c.apply(gin(in_mat1, thr, maxval), gout(out_mat_gapi), std::move(compile_args));
1097     }
1098
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);
1102
1103     SANITY_CHECK_NOTHING();
1104 }
1105
1106 //------------------------------------------------------------------------------
1107
1108 PERF_TEST_P_(ThresholdOTPerfTest, TestPerformance)
1109 {
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());
1114
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;
1118     double ocv_res;
1119
1120     // OpenCV code ///////////////////////////////////////////////////////////
1121     ocv_res = cv::threshold(in_mat1, out_mat_ocv, maxval.val[0], maxval.val[0], tt);
1122
1123     // G-API code ////////////////////////////////////////////////////////////
1124     cv::GMat in1, out;
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));
1128
1129     // Warm-up graph engine:
1130     c.apply(gin(in_mat1, maxval), gout(out_mat_gapi, out_gapi_scalar), std::move(compile_args));
1131
1132     TEST_CYCLE()
1133     {
1134         c.apply(gin(in_mat1, maxval), gout(out_mat_gapi, out_gapi_scalar), std::move(compile_args));
1135     }
1136
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]);
1141
1142     SANITY_CHECK_NOTHING();
1143 }
1144
1145 //------------------------------------------------------------------------------
1146
1147 PERF_TEST_P_(InRangePerfTest, TestPerformance)
1148 {
1149     cv::Size sz_in = get<0>(GetParam());
1150     MatType type = get<1>(GetParam());
1151     cv::GCompileArgs compile_args = get<2>(GetParam());
1152
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);
1156
1157     // OpenCV code ///////////////////////////////////////////////////////////
1158     cv::inRange(in_mat1, thrLow, thrUp, out_mat_ocv);
1159
1160     // G-API code ////////////////////////////////////////////////////////////
1161     cv::GMat in1;
1162     cv::GScalar th1, mv1;
1163     auto out = cv::gapi::inRange(in1, th1, mv1);
1164     cv::GComputation c(GIn(in1, th1, mv1), GOut(out));
1165
1166     // Warm-up graph engine:
1167     c.apply(gin(in_mat1, thrLow, thrUp), gout(out_mat_gapi), std::move(compile_args));
1168
1169     TEST_CYCLE()
1170     {
1171         c.apply(gin(in_mat1, thrLow, thrUp), gout(out_mat_gapi), std::move(compile_args));
1172     }
1173
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);
1177
1178     SANITY_CHECK_NOTHING();
1179 }
1180
1181 //------------------------------------------------------------------------------
1182
1183 PERF_TEST_P_(Split3PerfTest, TestPerformance)
1184 {
1185     Size sz_in = get<0>(GetParam());
1186     cv::GCompileArgs compile_args = get<1>(GetParam());
1187
1188
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);
1194
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);
1198
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));
1203
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));
1206
1207     TEST_CYCLE()
1208     {
1209         c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat2, out_mat3), std::move(compile_args));
1210     }
1211
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));
1216
1217     SANITY_CHECK_NOTHING();
1218 }
1219
1220 //------------------------------------------------------------------------------
1221
1222 PERF_TEST_P_(Split4PerfTest, TestPerformance)
1223 {
1224     Size sz_in = get<0>(GetParam());
1225     cv::GCompileArgs compile_args = get<1>(GetParam());
1226
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);
1234
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);
1238
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));
1243
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));
1246
1247     TEST_CYCLE()
1248     {
1249         c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat2, out_mat3, out_mat4), std::move(compile_args));
1250     }
1251
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));
1257
1258     SANITY_CHECK_NOTHING();
1259 }
1260
1261 //------------------------------------------------------------------------------
1262
1263 PERF_TEST_P_(Merge3PerfTest, TestPerformance)
1264 {
1265     Size sz_in = get<0>(GetParam());
1266     cv::GCompileArgs compile_args = get<1>(GetParam());
1267
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);
1273
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);
1277
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));
1282
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));
1285
1286     TEST_CYCLE()
1287     {
1288         c.apply(cv::gin(in_mat1, in_mat2, in_mat3), cv::gout(out_mat_gapi), std::move(compile_args));
1289     }
1290
1291     // Comparison ////////////////////////////////////////////////////////////
1292     EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
1293
1294     SANITY_CHECK_NOTHING();
1295 }
1296
1297 //------------------------------------------------------------------------------
1298
1299 PERF_TEST_P_(Merge4PerfTest, TestPerformance)
1300 {
1301     Size sz_in = get<0>(GetParam());
1302     cv::GCompileArgs compile_args = get<1>(GetParam());
1303
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);
1311
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);
1315
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));
1320
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));
1323
1324     TEST_CYCLE()
1325     {
1326         c.apply(cv::gin(in_mat1, in_mat2, in_mat3, in_mat4), cv::gout(out_mat_gapi), std::move(compile_args));
1327     }
1328
1329     // Comparison ////////////////////////////////////////////////////////////
1330     EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
1331
1332     SANITY_CHECK_NOTHING();
1333 }
1334
1335 //------------------------------------------------------------------------------
1336
1337 PERF_TEST_P_(RemapPerfTest, TestPerformance)
1338 {
1339     cv::Size sz_in = get<0>(GetParam());
1340     MatType type = get<1>(GetParam());
1341     cv::GCompileArgs compile_args = get<2>(GetParam());
1342
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();
1348
1349     // OpenCV code ///////////////////////////////////////////////////////////
1350     cv::remap(in_mat1, out_mat_ocv, in_map1, in_map2, cv::INTER_NEAREST, cv::BORDER_REPLICATE, bv);
1351
1352     // G-API code ////////////////////////////////////////////////////////////
1353     cv::GMat in1;
1354     auto out = cv::gapi::remap(in1, in_map1, in_map2, cv::INTER_NEAREST, cv::BORDER_REPLICATE, bv);
1355     cv::GComputation c(in1, out);
1356
1357     // Warm-up graph engine:
1358     c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1359
1360     TEST_CYCLE()
1361     {
1362         c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1363     }
1364
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);
1368
1369     SANITY_CHECK_NOTHING();
1370 }
1371
1372 //------------------------------------------------------------------------------
1373
1374 PERF_TEST_P_(FlipPerfTest, TestPerformance)
1375 {
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());
1380
1381     initMatrixRandU(type, sz_in, type, false);
1382
1383     // OpenCV code ///////////////////////////////////////////////////////////
1384     cv::flip(in_mat1, out_mat_ocv, flipCode);
1385
1386     // G-API code ////////////////////////////////////////////////////////////
1387     cv::GMat in;
1388     auto out = cv::gapi::flip(in, flipCode);
1389     cv::GComputation c(in, out);
1390
1391     // Warm-up graph engine:
1392     c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1393
1394     TEST_CYCLE()
1395     {
1396         c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1397     }
1398
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);
1402
1403     SANITY_CHECK_NOTHING();
1404 }
1405
1406 //------------------------------------------------------------------------------
1407
1408 PERF_TEST_P_(CropPerfTest, TestPerformance)
1409 {
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());
1414
1415     initMatrixRandU(type, sz_in, type, false);
1416     cv::Size sz_out = cv::Size(rect_to.width, rect_to.height);
1417
1418     // OpenCV code ///////////////////////////////////////////////////////////
1419     cv::Mat(in_mat1, rect_to).copyTo(out_mat_ocv);
1420
1421     // G-API code ////////////////////////////////////////////////////////////
1422     cv::GMat in;
1423     auto out = cv::gapi::crop(in, rect_to);
1424     cv::GComputation c(in, out);
1425
1426     // Warm-up graph engine:
1427     c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1428
1429     TEST_CYCLE()
1430     {
1431         c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1432     }
1433
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);
1437
1438     SANITY_CHECK_NOTHING();
1439 }
1440
1441 //------------------------------------------------------------------------------
1442
1443 PERF_TEST_P_(ConcatHorPerfTest, TestPerformance)
1444 {
1445     cv::Size sz_out = get<0>(GetParam());
1446     MatType type = get<1>(GetParam());
1447     cv::GCompileArgs compile_args = get<2>(GetParam());
1448
1449     int wpart = sz_out.width / 4;
1450
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);
1453
1454     in_mat1 = cv::Mat(sz_in1, type);
1455     in_mat2 = cv::Mat(sz_in2, type);
1456
1457     cv::Scalar mean = cv::Scalar::all(127);
1458     cv::Scalar stddev = cv::Scalar::all(40.f);
1459
1460     cv::randn(in_mat1, mean, stddev);
1461     cv::randn(in_mat2, mean, stddev);
1462
1463     out_mat_gapi = cv::Mat(sz_out, type);
1464     out_mat_ocv = cv::Mat(sz_out, type);
1465
1466     // OpenCV code ///////////////////////////////////////////////////////////
1467     cv::hconcat(in_mat1, in_mat2, out_mat_ocv);
1468
1469     // G-API code ////////////////////////////////////////////////////////////
1470     cv::GMat in1, in2;
1471     auto out = cv::gapi::concatHor(in1, in2);
1472     cv::GComputation c(GIn(in1, in2), GOut(out));
1473
1474     // Warm-up graph engine:
1475     c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
1476
1477     TEST_CYCLE()
1478     {
1479         c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
1480     }
1481
1482     // Comparison ////////////////////////////////////////////////////////////
1483     EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
1484
1485     SANITY_CHECK_NOTHING();
1486 }
1487
1488 //------------------------------------------------------------------------------
1489
1490 PERF_TEST_P_(ConcatHorVecPerfTest, TestPerformance)
1491 {
1492     cv::Size sz_out = get<0>(GetParam());
1493     MatType type = get<1>(GetParam());
1494     cv::GCompileArgs compile_args = get<2>(GetParam());
1495
1496     int wpart1 = sz_out.width / 3;
1497     int wpart2 = sz_out.width / 2;
1498
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);
1502
1503     in_mat1 = cv::Mat(sz_in1, type);
1504     in_mat2 = cv::Mat(sz_in2, type);
1505     cv::Mat in_mat3(sz_in3, type);
1506
1507     cv::Scalar mean = cv::Scalar::all(127);
1508     cv::Scalar stddev = cv::Scalar::all(40.f);
1509
1510     cv::randn(in_mat1, mean, stddev);
1511     cv::randn(in_mat2, mean, stddev);
1512     cv::randn(in_mat3, mean, stddev);
1513
1514     out_mat_gapi = cv::Mat(sz_out, type);
1515     out_mat_ocv = cv::Mat(sz_out, type);
1516
1517     std::vector <cv::Mat> cvmats = { in_mat1, in_mat2, in_mat3 };
1518
1519     // OpenCV code ///////////////////////////////////////////////////////////
1520     cv::hconcat(cvmats, out_mat_ocv);
1521
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 });
1526
1527     // Warm-up graph engine:
1528     c.apply(gin(in_mat1, in_mat2, in_mat3), gout(out_mat_gapi), std::move(compile_args));
1529
1530     TEST_CYCLE()
1531     {
1532         c.apply(gin(in_mat1, in_mat2, in_mat3), gout(out_mat_gapi), std::move(compile_args));
1533     }
1534
1535     // Comparison ////////////////////////////////////////////////////////////
1536     EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
1537
1538     SANITY_CHECK_NOTHING();
1539 }
1540
1541 //------------------------------------------------------------------------------
1542
1543 PERF_TEST_P_(ConcatVertPerfTest, TestPerformance)
1544 {
1545     cv::Size sz_out = get<0>(GetParam());
1546     MatType type = get<1>(GetParam());
1547     cv::GCompileArgs compile_args = get<2>(GetParam());
1548
1549     int hpart = sz_out.height * 2 / 3;
1550
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);
1553
1554     in_mat1 = cv::Mat(sz_in1, type);
1555     in_mat2 = cv::Mat(sz_in2, type);
1556
1557     cv::Scalar mean = cv::Scalar::all(127);
1558     cv::Scalar stddev = cv::Scalar::all(40.f);
1559
1560     cv::randn(in_mat1, mean, stddev);
1561     cv::randn(in_mat2, mean, stddev);
1562
1563     out_mat_gapi = cv::Mat(sz_out, type);
1564     out_mat_ocv = cv::Mat(sz_out, type);
1565
1566     // OpenCV code ///////////////////////////////////////////////////////////
1567     cv::vconcat(in_mat1, in_mat2, out_mat_ocv);
1568
1569     // G-API code //////////////////////////////////////////////////////////////
1570     cv::GMat in1, in2;
1571     auto out = cv::gapi::concatVert(in1, in2);
1572     cv::GComputation c(GIn(in1, in2), GOut(out));
1573
1574     // Warm-up graph engine:
1575     c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
1576
1577     TEST_CYCLE()
1578     {
1579         c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args));
1580     }
1581
1582     // Comparison ////////////////////////////////////////////////////////////
1583     EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
1584
1585     SANITY_CHECK_NOTHING();
1586 }
1587
1588 //------------------------------------------------------------------------------
1589
1590 PERF_TEST_P_(ConcatVertVecPerfTest, TestPerformance)
1591 {
1592     cv::Size sz_out = get<0>(GetParam());
1593     MatType type = get<1>(GetParam());
1594     cv::GCompileArgs compile_args = get<2>(GetParam());
1595
1596     int hpart1 = sz_out.height * 2 / 5;
1597     int hpart2 = sz_out.height / 5;
1598
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);
1602
1603     in_mat1 = cv::Mat(sz_in1, type);
1604     in_mat2 = cv::Mat(sz_in2, type);
1605     cv::Mat in_mat3(sz_in3, type);
1606
1607     cv::Scalar mean = cv::Scalar::all(127);
1608     cv::Scalar stddev = cv::Scalar::all(40.f);
1609
1610     cv::randn(in_mat1, mean, stddev);
1611     cv::randn(in_mat2, mean, stddev);
1612     cv::randn(in_mat3, mean, stddev);
1613
1614     out_mat_gapi = cv::Mat(sz_out, type);
1615     out_mat_ocv = cv::Mat(sz_out, type);
1616
1617     std::vector <cv::Mat> cvmats = { in_mat1, in_mat2, in_mat3 };
1618
1619     // OpenCV code ///////////////////////////////////////////////////////////
1620     cv::vconcat(cvmats, out_mat_ocv);
1621
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 });
1626
1627     // Warm-up graph engine:
1628     c.apply(gin(in_mat1, in_mat2, in_mat3), gout(out_mat_gapi), std::move(compile_args));
1629
1630     TEST_CYCLE()
1631     {
1632         c.apply(gin(in_mat1, in_mat2, in_mat3), gout(out_mat_gapi), std::move(compile_args));
1633     }
1634
1635     // Comparison ////////////////////////////////////////////////////////////
1636     EXPECT_EQ(0, cv::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
1637
1638     SANITY_CHECK_NOTHING();
1639 }
1640
1641 //------------------------------------------------------------------------------
1642
1643 PERF_TEST_P_(LUTPerfTest, TestPerformance)
1644 {
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());
1650
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));
1655
1656     // OpenCV code ///////////////////////////////////////////////////////////
1657     cv::LUT(in_mat1, in_lut, out_mat_ocv);
1658
1659     // G-API code //////////////////////////////////////////////////////////////
1660     cv::GMat in;
1661     auto out = cv::gapi::LUT(in, in_lut);
1662     cv::GComputation c(in, out);
1663
1664     // Warm-up graph engine:
1665     c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1666
1667     TEST_CYCLE()
1668     {
1669         c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1670     }
1671
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);
1675
1676     SANITY_CHECK_NOTHING();
1677 }
1678
1679 //------------------------------------------------------------------------------
1680
1681 PERF_TEST_P_(ConvertToPerfTest, TestPerformance)
1682 {
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));
1688
1689     initMatrixRandU(type_mat, sz_in, type_out);
1690
1691     // OpenCV code ///////////////////////////////////////////////////////////
1692     in_mat1.convertTo(out_mat_ocv, depth_to);
1693
1694     // G-API code //////////////////////////////////////////////////////////////
1695     cv::GMat in;
1696     auto out = cv::gapi::convertTo(in, depth_to);
1697     cv::GComputation c(in, out);
1698
1699     // Warm-up graph engine:
1700     c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1701
1702     TEST_CYCLE()
1703     {
1704         c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1705     }
1706
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);
1710
1711     SANITY_CHECK_NOTHING();
1712 }
1713
1714 //------------------------------------------------------------------------------
1715
1716 PERF_TEST_P_(ResizePerfTest, TestPerformance)
1717 {
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());
1724
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);
1731
1732     // OpenCV code ///////////////////////////////////////////////////////////
1733     cv::resize(in_mat1, out_mat_ocv, sz_out, 0.0, 0.0, interp);
1734
1735     // G-API code //////////////////////////////////////////////////////////////
1736     cv::GMat in;
1737     auto out = cv::gapi::resize(in, sz_out, 0.0, 0.0, interp);
1738     cv::GComputation c(in, out);
1739
1740     // Warm-up graph engine:
1741     c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1742
1743     TEST_CYCLE()
1744     {
1745         c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1746     }
1747
1748     // Comparison ////////////////////////////////////////////////////////////
1749     {
1750         EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
1751     }
1752
1753     SANITY_CHECK_NOTHING();
1754 }
1755
1756 //------------------------------------------------------------------------------
1757
1758 PERF_TEST_P_(ResizeFxFyPerfTest, TestPerformance)
1759 {
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());
1767
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);
1775
1776     // OpenCV code ///////////////////////////////////////////////////////////
1777     cv::resize(in_mat1, out_mat_ocv, sz_out, fx, fy, interp);
1778
1779     // G-API code //////////////////////////////////////////////////////////////
1780     cv::GMat in;
1781     auto out = cv::gapi::resize(in, sz_out, fx, fy, interp);
1782     cv::GComputation c(in, out);
1783
1784     // Warm-up graph engine:
1785     c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1786
1787     TEST_CYCLE()
1788     {
1789         c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
1790     }
1791
1792     // Comparison ////////////////////////////////////////////////////////////
1793     {
1794         EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
1795     }
1796
1797     SANITY_CHECK_NOTHING();
1798 }
1799
1800 //------------------------------------------------------------------------------
1801
1802 }
1803 #endif // OPENCV_GAPI_CORE_PERF_TESTS_INL_HPP