gapi_imgproc_perf_tests_inl.hpp 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947
  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-2020 Intel Corporation
  6. #ifndef OPENCV_GAPI_IMGPROC_PERF_TESTS_INL_HPP
  7. #define OPENCV_GAPI_IMGPROC_PERF_TESTS_INL_HPP
  8. #include "gapi_imgproc_perf_tests.hpp"
  9. #include "../../test/common/gapi_imgproc_tests_common.hpp"
  10. namespace opencv_test
  11. {
  12. using namespace perf;
  13. namespace
  14. {
  15. void rgb2yuyv(const uchar* rgb_line, uchar* yuv422_line, int width)
  16. {
  17. CV_Assert(width % 2 == 0);
  18. for (int i = 0; i < width; i += 2)
  19. {
  20. uchar r = rgb_line[i * 3 ];
  21. uchar g = rgb_line[i * 3 + 1];
  22. uchar b = rgb_line[i * 3 + 2];
  23. yuv422_line[i * 2 ] = cv::saturate_cast<uchar>(-0.14713 * r - 0.28886 * g + 0.436 * b + 128.f); // U0
  24. yuv422_line[i * 2 + 1] = cv::saturate_cast<uchar>( 0.299 * r + 0.587 * g + 0.114 * b ); // Y0
  25. yuv422_line[i * 2 + 2] = cv::saturate_cast<uchar>(0.615 * r - 0.51499 * g - 0.10001 * b + 128.f); // V0
  26. r = rgb_line[i * 3 + 3];
  27. g = rgb_line[i * 3 + 4];
  28. b = rgb_line[i * 3 + 5];
  29. yuv422_line[i * 2 + 3] = cv::saturate_cast<uchar>(0.299 * r + 0.587 * g + 0.114 * b); // Y1
  30. }
  31. }
  32. void convertRGB2YUV422Ref(const cv::Mat& in, cv::Mat &out)
  33. {
  34. out.create(in.size(), CV_8UC2);
  35. for (int i = 0; i < in.rows; ++i)
  36. {
  37. const uchar* in_line_p = in.ptr<uchar>(i);
  38. uchar* out_line_p = out.ptr<uchar>(i);
  39. rgb2yuyv(in_line_p, out_line_p, in.cols);
  40. }
  41. }
  42. }
  43. //------------------------------------------------------------------------------
  44. PERF_TEST_P_(SepFilterPerfTest, TestPerformance)
  45. {
  46. compare_f cmpF;
  47. MatType type = 0;
  48. int kernSize = 0, dtype = 0;
  49. cv::Size sz;
  50. cv::GCompileArgs compile_args;
  51. std::tie(cmpF, type, kernSize, sz, dtype, compile_args) = GetParam();
  52. cv::Mat kernelX(kernSize, 1, CV_32F);
  53. cv::Mat kernelY(kernSize, 1, CV_32F);
  54. randu(kernelX, -1, 1);
  55. randu(kernelY, -1, 1);
  56. initMatrixRandN(type, sz, dtype, false);
  57. cv::Point anchor = cv::Point(-1, -1);
  58. // OpenCV code /////////////////////////////////////////////////////////////
  59. {
  60. cv::sepFilter2D(in_mat1, out_mat_ocv, dtype, kernelX, kernelY );
  61. }
  62. // G-API code //////////////////////////////////////////////////////////////
  63. cv::GMat in;
  64. auto out = cv::gapi::sepFilter(in, dtype, kernelX, kernelY, anchor, cv::Scalar() );
  65. cv::GComputation c(in, out);
  66. // Warm-up graph engine:
  67. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  68. TEST_CYCLE()
  69. {
  70. c.apply(in_mat1, out_mat_gapi);
  71. }
  72. // Comparison //////////////////////////////////////////////////////////////
  73. {
  74. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  75. EXPECT_EQ(out_mat_gapi.size(), sz);
  76. }
  77. SANITY_CHECK_NOTHING();
  78. }
  79. //------------------------------------------------------------------------------
  80. PERF_TEST_P_(Filter2DPerfTest, TestPerformance)
  81. {
  82. compare_f cmpF;
  83. MatType type = 0;
  84. int kernSize = 0, borderType = 0, dtype = 0;
  85. cv::Size sz;
  86. cv::GCompileArgs compile_args;
  87. std::tie(cmpF, type, kernSize, sz, borderType, dtype, compile_args) = GetParam();
  88. initMatrixRandN(type, sz, dtype, false);
  89. cv::Point anchor = {-1, -1};
  90. double delta = 0;
  91. cv::Mat kernel = cv::Mat(kernSize, kernSize, CV_32FC1 );
  92. cv::Scalar kernMean = cv::Scalar::all(1.0);
  93. cv::Scalar kernStddev = cv::Scalar::all(2.0/3);
  94. randn(kernel, kernMean, kernStddev);
  95. // OpenCV code /////////////////////////////////////////////////////////////
  96. {
  97. cv::filter2D(in_mat1, out_mat_ocv, dtype, kernel, anchor, delta, borderType);
  98. }
  99. // G-API code //////////////////////////////////////////////////////////////
  100. cv::GMat in;
  101. auto out = cv::gapi::filter2D(in, dtype, kernel, anchor, delta, borderType);
  102. cv::GComputation c(in, out);
  103. // Warm-up graph engine:
  104. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  105. TEST_CYCLE()
  106. {
  107. c.apply(in_mat1, out_mat_gapi);
  108. }
  109. // Comparison //////////////////////////////////////////////////////////////
  110. {
  111. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  112. EXPECT_EQ(out_mat_gapi.size(), sz);
  113. }
  114. SANITY_CHECK_NOTHING();
  115. }
  116. //------------------------------------------------------------------------------
  117. PERF_TEST_P_(BoxFilterPerfTest, TestPerformance)
  118. {
  119. compare_f cmpF;
  120. MatType type = 0;
  121. int filterSize = 0, borderType = 0, dtype = 0;
  122. cv::Size sz;
  123. cv::GCompileArgs compile_args;
  124. std::tie(cmpF, type, filterSize, sz, borderType, dtype, compile_args) = GetParam();
  125. initMatrixRandN(type, sz, dtype, false);
  126. cv::Point anchor = {-1, -1};
  127. bool normalize = true;
  128. // OpenCV code /////////////////////////////////////////////////////////////
  129. {
  130. cv::boxFilter(in_mat1, out_mat_ocv, dtype, cv::Size(filterSize, filterSize), anchor, normalize, borderType);
  131. }
  132. // G-API code //////////////////////////////////////////////////////////////
  133. cv::GMat in;
  134. auto out = cv::gapi::boxFilter(in, dtype, cv::Size(filterSize, filterSize), anchor, normalize, borderType);
  135. cv::GComputation c(in, out);
  136. // Warm-up graph engine:
  137. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  138. TEST_CYCLE()
  139. {
  140. c.apply(in_mat1, out_mat_gapi);
  141. }
  142. // Comparison //////////////////////////////////////////////////////////////
  143. {
  144. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  145. EXPECT_EQ(out_mat_gapi.size(), sz);
  146. }
  147. SANITY_CHECK_NOTHING();
  148. }
  149. //------------------------------------------------------------------------------
  150. PERF_TEST_P_(BlurPerfTest, TestPerformance)
  151. {
  152. compare_f cmpF;
  153. MatType type = 0;
  154. int filterSize = 0, borderType = 0;
  155. cv::Size sz;
  156. cv::GCompileArgs compile_args;
  157. std::tie(cmpF, type, filterSize, sz, borderType, compile_args) = GetParam();
  158. initMatrixRandN(type, sz, type, false);
  159. cv::Point anchor = {-1, -1};
  160. // OpenCV code /////////////////////////////////////////////////////////////
  161. {
  162. cv::blur(in_mat1, out_mat_ocv, cv::Size(filterSize, filterSize), anchor, borderType);
  163. }
  164. // G-API code //////////////////////////////////////////////////////////////
  165. cv::GMat in;
  166. auto out = cv::gapi::blur(in, cv::Size(filterSize, filterSize), anchor, borderType);
  167. cv::GComputation c(in, out);
  168. // Warm-up graph engine:
  169. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  170. TEST_CYCLE()
  171. {
  172. c.apply(in_mat1, out_mat_gapi);
  173. }
  174. // Comparison //////////////////////////////////////////////////////////////
  175. {
  176. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  177. EXPECT_EQ(out_mat_gapi.size(), sz);
  178. }
  179. SANITY_CHECK_NOTHING();
  180. }
  181. //------------------------------------------------------------------------------
  182. PERF_TEST_P_(GaussianBlurPerfTest, TestPerformance)
  183. {
  184. compare_f cmpF;
  185. MatType type = 0;
  186. int kernSize = 0;
  187. cv::Size sz;
  188. cv::GCompileArgs compile_args;
  189. std::tie(cmpF, type, kernSize, sz, compile_args) = GetParam();
  190. cv::Size kSize = cv::Size(kernSize, kernSize);
  191. auto& rng = cv::theRNG();
  192. double sigmaX = rng();
  193. initMatrixRandN(type, sz, type, false);
  194. // OpenCV code ///////////////////////////////////////////////////////////
  195. cv::GaussianBlur(in_mat1, out_mat_ocv, kSize, sigmaX);
  196. // G-API code //////////////////////////////////////////////////////////////
  197. cv::GMat in;
  198. auto out = cv::gapi::gaussianBlur(in, kSize, sigmaX);
  199. cv::GComputation c(in, out);
  200. // Warm-up graph engine:
  201. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  202. TEST_CYCLE()
  203. {
  204. c.apply(in_mat1, out_mat_gapi);
  205. }
  206. // Comparison //////////////////////////////////////////////////////////////
  207. {
  208. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  209. EXPECT_EQ(out_mat_gapi.size(), sz);
  210. }
  211. SANITY_CHECK_NOTHING();
  212. }
  213. //------------------------------------------------------------------------------
  214. PERF_TEST_P_(MedianBlurPerfTest, TestPerformance)
  215. {
  216. compare_f cmpF;
  217. MatType type = 0;
  218. int kernSize = 0;
  219. cv::Size sz;
  220. cv::GCompileArgs compile_args;
  221. std::tie(cmpF, type, kernSize, sz, compile_args) = GetParam();
  222. initMatrixRandN(type, sz, type, false);
  223. // OpenCV code /////////////////////////////////////////////////////////////
  224. {
  225. cv::medianBlur(in_mat1, out_mat_ocv, kernSize);
  226. }
  227. // G-API code //////////////////////////////////////////////////////////////
  228. cv::GMat in;
  229. auto out = cv::gapi::medianBlur(in, kernSize);
  230. cv::GComputation c(in, out);
  231. // Warm-up graph engine:
  232. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  233. TEST_CYCLE()
  234. {
  235. c.apply(in_mat1, out_mat_gapi);
  236. }
  237. // Comparison //////////////////////////////////////////////////////////////
  238. {
  239. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  240. EXPECT_EQ(out_mat_gapi.size(), sz);
  241. }
  242. SANITY_CHECK_NOTHING();
  243. }
  244. //------------------------------------------------------------------------------
  245. PERF_TEST_P_(ErodePerfTest, TestPerformance)
  246. {
  247. compare_f cmpF;
  248. MatType type = 0;
  249. int kernSize = 0, kernType = 0;
  250. cv::Size sz;
  251. cv::GCompileArgs compile_args;
  252. std::tie(cmpF, type, kernSize, sz, kernType, compile_args) = GetParam();
  253. initMatrixRandN(type, sz, type, false);
  254. cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize));
  255. // OpenCV code /////////////////////////////////////////////////////////////
  256. {
  257. cv::erode(in_mat1, out_mat_ocv, kernel);
  258. }
  259. // G-API code //////////////////////////////////////////////////////////////
  260. cv::GMat in;
  261. auto out = cv::gapi::erode(in, kernel);
  262. cv::GComputation c(in, out);
  263. // Warm-up graph engine:
  264. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  265. TEST_CYCLE()
  266. {
  267. c.apply(in_mat1, out_mat_gapi);
  268. }
  269. // Comparison //////////////////////////////////////////////////////////////
  270. {
  271. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  272. EXPECT_EQ(out_mat_gapi.size(), sz);
  273. }
  274. SANITY_CHECK_NOTHING();
  275. }
  276. //------------------------------------------------------------------------------
  277. PERF_TEST_P_(Erode3x3PerfTest, TestPerformance)
  278. {
  279. compare_f cmpF;
  280. MatType type = 0;
  281. int numIters = 0;
  282. cv::Size sz;
  283. cv::GCompileArgs compile_args;
  284. std::tie(cmpF, type, sz, numIters, compile_args) = GetParam();
  285. initMatrixRandN(type, sz, type, false);
  286. cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3, 3));
  287. // OpenCV code /////////////////////////////////////////////////////////////
  288. {
  289. cv::erode(in_mat1, out_mat_ocv, kernel, cv::Point(-1, -1), numIters);
  290. }
  291. // G-API code //////////////////////////////////////////////////////////////
  292. cv::GMat in;
  293. auto out = cv::gapi::erode3x3(in, numIters);
  294. cv::GComputation c(in, out);
  295. // Warm-up graph engine:
  296. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  297. TEST_CYCLE()
  298. {
  299. c.apply(in_mat1, out_mat_gapi);
  300. }
  301. // Comparison //////////////////////////////////////////////////////////////
  302. {
  303. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  304. EXPECT_EQ(out_mat_gapi.size(), sz);
  305. }
  306. SANITY_CHECK_NOTHING();
  307. }
  308. //------------------------------------------------------------------------------
  309. PERF_TEST_P_(DilatePerfTest, TestPerformance)
  310. {
  311. compare_f cmpF;
  312. MatType type = 0;
  313. int kernSize = 0, kernType = 0;
  314. cv::Size sz;
  315. cv::GCompileArgs compile_args;
  316. std::tie(cmpF, type, kernSize, sz, kernType, compile_args) = GetParam();
  317. initMatrixRandN(type, sz, type, false);
  318. cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize));
  319. // OpenCV code /////////////////////////////////////////////////////////////
  320. {
  321. cv::dilate(in_mat1, out_mat_ocv, kernel);
  322. }
  323. // G-API code //////////////////////////////////////////////////////////////
  324. cv::GMat in;
  325. auto out = cv::gapi::dilate(in, kernel);
  326. cv::GComputation c(in, out);
  327. // Warm-up graph engine:
  328. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  329. TEST_CYCLE()
  330. {
  331. c.apply(in_mat1, out_mat_gapi);
  332. }
  333. // Comparison //////////////////////////////////////////////////////////////
  334. {
  335. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  336. EXPECT_EQ(out_mat_gapi.size(), sz);
  337. }
  338. SANITY_CHECK_NOTHING();
  339. }
  340. //------------------------------------------------------------------------------
  341. PERF_TEST_P_(Dilate3x3PerfTest, TestPerformance)
  342. {
  343. compare_f cmpF;
  344. MatType type = 0;
  345. int numIters = 0;
  346. cv::Size sz;
  347. cv::GCompileArgs compile_args;
  348. std::tie(cmpF, type, sz, numIters, compile_args) = GetParam();
  349. initMatrixRandN(type, sz, type, false);
  350. cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3, 3));
  351. // OpenCV code /////////////////////////////////////////////////////////////
  352. {
  353. cv::dilate(in_mat1, out_mat_ocv, kernel, cv::Point(-1,-1), numIters);
  354. }
  355. // G-API code //////////////////////////////////////////////////////////////
  356. cv::GMat in;
  357. auto out = cv::gapi::dilate3x3(in, numIters);
  358. cv::GComputation c(in, out);
  359. // Warm-up graph engine:
  360. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  361. TEST_CYCLE()
  362. {
  363. c.apply(in_mat1, out_mat_gapi);
  364. }
  365. // Comparison //////////////////////////////////////////////////////////////
  366. {
  367. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  368. EXPECT_EQ(out_mat_gapi.size(), sz);
  369. }
  370. SANITY_CHECK_NOTHING();
  371. }
  372. //------------------------------------------------------------------------------
  373. PERF_TEST_P_(MorphologyExPerfTest, TestPerformance)
  374. {
  375. compare_f cmpF;
  376. MatType type = 0;
  377. cv::MorphTypes op = cv::MORPH_ERODE;
  378. cv::Size sz;
  379. cv::GCompileArgs compile_args;
  380. std::tie(cmpF, type, sz, op, compile_args) = GetParam();
  381. initMatrixRandN(type, sz, type, false);
  382. cv::MorphShapes defShape = cv::MORPH_RECT;
  383. int defKernSize = 3;
  384. cv::Mat kernel = cv::getStructuringElement(defShape, cv::Size(defKernSize, defKernSize));
  385. // OpenCV code /////////////////////////////////////////////////////////////
  386. {
  387. cv::morphologyEx(in_mat1, out_mat_ocv, op, kernel);
  388. }
  389. // G-API code //////////////////////////////////////////////////////////////
  390. cv::GMat in;
  391. auto out = cv::gapi::morphologyEx(in, op, kernel);
  392. cv::GComputation c(in, out);
  393. // Warm-up graph engine:
  394. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  395. TEST_CYCLE()
  396. {
  397. c.apply(in_mat1, out_mat_gapi);
  398. }
  399. // Comparison //////////////////////////////////////////////////////////////
  400. {
  401. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  402. EXPECT_EQ(out_mat_gapi.size(), sz);
  403. }
  404. SANITY_CHECK_NOTHING();
  405. }
  406. //------------------------------------------------------------------------------
  407. PERF_TEST_P_(SobelPerfTest, TestPerformance)
  408. {
  409. compare_f cmpF;
  410. MatType type = 0;
  411. int kernSize = 0, dtype = 0, dx = 0, dy = 0;
  412. cv::Size sz;
  413. cv::GCompileArgs compile_args;
  414. std::tie(cmpF, type, kernSize, sz, dtype, dx, dy, compile_args) = GetParam();
  415. initMatrixRandN(type, sz, dtype, false);
  416. // OpenCV code /////////////////////////////////////////////////////////////
  417. {
  418. cv::Sobel(in_mat1, out_mat_ocv, dtype, dx, dy, kernSize);
  419. }
  420. // G-API code //////////////////////////////////////////////////////////////
  421. cv::GMat in;
  422. auto out = cv::gapi::Sobel(in, dtype, dx, dy, kernSize);
  423. cv::GComputation c(in, out);
  424. // Warm-up graph engine:
  425. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  426. TEST_CYCLE()
  427. {
  428. c.apply(in_mat1, out_mat_gapi);
  429. }
  430. // Comparison //////////////////////////////////////////////////////////////
  431. {
  432. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  433. EXPECT_EQ(out_mat_gapi.size(), sz);
  434. }
  435. SANITY_CHECK_NOTHING();
  436. }
  437. //------------------------------------------------------------------------------
  438. PERF_TEST_P_(SobelXYPerfTest, TestPerformance)
  439. {
  440. compare_f cmpF;
  441. MatType type = 0;
  442. int kernSize = 0, dtype = 0, order = 0;
  443. cv::Size sz;
  444. cv::GCompileArgs compile_args;
  445. std::tie(cmpF, type, kernSize, sz, dtype, order, compile_args) = GetParam();
  446. cv::Mat out_mat_ocv2;
  447. cv::Mat out_mat_gapi2;
  448. initMatrixRandN(type, sz, dtype, false);
  449. // OpenCV code /////////////////////////////////////////////////////////////
  450. {
  451. cv::Sobel(in_mat1, out_mat_ocv, dtype, order, 0, kernSize);
  452. cv::Sobel(in_mat1, out_mat_ocv2, dtype, 0, order, kernSize);
  453. }
  454. // G-API code //////////////////////////////////////////////////////////////
  455. cv::GMat in;
  456. auto out = cv::gapi::SobelXY(in, dtype, order, kernSize);
  457. cv::GComputation c(cv::GIn(in), cv::GOut(std::get<0>(out), std::get<1>(out)));
  458. // Warm-up graph engine:
  459. c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat_gapi2), std::move(compile_args));
  460. TEST_CYCLE()
  461. {
  462. c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat_gapi2));
  463. }
  464. // Comparison //////////////////////////////////////////////////////////////
  465. {
  466. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  467. EXPECT_TRUE(cmpF(out_mat_gapi2, out_mat_ocv2));
  468. EXPECT_EQ(out_mat_gapi.size(), sz);
  469. EXPECT_EQ(out_mat_gapi2.size(), sz);
  470. }
  471. SANITY_CHECK_NOTHING();
  472. }
  473. //------------------------------------------------------------------------------
  474. PERF_TEST_P_(LaplacianPerfTest, TestPerformance)
  475. {
  476. compare_f cmpF;
  477. MatType type = 0;
  478. int kernSize = 0, dtype = 0;
  479. cv::Size sz;
  480. cv::GCompileArgs compile_args;
  481. std::tie(cmpF, type, kernSize, sz, dtype, compile_args) = GetParam();
  482. initMatrixRandN(type, sz, dtype, false);
  483. // OpenCV code /////////////////////////////////////////////////////////////
  484. {
  485. cv::Laplacian(in_mat1, out_mat_ocv, dtype, kernSize);
  486. }
  487. // G-API code //////////////////////////////////////////////////////////////
  488. cv::GMat in;
  489. auto out = cv::gapi::Laplacian(in, dtype, kernSize);
  490. cv::GComputation c(in, out);
  491. // Warm-up graph engine:
  492. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  493. TEST_CYCLE()
  494. {
  495. c.apply(in_mat1, out_mat_gapi);
  496. }
  497. // Comparison //////////////////////////////////////////////////////////////
  498. {
  499. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  500. EXPECT_EQ(out_mat_gapi.size(), sz);
  501. }
  502. SANITY_CHECK_NOTHING();
  503. }
  504. //------------------------------------------------------------------------------
  505. PERF_TEST_P_(BilateralFilterPerfTest, TestPerformance)
  506. {
  507. compare_f cmpF;
  508. MatType type = 0;
  509. int dtype = 0, d = 0, borderType = BORDER_DEFAULT;
  510. double sigmaColor = 0, sigmaSpace = 0;
  511. cv::Size sz;
  512. cv::GCompileArgs compile_args;
  513. std::tie(cmpF, type, dtype, sz, d, sigmaColor, sigmaSpace,
  514. compile_args) = GetParam();
  515. initMatrixRandN(type, sz, dtype, false);
  516. // OpenCV code /////////////////////////////////////////////////////////////
  517. {
  518. cv::bilateralFilter(in_mat1, out_mat_ocv, d, sigmaColor, sigmaSpace, borderType);
  519. }
  520. // G-API code //////////////////////////////////////////////////////////////
  521. cv::GMat in;
  522. auto out = cv::gapi::bilateralFilter(in, d, sigmaColor, sigmaSpace, borderType);
  523. cv::GComputation c(in, out);
  524. // Warm-up graph engine:
  525. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  526. TEST_CYCLE()
  527. {
  528. c.apply(in_mat1, out_mat_gapi);
  529. }
  530. // Comparison //////////////////////////////////////////////////////////////
  531. {
  532. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  533. EXPECT_EQ(out_mat_gapi.size(), sz);
  534. }
  535. SANITY_CHECK_NOTHING();
  536. }
  537. //------------------------------------------------------------------------------
  538. PERF_TEST_P_(CannyPerfTest, TestPerformance)
  539. {
  540. compare_f cmpF;
  541. MatType type;
  542. int apSize = 0;
  543. double thrLow = 0.0, thrUp = 0.0;
  544. cv::Size sz;
  545. bool l2gr = false;
  546. cv::GCompileArgs compile_args;
  547. std::tie(cmpF, type, sz, thrLow, thrUp, apSize, l2gr, compile_args) = GetParam();
  548. initMatrixRandN(type, sz, CV_8UC1, false);
  549. // OpenCV code /////////////////////////////////////////////////////////////
  550. {
  551. cv::Canny(in_mat1, out_mat_ocv, thrLow, thrUp, apSize, l2gr);
  552. }
  553. // G-API code //////////////////////////////////////////////////////////////
  554. cv::GMat in;
  555. auto out = cv::gapi::Canny(in, thrLow, thrUp, apSize, l2gr);
  556. cv::GComputation c(in, out);
  557. // Warm-up graph engine:
  558. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  559. TEST_CYCLE()
  560. {
  561. c.apply(in_mat1, out_mat_gapi);
  562. }
  563. // Comparison //////////////////////////////////////////////////////////////
  564. {
  565. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  566. EXPECT_EQ(out_mat_gapi.size(), sz);
  567. }
  568. SANITY_CHECK_NOTHING();
  569. }
  570. //------------------------------------------------------------------------------
  571. PERF_TEST_P_(GoodFeaturesPerfTest, TestPerformance)
  572. {
  573. double k = 0.04;
  574. compare_vector_f<cv::Point2f> cmpF;
  575. std::string fileName = "";
  576. int type = -1, maxCorners = -1, blockSize = -1;
  577. double qualityLevel = 0.0, minDistance = 0.0;
  578. bool useHarrisDetector = false;
  579. cv::GCompileArgs compileArgs;
  580. std::tie(cmpF, fileName, type, maxCorners, qualityLevel,
  581. minDistance, blockSize, useHarrisDetector, compileArgs) = GetParam();
  582. initMatFromImage(type, fileName);
  583. std::vector<cv::Point2f> outVecOCV, outVecGAPI;
  584. // OpenCV code /////////////////////////////////////////////////////////////
  585. {
  586. cv::goodFeaturesToTrack(in_mat1, outVecOCV, maxCorners, qualityLevel, minDistance,
  587. cv::noArray(), blockSize, useHarrisDetector, k);
  588. }
  589. // G-API code //////////////////////////////////////////////////////////////
  590. cv::GMat in;
  591. auto out = cv::gapi::goodFeaturesToTrack(in, maxCorners, qualityLevel, minDistance, cv::Mat(),
  592. blockSize, useHarrisDetector, k);
  593. cv::GComputation c(cv::GIn(in), cv::GOut(out));
  594. // Warm-up graph engine:
  595. c.apply(cv::gin(in_mat1), cv::gout(outVecGAPI), std::move(compileArgs));
  596. TEST_CYCLE()
  597. {
  598. c.apply(cv::gin(in_mat1), cv::gout(outVecGAPI));
  599. }
  600. // Comparison //////////////////////////////////////////////////////////////
  601. {
  602. EXPECT_TRUE(cmpF(outVecGAPI, outVecOCV));
  603. }
  604. SANITY_CHECK_NOTHING();
  605. }
  606. //------------------------------------------------------------------------------
  607. PERF_TEST_P_(FindContoursPerfTest, TestPerformance)
  608. {
  609. CompareMats cmpF;
  610. MatType type;
  611. cv::Size sz;
  612. cv::RetrievalModes mode;
  613. cv::ContourApproximationModes method;
  614. cv::GCompileArgs compile_args;
  615. std::tie(cmpF, type, sz, mode, method, compile_args) = GetParam();
  616. cv::Mat in;
  617. initMatForFindingContours(in, sz, type);
  618. cv::Point offset = cv::Point();
  619. std::vector<cv::Vec4i> out_hier_gapi = std::vector<cv::Vec4i>();
  620. std::vector<std::vector<cv::Point>> out_cnts_gapi;
  621. cv::GComputation c(findContoursTestGAPI(in, mode, method, std::move(compile_args),
  622. out_cnts_gapi, out_hier_gapi, offset));
  623. TEST_CYCLE()
  624. {
  625. c.apply(gin(in, offset), gout(out_cnts_gapi));
  626. }
  627. findContoursTestOpenCVCompare(in, mode, method, out_cnts_gapi, out_hier_gapi, cmpF);
  628. SANITY_CHECK_NOTHING();
  629. }
  630. PERF_TEST_P_(FindContoursHPerfTest, TestPerformance)
  631. {
  632. CompareMats cmpF;
  633. MatType type;
  634. cv::Size sz;
  635. cv::RetrievalModes mode;
  636. cv::ContourApproximationModes method;
  637. cv::GCompileArgs compile_args;
  638. std::tie(cmpF, type, sz, mode, method, compile_args) = GetParam();
  639. cv::Mat in;
  640. initMatForFindingContours(in, sz, type);
  641. cv::Point offset = cv::Point();
  642. std::vector<std::vector<cv::Point>> out_cnts_gapi;
  643. std::vector<cv::Vec4i> out_hier_gapi;
  644. cv::GComputation c(findContoursTestGAPI<HIERARCHY>(in, mode, method, std::move(compile_args),
  645. out_cnts_gapi, out_hier_gapi, offset));
  646. TEST_CYCLE()
  647. {
  648. c.apply(gin(in, offset), gout(out_cnts_gapi, out_hier_gapi));
  649. }
  650. findContoursTestOpenCVCompare<HIERARCHY>(in, mode, method, out_cnts_gapi, out_hier_gapi, cmpF);
  651. SANITY_CHECK_NOTHING();
  652. }
  653. //------------------------------------------------------------------------------
  654. PERF_TEST_P_(BoundingRectMatPerfTest, TestPerformance)
  655. {
  656. CompareRects cmpF;
  657. cv::Size sz;
  658. MatType type;
  659. bool initByVector = false;
  660. cv::GCompileArgs compile_args;
  661. std::tie(cmpF, type, sz, initByVector, compile_args) = GetParam();
  662. if (initByVector)
  663. {
  664. initMatByPointsVectorRandU<cv::Point_>(type, sz, -1);
  665. }
  666. else
  667. {
  668. initMatrixRandU(type, sz, -1, false);
  669. }
  670. cv::Rect out_rect_gapi;
  671. cv::GComputation c(boundingRectTestGAPI(in_mat1, std::move(compile_args), out_rect_gapi));
  672. TEST_CYCLE()
  673. {
  674. c.apply(cv::gin(in_mat1), cv::gout(out_rect_gapi));
  675. }
  676. boundingRectTestOpenCVCompare(in_mat1, out_rect_gapi, cmpF);
  677. SANITY_CHECK_NOTHING();
  678. }
  679. PERF_TEST_P_(BoundingRectVector32SPerfTest, TestPerformance)
  680. {
  681. CompareRects cmpF;
  682. cv::Size sz;
  683. cv::GCompileArgs compile_args;
  684. std::tie(cmpF, sz, compile_args) = GetParam();
  685. std::vector<cv::Point2i> in_vector;
  686. initPointsVectorRandU(sz.width, in_vector);
  687. cv::Rect out_rect_gapi;
  688. cv::GComputation c(boundingRectTestGAPI(in_vector, std::move(compile_args), out_rect_gapi));
  689. TEST_CYCLE()
  690. {
  691. c.apply(cv::gin(in_vector), cv::gout(out_rect_gapi));
  692. }
  693. boundingRectTestOpenCVCompare(in_vector, out_rect_gapi, cmpF);
  694. SANITY_CHECK_NOTHING();
  695. }
  696. PERF_TEST_P_(BoundingRectVector32FPerfTest, TestPerformance)
  697. {
  698. CompareRects cmpF;
  699. cv::Size sz;
  700. cv::GCompileArgs compile_args;
  701. std::tie(cmpF, sz, compile_args) = GetParam();
  702. std::vector<cv::Point2f> in_vector;
  703. initPointsVectorRandU(sz.width, in_vector);
  704. cv::Rect out_rect_gapi;
  705. cv::GComputation c(boundingRectTestGAPI(in_vector, std::move(compile_args), out_rect_gapi));
  706. TEST_CYCLE()
  707. {
  708. c.apply(cv::gin(in_vector), cv::gout(out_rect_gapi));
  709. }
  710. boundingRectTestOpenCVCompare(in_vector, out_rect_gapi, cmpF);
  711. SANITY_CHECK_NOTHING();
  712. }
  713. //------------------------------------------------------------------------------
  714. PERF_TEST_P_(FitLine2DMatVectorPerfTest, TestPerformance)
  715. {
  716. CompareVecs<float, 4> cmpF;
  717. cv::Size sz;
  718. MatType type;
  719. cv::DistanceTypes distType;
  720. cv::GCompileArgs compile_args;
  721. std::tie(cmpF, type, sz, distType, compile_args) = GetParam();
  722. initMatByPointsVectorRandU<cv::Point_>(type, sz, -1);
  723. cv::Vec4f out_vec_gapi;
  724. cv::GComputation c(fitLineTestGAPI(in_mat1, distType, std::move(compile_args), out_vec_gapi));
  725. TEST_CYCLE()
  726. {
  727. c.apply(cv::gin(in_mat1), cv::gout(out_vec_gapi));
  728. }
  729. fitLineTestOpenCVCompare(in_mat1, distType, out_vec_gapi, cmpF);
  730. SANITY_CHECK_NOTHING();
  731. }
  732. PERF_TEST_P_(FitLine2DVector32SPerfTest, TestPerformance)
  733. {
  734. CompareVecs<float, 4> cmpF;
  735. cv::Size sz;
  736. cv::DistanceTypes distType;
  737. cv::GCompileArgs compile_args;
  738. std::tie(cmpF, sz, distType, compile_args) = GetParam();
  739. std::vector<cv::Point2i> in_vector;
  740. initPointsVectorRandU(sz.width, in_vector);
  741. cv::Vec4f out_vec_gapi;
  742. cv::GComputation c(fitLineTestGAPI(in_vector, distType, std::move(compile_args),
  743. out_vec_gapi));
  744. TEST_CYCLE()
  745. {
  746. c.apply(cv::gin(in_vector), cv::gout(out_vec_gapi));
  747. }
  748. fitLineTestOpenCVCompare(in_vector, distType, out_vec_gapi, cmpF);
  749. SANITY_CHECK_NOTHING();
  750. }
  751. PERF_TEST_P_(FitLine2DVector32FPerfTest, TestPerformance)
  752. {
  753. CompareVecs<float, 4> cmpF;
  754. cv::Size sz;
  755. cv::DistanceTypes distType;
  756. cv::GCompileArgs compile_args;
  757. std::tie(cmpF, sz, distType, compile_args) = GetParam();
  758. std::vector<cv::Point2f> in_vector;
  759. initPointsVectorRandU(sz.width, in_vector);
  760. cv::Vec4f out_vec_gapi;
  761. cv::GComputation c(fitLineTestGAPI(in_vector, distType, std::move(compile_args),
  762. out_vec_gapi));
  763. TEST_CYCLE()
  764. {
  765. c.apply(cv::gin(in_vector), cv::gout(out_vec_gapi));
  766. }
  767. fitLineTestOpenCVCompare(in_vector, distType, out_vec_gapi, cmpF);
  768. SANITY_CHECK_NOTHING();
  769. }
  770. PERF_TEST_P_(FitLine2DVector64FPerfTest, TestPerformance)
  771. {
  772. CompareVecs<float, 4> cmpF;
  773. cv::Size sz;
  774. cv::DistanceTypes distType;
  775. cv::GCompileArgs compile_args;
  776. std::tie(cmpF, sz, distType, compile_args) = GetParam();
  777. std::vector<cv::Point2d> in_vector;
  778. initPointsVectorRandU(sz.width, in_vector);
  779. cv::Vec4f out_vec_gapi;
  780. cv::GComputation c(fitLineTestGAPI(in_vector, distType, std::move(compile_args),
  781. out_vec_gapi));
  782. TEST_CYCLE()
  783. {
  784. c.apply(cv::gin(in_vector), cv::gout(out_vec_gapi));
  785. }
  786. fitLineTestOpenCVCompare(in_vector, distType, out_vec_gapi, cmpF);
  787. SANITY_CHECK_NOTHING();
  788. }
  789. PERF_TEST_P_(FitLine3DMatVectorPerfTest, TestPerformance)
  790. {
  791. CompareVecs<float, 6> cmpF;
  792. cv::Size sz;
  793. MatType type;
  794. cv::DistanceTypes distType;
  795. cv::GCompileArgs compile_args;
  796. std::tie(cmpF, type, sz, distType, compile_args) = GetParam();
  797. initMatByPointsVectorRandU<cv::Point3_>(type, sz, -1);
  798. cv::Vec6f out_vec_gapi;
  799. cv::GComputation c(fitLineTestGAPI(in_mat1, distType, std::move(compile_args), out_vec_gapi));
  800. TEST_CYCLE()
  801. {
  802. c.apply(cv::gin(in_mat1), cv::gout(out_vec_gapi));
  803. }
  804. fitLineTestOpenCVCompare(in_mat1, distType, out_vec_gapi, cmpF);
  805. SANITY_CHECK_NOTHING();
  806. }
  807. PERF_TEST_P_(FitLine3DVector32SPerfTest, TestPerformance)
  808. {
  809. CompareVecs<float, 6> cmpF;
  810. cv::Size sz;
  811. cv::DistanceTypes distType;
  812. cv::GCompileArgs compile_args;
  813. std::tie(cmpF, sz, distType, compile_args) = GetParam();
  814. std::vector<cv::Point3i> in_vector;
  815. initPointsVectorRandU(sz.width, in_vector);
  816. cv::Vec6f out_vec_gapi;
  817. cv::GComputation c(fitLineTestGAPI(in_vector, distType, std::move(compile_args),
  818. out_vec_gapi));
  819. TEST_CYCLE()
  820. {
  821. c.apply(cv::gin(in_vector), cv::gout(out_vec_gapi));
  822. }
  823. fitLineTestOpenCVCompare(in_vector, distType, out_vec_gapi, cmpF);
  824. SANITY_CHECK_NOTHING();
  825. }
  826. PERF_TEST_P_(FitLine3DVector32FPerfTest, TestPerformance)
  827. {
  828. CompareVecs<float, 6> cmpF;
  829. cv::Size sz;
  830. cv::DistanceTypes distType;
  831. cv::GCompileArgs compile_args;
  832. std::tie(cmpF, sz, distType, compile_args) = GetParam();
  833. std::vector<cv::Point3f> in_vector;
  834. initPointsVectorRandU(sz.width, in_vector);
  835. cv::Vec6f out_vec_gapi;
  836. cv::GComputation c(fitLineTestGAPI(in_vector, distType, std::move(compile_args),
  837. out_vec_gapi));
  838. TEST_CYCLE()
  839. {
  840. c.apply(cv::gin(in_vector), cv::gout(out_vec_gapi));
  841. }
  842. fitLineTestOpenCVCompare(in_vector, distType, out_vec_gapi, cmpF);
  843. SANITY_CHECK_NOTHING();
  844. }
  845. PERF_TEST_P_(FitLine3DVector64FPerfTest, TestPerformance)
  846. {
  847. CompareVecs<float, 6> cmpF;
  848. cv::Size sz;
  849. cv::DistanceTypes distType;
  850. cv::GCompileArgs compile_args;
  851. std::tie(cmpF, sz, distType, compile_args) = GetParam();
  852. std::vector<cv::Point3d> in_vector;
  853. initPointsVectorRandU(sz.width, in_vector);
  854. cv::Vec6f out_vec_gapi;
  855. cv::GComputation c(fitLineTestGAPI(in_vector, distType, std::move(compile_args),
  856. out_vec_gapi));
  857. TEST_CYCLE()
  858. {
  859. c.apply(cv::gin(in_vector), cv::gout(out_vec_gapi));
  860. }
  861. fitLineTestOpenCVCompare(in_vector, distType, out_vec_gapi, cmpF);
  862. SANITY_CHECK_NOTHING();
  863. }
  864. //------------------------------------------------------------------------------
  865. PERF_TEST_P_(EqHistPerfTest, TestPerformance)
  866. {
  867. compare_f cmpF = get<0>(GetParam());
  868. Size sz = get<1>(GetParam());
  869. cv::GCompileArgs compile_args = get<2>(GetParam());
  870. initMatrixRandN(CV_8UC1, sz, CV_8UC1, false);
  871. // OpenCV code /////////////////////////////////////////////////////////////
  872. {
  873. cv::equalizeHist(in_mat1, out_mat_ocv);
  874. }
  875. // G-API code //////////////////////////////////////////////////////////////
  876. cv::GMat in;
  877. auto out = cv::gapi::equalizeHist(in);
  878. cv::GComputation c(in, out);
  879. // Warm-up graph engine:
  880. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  881. TEST_CYCLE()
  882. {
  883. c.apply(in_mat1, out_mat_gapi);
  884. }
  885. // Comparison //////////////////////////////////////////////////////////////
  886. {
  887. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  888. EXPECT_EQ(out_mat_gapi.size(), sz);
  889. }
  890. SANITY_CHECK_NOTHING();
  891. }
  892. //------------------------------------------------------------------------------
  893. PERF_TEST_P_(BGR2RGBPerfTest, TestPerformance)
  894. {
  895. compare_f cmpF;
  896. cv::Size sz;
  897. cv::GCompileArgs compile_args;
  898. std::tie(cmpF, sz, compile_args) = GetParam();
  899. initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
  900. // OpenCV code /////////////////////////////////////////////////////////////
  901. {
  902. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2RGB);
  903. }
  904. // G-API code //////////////////////////////////////////////////////////////
  905. cv::GMat in;
  906. auto out = cv::gapi::BGR2RGB(in);
  907. cv::GComputation c(in, out);
  908. // Warm-up graph engine:
  909. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  910. TEST_CYCLE()
  911. {
  912. c.apply(in_mat1, out_mat_gapi);
  913. }
  914. // Comparison //////////////////////////////////////////////////////////////
  915. {
  916. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  917. EXPECT_EQ(out_mat_gapi.size(), sz);
  918. }
  919. SANITY_CHECK_NOTHING();
  920. }
  921. //------------------------------------------------------------------------------
  922. PERF_TEST_P_(RGB2GrayPerfTest, TestPerformance)
  923. {
  924. compare_f cmpF = get<0>(GetParam());
  925. Size sz = get<1>(GetParam());
  926. cv::GCompileArgs compile_args = get<2>(GetParam());
  927. initMatrixRandN(CV_8UC3, sz, CV_8UC1, false);
  928. // OpenCV code /////////////////////////////////////////////////////////////
  929. {
  930. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2GRAY);
  931. }
  932. // G-API code //////////////////////////////////////////////////////////////
  933. cv::GMat in;
  934. auto out = cv::gapi::RGB2Gray(in);
  935. cv::GComputation c(in, out);
  936. // Warm-up graph engine:
  937. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  938. TEST_CYCLE()
  939. {
  940. c.apply(in_mat1, out_mat_gapi);
  941. }
  942. // Comparison //////////////////////////////////////////////////////////////
  943. {
  944. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  945. EXPECT_EQ(out_mat_gapi.size(), sz);
  946. }
  947. SANITY_CHECK_NOTHING();
  948. }
  949. //------------------------------------------------------------------------------
  950. PERF_TEST_P_(BGR2GrayPerfTest, TestPerformance)
  951. {
  952. compare_f cmpF = get<0>(GetParam());
  953. Size sz = get<1>(GetParam());
  954. cv::GCompileArgs compile_args = get<2>(GetParam());
  955. initMatrixRandN(CV_8UC3, sz, CV_8UC1, false);
  956. // OpenCV code /////////////////////////////////////////////////////////////
  957. {
  958. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2GRAY);
  959. }
  960. // G-API code //////////////////////////////////////////////////////////////
  961. cv::GMat in;
  962. auto out = cv::gapi::BGR2Gray(in);
  963. cv::GComputation c(in, out);
  964. // Warm-up graph engine:
  965. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  966. TEST_CYCLE()
  967. {
  968. c.apply(in_mat1, out_mat_gapi);
  969. }
  970. // Comparison //////////////////////////////////////////////////////////////
  971. {
  972. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  973. EXPECT_EQ(out_mat_gapi.size(), sz);
  974. }
  975. SANITY_CHECK_NOTHING();
  976. }
  977. //------------------------------------------------------------------------------
  978. PERF_TEST_P_(RGB2YUVPerfTest, TestPerformance)
  979. {
  980. compare_f cmpF = get<0>(GetParam());
  981. Size sz = get<1>(GetParam());
  982. cv::GCompileArgs compile_args = get<2>(GetParam());
  983. initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
  984. // OpenCV code /////////////////////////////////////////////////////////////
  985. {
  986. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2YUV);
  987. }
  988. // G-API code //////////////////////////////////////////////////////////////
  989. cv::GMat in;
  990. auto out = cv::gapi::RGB2YUV(in);
  991. cv::GComputation c(in, out);
  992. // Warm-up graph engine:
  993. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  994. TEST_CYCLE()
  995. {
  996. c.apply(in_mat1, out_mat_gapi);
  997. }
  998. // Comparison //////////////////////////////////////////////////////////////
  999. {
  1000. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  1001. EXPECT_EQ(out_mat_gapi.size(), sz);
  1002. }
  1003. SANITY_CHECK_NOTHING();
  1004. }
  1005. //------------------------------------------------------------------------------
  1006. PERF_TEST_P_(YUV2RGBPerfTest, TestPerformance)
  1007. {
  1008. compare_f cmpF = get<0>(GetParam());
  1009. Size sz = get<1>(GetParam());
  1010. cv::GCompileArgs compile_args = get<2>(GetParam());
  1011. initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
  1012. // OpenCV code /////////////////////////////////////////////////////////////
  1013. {
  1014. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2RGB);
  1015. }
  1016. // G-API code //////////////////////////////////////////////////////////////
  1017. cv::GMat in;
  1018. auto out = cv::gapi::YUV2RGB(in);
  1019. cv::GComputation c(in, out);
  1020. // Warm-up graph engine:
  1021. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  1022. TEST_CYCLE()
  1023. {
  1024. c.apply(in_mat1, out_mat_gapi);
  1025. }
  1026. // Comparison //////////////////////////////////////////////////////////////
  1027. {
  1028. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  1029. EXPECT_EQ(out_mat_gapi.size(), sz);
  1030. }
  1031. SANITY_CHECK_NOTHING();
  1032. }
  1033. //------------------------------------------------------------------------------
  1034. PERF_TEST_P_(BGR2I420PerfTest, TestPerformance)
  1035. {
  1036. compare_f cmpF;
  1037. cv::Size sz;
  1038. cv::GCompileArgs compile_args;
  1039. std::tie(cmpF, sz, compile_args) = GetParam();
  1040. initMatrixRandN(CV_8UC3, sz, CV_8UC1, false);
  1041. // OpenCV code /////////////////////////////////////////////////////////////
  1042. {
  1043. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2YUV_I420);
  1044. }
  1045. // G-API code //////////////////////////////////////////////////////////////
  1046. cv::GMat in;
  1047. auto out = cv::gapi::BGR2I420(in);
  1048. cv::GComputation c(in, out);
  1049. // Warm-up graph engine:
  1050. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  1051. TEST_CYCLE()
  1052. {
  1053. c.apply(in_mat1, out_mat_gapi);
  1054. }
  1055. // Comparison //////////////////////////////////////////////////////////////
  1056. {
  1057. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  1058. EXPECT_EQ(out_mat_gapi.size(), Size(sz.width, sz.height * 3 / 2));
  1059. }
  1060. SANITY_CHECK_NOTHING();
  1061. }
  1062. //------------------------------------------------------------------------------
  1063. PERF_TEST_P_(RGB2I420PerfTest, TestPerformance)
  1064. {
  1065. compare_f cmpF;
  1066. cv::Size sz;
  1067. cv::GCompileArgs compile_args;
  1068. std::tie(cmpF, sz, compile_args) = GetParam();
  1069. initMatrixRandN(CV_8UC3, sz, CV_8UC1, false);
  1070. // OpenCV code /////////////////////////////////////////////////////////////
  1071. {
  1072. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2YUV_I420);
  1073. }
  1074. // G-API code //////////////////////////////////////////////////////////////
  1075. cv::GMat in;
  1076. auto out = cv::gapi::RGB2I420(in);
  1077. cv::GComputation c(in, out);
  1078. // Warm-up graph engine:
  1079. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  1080. TEST_CYCLE()
  1081. {
  1082. c.apply(in_mat1, out_mat_gapi);
  1083. }
  1084. // Comparison //////////////////////////////////////////////////////////////
  1085. {
  1086. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  1087. EXPECT_EQ(out_mat_gapi.size(), Size(sz.width, sz.height * 3 / 2));
  1088. }
  1089. SANITY_CHECK_NOTHING();
  1090. }
  1091. //------------------------------------------------------------------------------
  1092. PERF_TEST_P_(I4202BGRPerfTest, TestPerformance)
  1093. {
  1094. compare_f cmpF;
  1095. cv::Size sz;
  1096. cv::GCompileArgs compile_args;
  1097. std::tie(cmpF, sz, compile_args) = GetParam();
  1098. initMatrixRandN(CV_8UC1, sz, CV_8UC3, false);
  1099. // OpenCV code /////////////////////////////////////////////////////////////
  1100. {
  1101. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2BGR_I420);
  1102. }
  1103. // G-API code //////////////////////////////////////////////////////////////
  1104. cv::GMat in;
  1105. auto out = cv::gapi::I4202BGR(in);
  1106. cv::GComputation c(in, out);
  1107. // Warm-up graph engine:
  1108. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  1109. TEST_CYCLE()
  1110. {
  1111. c.apply(in_mat1, out_mat_gapi);
  1112. }
  1113. // Comparison //////////////////////////////////////////////////////////////
  1114. {
  1115. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  1116. EXPECT_EQ(out_mat_gapi.size(), Size(sz.width, sz.height * 2 / 3));
  1117. }
  1118. SANITY_CHECK_NOTHING();
  1119. }
  1120. //------------------------------------------------------------------------------
  1121. PERF_TEST_P_(I4202RGBPerfTest, TestPerformance)
  1122. {
  1123. compare_f cmpF;
  1124. cv::Size sz;
  1125. cv::GCompileArgs compile_args;
  1126. std::tie(cmpF, sz, compile_args) = GetParam();
  1127. initMatrixRandN(CV_8UC1, sz, CV_8UC3, false);
  1128. // OpenCV code /////////////////////////////////////////////////////////////
  1129. {
  1130. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2RGB_I420);
  1131. }
  1132. // G-API code //////////////////////////////////////////////////////////////
  1133. cv::GMat in;
  1134. auto out = cv::gapi::I4202RGB(in);
  1135. cv::GComputation c(in, out);
  1136. // Warm-up graph engine:
  1137. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  1138. TEST_CYCLE()
  1139. {
  1140. c.apply(in_mat1, out_mat_gapi);
  1141. }
  1142. // Comparison //////////////////////////////////////////////////////////////
  1143. {
  1144. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  1145. EXPECT_EQ(out_mat_gapi.size(), Size(sz.width, sz.height * 2 / 3));
  1146. }
  1147. SANITY_CHECK_NOTHING();
  1148. }
  1149. //------------------------------------------------------------------------------
  1150. PERF_TEST_P_(RGB2LabPerfTest, TestPerformance)
  1151. {
  1152. compare_f cmpF = get<0>(GetParam());
  1153. Size sz = get<1>(GetParam());
  1154. cv::GCompileArgs compile_args = get<2>(GetParam());
  1155. initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
  1156. // OpenCV code /////////////////////////////////////////////////////////////
  1157. {
  1158. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2Lab);
  1159. }
  1160. // G-API code //////////////////////////////////////////////////////////////
  1161. cv::GMat in;
  1162. auto out = cv::gapi::RGB2Lab(in);
  1163. cv::GComputation c(in, out);
  1164. // Warm-up graph engine:
  1165. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  1166. TEST_CYCLE()
  1167. {
  1168. c.apply(in_mat1, out_mat_gapi);
  1169. }
  1170. // Comparison //////////////////////////////////////////////////////////////
  1171. {
  1172. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  1173. EXPECT_EQ(out_mat_gapi.size(), sz);
  1174. }
  1175. SANITY_CHECK_NOTHING();
  1176. }
  1177. //------------------------------------------------------------------------------
  1178. PERF_TEST_P_(BGR2LUVPerfTest, TestPerformance)
  1179. {
  1180. compare_f cmpF = get<0>(GetParam());
  1181. Size sz = get<1>(GetParam());
  1182. cv::GCompileArgs compile_args = get<2>(GetParam());
  1183. initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
  1184. // OpenCV code /////////////////////////////////////////////////////////////
  1185. {
  1186. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2Luv);
  1187. }
  1188. // G-API code //////////////////////////////////////////////////////////////
  1189. cv::GMat in;
  1190. auto out = cv::gapi::BGR2LUV(in);
  1191. cv::GComputation c(in, out);
  1192. // Warm-up graph engine:
  1193. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  1194. TEST_CYCLE()
  1195. {
  1196. c.apply(in_mat1, out_mat_gapi);
  1197. }
  1198. // Comparison //////////////////////////////////////////////////////////////
  1199. {
  1200. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  1201. EXPECT_EQ(out_mat_gapi.size(), sz);
  1202. }
  1203. SANITY_CHECK_NOTHING();
  1204. }
  1205. //------------------------------------------------------------------------------
  1206. PERF_TEST_P_(LUV2BGRPerfTest, TestPerformance)
  1207. {
  1208. compare_f cmpF = get<0>(GetParam());
  1209. Size sz = get<1>(GetParam());
  1210. cv::GCompileArgs compile_args = get<2>(GetParam());
  1211. initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
  1212. // OpenCV code /////////////////////////////////////////////////////////////
  1213. {
  1214. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_Luv2BGR);
  1215. }
  1216. // G-API code //////////////////////////////////////////////////////////////
  1217. cv::GMat in;
  1218. auto out = cv::gapi::LUV2BGR(in);
  1219. cv::GComputation c(in, out);
  1220. // Warm-up graph engine:
  1221. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  1222. TEST_CYCLE()
  1223. {
  1224. c.apply(in_mat1, out_mat_gapi);
  1225. }
  1226. // Comparison //////////////////////////////////////////////////////////////
  1227. {
  1228. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  1229. EXPECT_EQ(out_mat_gapi.size(), sz);
  1230. }
  1231. SANITY_CHECK_NOTHING();
  1232. }
  1233. //------------------------------------------------------------------------------
  1234. PERF_TEST_P_(BGR2YUVPerfTest, TestPerformance)
  1235. {
  1236. compare_f cmpF = get<0>(GetParam());
  1237. Size sz = get<1>(GetParam());
  1238. cv::GCompileArgs compile_args = get<2>(GetParam());
  1239. initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
  1240. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2YUV);
  1241. cv::GMat in;
  1242. auto out = cv::gapi::BGR2YUV(in);
  1243. cv::GComputation c(in, out);
  1244. // Warm-up graph engine:
  1245. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  1246. TEST_CYCLE()
  1247. {
  1248. c.apply(in_mat1, out_mat_gapi);
  1249. }
  1250. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  1251. EXPECT_EQ(out_mat_gapi.size(), sz);
  1252. SANITY_CHECK_NOTHING();
  1253. }
  1254. //------------------------------------------------------------------------------
  1255. PERF_TEST_P_(YUV2BGRPerfTest, TestPerformance)
  1256. {
  1257. compare_f cmpF = get<0>(GetParam());
  1258. Size sz = get<1>(GetParam());
  1259. cv::GCompileArgs compile_args = get<2>(GetParam());
  1260. initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
  1261. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2BGR);
  1262. cv::GMat in;
  1263. auto out = cv::gapi::YUV2BGR(in);
  1264. cv::GComputation c(in, out);
  1265. // Warm-up graph engine:
  1266. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  1267. TEST_CYCLE()
  1268. {
  1269. c.apply(in_mat1, out_mat_gapi);
  1270. }
  1271. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  1272. EXPECT_EQ(out_mat_gapi.size(), sz);
  1273. SANITY_CHECK_NOTHING();
  1274. }
  1275. PERF_TEST_P_(BayerGR2RGBPerfTest, TestPerformance)
  1276. {
  1277. compare_f cmpF = get<0>(GetParam());
  1278. Size sz = get<1>(GetParam());
  1279. cv::GCompileArgs compile_args = get<2>(GetParam());
  1280. initMatrixRandN(CV_8UC1, sz, CV_8UC3, false);
  1281. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BayerGR2RGB);
  1282. cv::GMat in;
  1283. auto out = cv::gapi::BayerGR2RGB(in);
  1284. cv::GComputation c(in, out);
  1285. // Warm-up graph engine:
  1286. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  1287. TEST_CYCLE()
  1288. {
  1289. c.apply(in_mat1, out_mat_gapi);
  1290. }
  1291. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  1292. EXPECT_EQ(out_mat_gapi.size(), sz);
  1293. SANITY_CHECK_NOTHING();
  1294. }
  1295. PERF_TEST_P_(RGB2HSVPerfTest, TestPerformance)
  1296. {
  1297. compare_f cmpF = get<0>(GetParam());
  1298. Size sz = get<1>(GetParam());
  1299. cv::GCompileArgs compile_args = get<2>(GetParam());
  1300. initMatrixRandN(CV_8UC3, sz, CV_8UC3, false);
  1301. cv::cvtColor(in_mat1, in_mat1, cv::COLOR_BGR2RGB);
  1302. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2HSV);
  1303. cv::GMat in;
  1304. auto out = cv::gapi::RGB2HSV(in);
  1305. cv::GComputation c(in, out);
  1306. // Warm-up graph engine:
  1307. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  1308. TEST_CYCLE()
  1309. {
  1310. c.apply(in_mat1, out_mat_gapi);
  1311. }
  1312. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  1313. EXPECT_EQ(out_mat_gapi.size(), sz);
  1314. SANITY_CHECK_NOTHING();
  1315. }
  1316. PERF_TEST_P_(RGB2YUV422PerfTest, TestPerformance)
  1317. {
  1318. compare_f cmpF = get<0>(GetParam());
  1319. Size sz = get<1>(GetParam());
  1320. cv::GCompileArgs compile_args = get<2>(GetParam());
  1321. initMatrixRandN(CV_8UC3, sz, CV_8UC2, false);
  1322. cv::cvtColor(in_mat1, in_mat1, cv::COLOR_BGR2RGB);
  1323. convertRGB2YUV422Ref(in_mat1, out_mat_ocv);
  1324. cv::GMat in;
  1325. auto out = cv::gapi::RGB2YUV422(in);
  1326. cv::GComputation c(in, out);
  1327. // Warm-up graph engine:
  1328. c.apply(in_mat1, out_mat_gapi, std::move(compile_args));
  1329. TEST_CYCLE()
  1330. {
  1331. c.apply(in_mat1, out_mat_gapi);
  1332. }
  1333. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  1334. EXPECT_EQ(out_mat_gapi.size(), sz);
  1335. SANITY_CHECK_NOTHING();
  1336. }
  1337. //------------------------------------------------------------------------------
  1338. PERF_TEST_P_(ResizePerfTest, TestPerformance)
  1339. {
  1340. compare_f cmpF;
  1341. MatType type = -1;
  1342. int interp = 1;
  1343. cv::Size sz;
  1344. cv::Size sz_out;
  1345. cv::GCompileArgs compile_args;
  1346. std::tie(cmpF, type, interp, sz, sz_out, compile_args) = GetParam();
  1347. in_mat1 = cv::Mat(sz, type);
  1348. cv::Scalar mean = cv::Scalar::all(127);
  1349. cv::Scalar stddev = cv::Scalar::all(40.f);
  1350. cv::randn(in_mat1, mean, stddev);
  1351. out_mat_gapi = cv::Mat(sz_out, type);
  1352. out_mat_ocv = cv::Mat(sz_out, type);
  1353. // OpenCV code ///////////////////////////////////////////////////////////
  1354. cv::resize(in_mat1, out_mat_ocv, sz_out, 0.0, 0.0, interp);
  1355. // G-API code //////////////////////////////////////////////////////////////
  1356. cv::GMat in;
  1357. auto out = cv::gapi::resize(in, sz_out, 0.0, 0.0, interp);
  1358. cv::GComputation c(in, out);
  1359. // Warm-up graph engine:
  1360. auto cc = c.compile(descr_of(gin(in_mat1)),
  1361. std::move(compile_args));
  1362. cc(gin(in_mat1), gout(out_mat_gapi));
  1363. TEST_CYCLE()
  1364. {
  1365. cc(gin(in_mat1), gout(out_mat_gapi));
  1366. }
  1367. // Comparison ////////////////////////////////////////////////////////////
  1368. {
  1369. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  1370. }
  1371. SANITY_CHECK_NOTHING();
  1372. }
  1373. //------------------------------------------------------------------------------
  1374. PERF_TEST_P_(ResizeFxFyPerfTest, TestPerformance)
  1375. {
  1376. compare_f cmpF;
  1377. MatType type = -1;
  1378. int interp = 1;
  1379. cv::Size sz;
  1380. double fx = 1.0;
  1381. double fy = 1.0;
  1382. cv::GCompileArgs compile_args;
  1383. std::tie(cmpF, type, interp, sz, fx, fy, compile_args) = GetParam();
  1384. in_mat1 = cv::Mat(sz, type);
  1385. cv::Scalar mean = cv::Scalar::all(127);
  1386. cv::Scalar stddev = cv::Scalar::all(40.f);
  1387. cv::randn(in_mat1, mean, stddev);
  1388. cv::Size sz_out = cv:: Size(saturate_cast<int>(sz.width*fx), saturate_cast<int>(sz.height*fy));
  1389. out_mat_gapi = cv::Mat(sz_out, type);
  1390. out_mat_ocv = cv::Mat(sz_out, type);
  1391. // OpenCV code ///////////////////////////////////////////////////////////
  1392. cv::resize(in_mat1, out_mat_ocv, sz_out, fx, fy, interp);
  1393. // G-API code //////////////////////////////////////////////////////////////
  1394. cv::GMat in;
  1395. auto out = cv::gapi::resize(in, sz_out, fx, fy, interp);
  1396. cv::GComputation c(in, out);
  1397. // Warm-up graph engine:
  1398. auto cc = c.compile(descr_of(gin(in_mat1)),
  1399. std::move(compile_args));
  1400. cc(gin(in_mat1), gout(out_mat_gapi));
  1401. TEST_CYCLE()
  1402. {
  1403. cc(gin(in_mat1), gout(out_mat_gapi));
  1404. }
  1405. // Comparison ////////////////////////////////////////////////////////////
  1406. {
  1407. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  1408. }
  1409. SANITY_CHECK_NOTHING();
  1410. }
  1411. //------------------------------------------------------------------------------
  1412. PERF_TEST_P_(ResizeInSimpleGraphPerfTest, TestPerformance)
  1413. {
  1414. compare_f cmpF;
  1415. MatType type = -1;
  1416. cv::Size sz;
  1417. double fx = 0.5;
  1418. double fy = 0.5;
  1419. cv::GCompileArgs compile_args;
  1420. std::tie(cmpF, type, sz, fx, fy, compile_args) = GetParam();
  1421. initMatsRandU(type, sz, type, false);
  1422. cv::Mat add_res_ocv;
  1423. cv::add(in_mat1, in_mat2, add_res_ocv);
  1424. cv::resize(add_res_ocv, out_mat_ocv, cv::Size(), fx, fy);
  1425. cv::GMat in1, in2;
  1426. cv::GMat add_res_gapi = cv::gapi::add(in1, in2);
  1427. cv::GMat out = cv::gapi::resize(add_res_gapi, cv::Size(), fx, fy, INTER_LINEAR);
  1428. cv::GComputation ac(GIn(in1, in2), GOut(out));
  1429. auto cc = ac.compile(descr_of(gin(in_mat1, in_mat2)),
  1430. std::move(compile_args));
  1431. cc(gin(in_mat1, in_mat2), gout(out_mat_gapi));
  1432. TEST_CYCLE()
  1433. {
  1434. cc(gin(in_mat1, in_mat2), gout(out_mat_gapi));
  1435. }
  1436. // Comparison ////////////////////////////////////////////////////////////
  1437. {
  1438. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  1439. }
  1440. SANITY_CHECK_NOTHING();
  1441. }
  1442. //------------------------------------------------------------------------------
  1443. // This test cases were created to control performance result of test scenario mentioned here:
  1444. // https://stackoverflow.com/questions/60629331/opencv-gapi-performance-not-good-as-expected
  1445. PERF_TEST_P_(BottleneckKernelsConstInputPerfTest, TestPerformance)
  1446. {
  1447. compare_f cmpF;
  1448. std::string fileName = "";
  1449. cv::GCompileArgs compile_args;
  1450. double fx = 0.5;
  1451. double fy = 0.5;
  1452. std::tie(cmpF, fileName, compile_args) = GetParam();
  1453. in_mat1 = cv::imread(findDataFile(fileName));
  1454. cv::Mat cvvga;
  1455. cv::Mat cvgray;
  1456. cv::Mat cvblurred;
  1457. cv::resize(in_mat1, cvvga, cv::Size(), fx, fy);
  1458. cv::cvtColor(cvvga, cvgray, cv::COLOR_BGR2GRAY);
  1459. cv::blur(cvgray, cvblurred, cv::Size(3, 3));
  1460. cv::Canny(cvblurred, out_mat_ocv, 32, 128, 3);
  1461. cv::GMat in;
  1462. cv::GMat vga = cv::gapi::resize(in, cv::Size(), fx, fy, INTER_LINEAR);
  1463. cv::GMat gray = cv::gapi::BGR2Gray(vga);
  1464. cv::GMat blurred = cv::gapi::blur(gray, cv::Size(3, 3));
  1465. cv::GMat out = cv::gapi::Canny(blurred, 32, 128, 3);
  1466. cv::GComputation ac(in, out);
  1467. auto cc = ac.compile(descr_of(gin(in_mat1)),
  1468. std::move(compile_args));
  1469. cc(gin(in_mat1), gout(out_mat_gapi));
  1470. TEST_CYCLE()
  1471. {
  1472. cc(gin(in_mat1), gout(out_mat_gapi));
  1473. }
  1474. // Comparison ////////////////////////////////////////////////////////////
  1475. {
  1476. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  1477. }
  1478. SANITY_CHECK_NOTHING();
  1479. }
  1480. //------------------------------------------------------------------------------
  1481. }
  1482. #endif //OPENCV_GAPI_IMGPROC_PERF_TESTS_INL_HPP