gapi_render_perf_tests_inl.hpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  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) 2020 Intel Corporation
  6. #include "gapi_render_perf_tests.hpp"
  7. namespace opencv_test
  8. {
  9. namespace {
  10. void create_rand_mats(const cv::Size &size, MatType type, cv::Mat &ref_mat, cv::Mat &gapi_mat)
  11. {
  12. ref_mat.create(size, type);
  13. cv::randu(ref_mat, cv::Scalar::all(0), cv::Scalar::all(255));
  14. ref_mat.copyTo(gapi_mat);
  15. };
  16. } // namespace
  17. PERF_TEST_P_(RenderTestFTexts, RenderFTextsPerformanceBGROCVTest)
  18. {
  19. std::wstring text;
  20. cv::Size sz;
  21. cv::Point org;
  22. int fh = 0;
  23. cv::Scalar color;
  24. cv::GCompileArgs comp_args;
  25. std::tie(text ,sz ,org ,fh ,color, comp_args) = GetParam();
  26. MatType type = CV_8UC3;
  27. cv::Mat gapi_mat, ref_mat;
  28. create_rand_mats(sz, type, ref_mat, gapi_mat);
  29. // G-API code //////////////////////////////////////////////////////////////
  30. cv::gapi::wip::draw::Prims prims;
  31. prims.emplace_back(cv::gapi::wip::draw::FText{text, org, fh, color});
  32. cv::GMat in;
  33. cv::GArray<cv::gapi::wip::draw::Prim> arr;
  34. cv::GComputation comp(cv::GIn(in, arr),
  35. cv::GOut(cv::gapi::wip::draw::render3ch(in, arr)));
  36. // Warm-up graph engine:
  37. comp.apply(gin(gapi_mat, prims), gout(gapi_mat), std::move(comp_args));
  38. TEST_CYCLE()
  39. {
  40. comp.apply(gin(gapi_mat, prims), gout(gapi_mat));
  41. }
  42. SANITY_CHECK_NOTHING();
  43. }
  44. PERF_TEST_P_(RenderTestFTexts, RenderFTextsPerformanceNV12OCVTest)
  45. {
  46. std::wstring text;
  47. cv::Size sz;
  48. cv::Point org;
  49. int fh = 0;
  50. cv::Scalar color;
  51. cv::GCompileArgs comp_args;
  52. std::tie(text ,sz ,org ,fh ,color, comp_args) = GetParam();
  53. cv::Mat y_ref_mat, uv_ref_mat;
  54. cv::Mat y_in_gapi_mat, uv_in_gapi_mat,
  55. y_out_gapi_mat, uv_out_gapi_mat;
  56. create_rand_mats(sz, CV_8UC1, y_ref_mat, y_in_gapi_mat);
  57. create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat, uv_in_gapi_mat);
  58. // G-API code //////////////////////////////////////////////////////////////
  59. cv::gapi::wip::draw::Prims prims;
  60. prims.emplace_back(cv::gapi::wip::draw::FText{text, org, fh, color});
  61. cv::GMat y_in, uv_in, y_out, uv_out;
  62. cv::GArray<cv::gapi::wip::draw::Prim> arr;
  63. std::tie(y_out, uv_out) = cv::gapi::wip::draw::renderNV12(y_in, uv_in, arr);
  64. cv::GComputation comp(cv::GIn(y_in, uv_in, arr), cv::GOut(y_out, uv_out));
  65. // Warm-up graph engine:
  66. comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims),
  67. cv::gout(y_out_gapi_mat, uv_out_gapi_mat), std::move(comp_args));
  68. TEST_CYCLE()
  69. {
  70. comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims),
  71. cv::gout(y_out_gapi_mat, uv_out_gapi_mat));
  72. }
  73. SANITY_CHECK_NOTHING();
  74. }
  75. PERF_TEST_P_(RenderTestTexts, RenderTextsPerformanceBGROCVTest)
  76. {
  77. cv::Point org;
  78. int ff = 0;
  79. int thick = 0;
  80. int lt = 0;
  81. double fs = 2.0;
  82. cv::Scalar color;
  83. bool blo = false;
  84. std::string text;
  85. cv::Size sz;
  86. cv::GCompileArgs comp_args;
  87. std::tie(text, sz, org, ff, color, thick, lt, blo, comp_args) = GetParam();
  88. MatType type = CV_8UC3;
  89. cv::Mat gapi_mat, ref_mat;
  90. create_rand_mats(sz, type, ref_mat, gapi_mat);
  91. // G-API code //////////////////////////////////////////////////////////////
  92. cv::gapi::wip::draw::Prims prims;
  93. prims.emplace_back(cv::gapi::wip::draw::Text{text, org, ff, fs, color, thick, lt, blo});
  94. cv::GMat in;
  95. cv::GArray<cv::gapi::wip::draw::Prim> arr;
  96. cv::GComputation comp(cv::GIn(in, arr),
  97. cv::GOut(cv::gapi::wip::draw::render3ch(in, arr)));
  98. // Warm-up graph engine:
  99. comp.apply(gin(gapi_mat, prims), gout(gapi_mat), std::move(comp_args));
  100. TEST_CYCLE()
  101. {
  102. comp.apply(gin(gapi_mat, prims), gout(gapi_mat));
  103. }
  104. SANITY_CHECK_NOTHING();
  105. }
  106. PERF_TEST_P_(RenderTestTexts, RenderTextsPerformanceNV12OCVTest)
  107. {
  108. cv::Point org;
  109. int ff = 0;
  110. int thick = 0;
  111. int lt = 0;
  112. double fs = 2.0;
  113. cv::Scalar color;
  114. bool blo = false;
  115. std::string text;
  116. cv::Size sz;
  117. cv::GCompileArgs comp_args;
  118. std::tie(text, sz, org, ff, color, thick, lt, blo, comp_args) = GetParam();
  119. cv::Mat y_ref_mat, uv_ref_mat;
  120. cv::Mat y_in_gapi_mat, uv_in_gapi_mat,
  121. y_out_gapi_mat, uv_out_gapi_mat;
  122. create_rand_mats(sz, CV_8UC1, y_ref_mat, y_in_gapi_mat);
  123. create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat, uv_in_gapi_mat);
  124. // G-API code //////////////////////////////////////////////////////////////
  125. cv::gapi::wip::draw::Prims prims;
  126. prims.emplace_back(cv::gapi::wip::draw::Text{text, org, ff, fs, color, thick, lt, blo});
  127. cv::GMat y_in, uv_in, y_out, uv_out;
  128. cv::GArray<cv::gapi::wip::draw::Prim> arr;
  129. std::tie(y_out, uv_out) = cv::gapi::wip::draw::renderNV12(y_in, uv_in, arr);
  130. cv::GComputation comp(cv::GIn(y_in, uv_in, arr), cv::GOut(y_out, uv_out));
  131. // Warm-up graph engine:
  132. comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims),
  133. cv::gout(y_out_gapi_mat, uv_out_gapi_mat), std::move(comp_args));
  134. TEST_CYCLE()
  135. {
  136. comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims),
  137. cv::gout(y_out_gapi_mat, uv_out_gapi_mat));
  138. }
  139. SANITY_CHECK_NOTHING();
  140. }
  141. PERF_TEST_P_(RenderTestRects, RenderRectsPerformanceBGROCVTest)
  142. {
  143. cv::Rect rect;
  144. cv::Scalar color;
  145. int thick = 0;
  146. int lt = 0;
  147. int shift = 0;
  148. cv::Size sz;
  149. cv::GCompileArgs comp_args;
  150. std::tie(sz, rect, color, thick, lt, shift, comp_args) = GetParam();
  151. MatType type = CV_8UC3;
  152. cv::Mat gapi_mat, ref_mat;
  153. create_rand_mats(sz, type, ref_mat, gapi_mat);
  154. // G-API code //////////////////////////////////////////////////////////////
  155. cv::gapi::wip::draw::Prims prims;
  156. prims.emplace_back(cv::gapi::wip::draw::Rect{rect, color, thick, lt, shift});
  157. cv::GMat in;
  158. cv::GArray<cv::gapi::wip::draw::Prim> arr;
  159. cv::GComputation comp(cv::GIn(in, arr),
  160. cv::GOut(cv::gapi::wip::draw::render3ch(in, arr)));
  161. // Warm-up graph engine:
  162. comp.apply(gin(gapi_mat, prims), gout(gapi_mat), std::move(comp_args));
  163. TEST_CYCLE()
  164. {
  165. comp.apply(gin(gapi_mat, prims), gout(gapi_mat));
  166. }
  167. SANITY_CHECK_NOTHING();
  168. }
  169. PERF_TEST_P_(RenderTestRects, RenderRectsPerformanceNV12OCVTest)
  170. {
  171. cv::Rect rect;
  172. cv::Scalar color;
  173. int thick = 0;
  174. int lt = 0;
  175. int shift = 0;
  176. cv::Size sz;
  177. cv::GCompileArgs comp_args;
  178. std::tie(sz, rect, color, thick, lt, shift, comp_args) = GetParam();
  179. cv::Mat y_ref_mat, uv_ref_mat;
  180. cv::Mat y_in_gapi_mat, uv_in_gapi_mat,
  181. y_out_gapi_mat, uv_out_gapi_mat;
  182. create_rand_mats(sz, CV_8UC1, y_ref_mat, y_in_gapi_mat);
  183. create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat, uv_in_gapi_mat);
  184. // G-API code //////////////////////////////////////////////////////////////
  185. cv::gapi::wip::draw::Prims prims;
  186. prims.emplace_back(cv::gapi::wip::draw::Rect{rect, color, thick, lt, shift});
  187. cv::GMat y_in, uv_in, y_out, uv_out;
  188. cv::GArray<cv::gapi::wip::draw::Prim> arr;
  189. std::tie(y_out, uv_out) = cv::gapi::wip::draw::renderNV12(y_in, uv_in, arr);
  190. cv::GComputation comp(cv::GIn(y_in, uv_in, arr), cv::GOut(y_out, uv_out));
  191. // Warm-up graph engine:
  192. comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims),
  193. cv::gout(y_out_gapi_mat, uv_out_gapi_mat), std::move(comp_args));
  194. TEST_CYCLE()
  195. {
  196. comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims),
  197. cv::gout(y_out_gapi_mat, uv_out_gapi_mat));
  198. }
  199. SANITY_CHECK_NOTHING();
  200. }
  201. PERF_TEST_P_(RenderTestCircles, RenderCirclesPerformanceBGROCVTest)
  202. {
  203. cv::Point center;
  204. int radius;
  205. cv::Scalar color;
  206. int thick = 0;
  207. int lt = 0;
  208. int shift = 0;
  209. cv::Size sz;
  210. cv::GCompileArgs comp_args;
  211. std::tie(sz, center, radius, color, thick, lt, shift, comp_args) = GetParam();
  212. MatType type = CV_8UC3;
  213. cv::Mat gapi_mat, ref_mat;
  214. create_rand_mats(sz, type, ref_mat, gapi_mat);
  215. // G-API code //////////////////////////////////////////////////////////////
  216. cv::gapi::wip::draw::Prims prims;
  217. prims.emplace_back(cv::gapi::wip::draw::Circle{center, radius, color, thick, lt, shift});
  218. cv::GMat in;
  219. cv::GArray<cv::gapi::wip::draw::Prim> arr;
  220. cv::GComputation comp(cv::GIn(in, arr),
  221. cv::GOut(cv::gapi::wip::draw::render3ch(in, arr)));
  222. // Warm-up graph engine:
  223. comp.apply(gin(gapi_mat, prims), gout(gapi_mat), std::move(comp_args));
  224. TEST_CYCLE()
  225. {
  226. comp.apply(gin(gapi_mat, prims), gout(gapi_mat));
  227. }
  228. SANITY_CHECK_NOTHING();
  229. }
  230. PERF_TEST_P_(RenderTestCircles, RenderCirclesPerformanceNV12OCVTest)
  231. {
  232. cv::Point center;
  233. int radius;
  234. cv::Scalar color;
  235. int thick = 0;
  236. int lt = 0;
  237. int shift = 0;
  238. cv::Size sz;
  239. cv::GCompileArgs comp_args;
  240. std::tie(sz, center, radius, color, thick, lt, shift, comp_args) = GetParam();
  241. cv::Mat y_ref_mat, uv_ref_mat;
  242. cv::Mat y_in_gapi_mat, uv_in_gapi_mat,
  243. y_out_gapi_mat, uv_out_gapi_mat;
  244. create_rand_mats(sz, CV_8UC1, y_ref_mat, y_in_gapi_mat);
  245. create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat, uv_in_gapi_mat);
  246. // G-API code //////////////////////////////////////////////////////////////
  247. cv::gapi::wip::draw::Prims prims;
  248. prims.emplace_back(cv::gapi::wip::draw::Circle{center, radius, color, thick, lt, shift});
  249. cv::GMat y_in, uv_in, y_out, uv_out;
  250. cv::GArray<cv::gapi::wip::draw::Prim> arr;
  251. std::tie(y_out, uv_out) = cv::gapi::wip::draw::renderNV12(y_in, uv_in, arr);
  252. cv::GComputation comp(cv::GIn(y_in, uv_in, arr), cv::GOut(y_out, uv_out));
  253. // Warm-up graph engine:
  254. comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims),
  255. cv::gout(y_out_gapi_mat, uv_out_gapi_mat), std::move(comp_args));
  256. TEST_CYCLE()
  257. {
  258. comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims),
  259. cv::gout(y_out_gapi_mat, uv_out_gapi_mat));
  260. }
  261. SANITY_CHECK_NOTHING();
  262. }
  263. PERF_TEST_P_(RenderTestLines, RenderLinesPerformanceBGROCVTest)
  264. {
  265. cv::Point pt1;
  266. cv::Point pt2;
  267. cv::Scalar color;
  268. int thick = 0;
  269. int lt = 0;
  270. int shift = 0;
  271. compare_f cmpF;
  272. cv::Size sz;
  273. cv::GCompileArgs comp_args;
  274. std::tie(sz, pt1, pt2, color, thick, lt, shift, comp_args) = GetParam();
  275. MatType type = CV_8UC3;
  276. cv::Mat gapi_mat, ref_mat;
  277. create_rand_mats(sz, type, ref_mat, gapi_mat);
  278. // G-API code //////////////////////////////////////////////////////////////
  279. cv::gapi::wip::draw::Prims prims;
  280. prims.emplace_back(cv::gapi::wip::draw::Line{pt1, pt2, color, thick, lt, shift});
  281. cv::GMat in;
  282. cv::GArray<cv::gapi::wip::draw::Prim> arr;
  283. cv::GComputation comp(cv::GIn(in, arr),
  284. cv::GOut(cv::gapi::wip::draw::render3ch(in, arr)));
  285. // Warm-up graph engine:
  286. comp.apply(gin(gapi_mat, prims), gout(gapi_mat), std::move(comp_args));
  287. TEST_CYCLE()
  288. {
  289. comp.apply(gin(gapi_mat, prims), gout(gapi_mat));
  290. }
  291. SANITY_CHECK_NOTHING();
  292. }
  293. PERF_TEST_P_(RenderTestLines, RenderLinesPerformanceNV12OCVTest)
  294. {
  295. cv::Point pt1;
  296. cv::Point pt2;
  297. cv::Scalar color;
  298. int thick = 0;
  299. int lt = 0;
  300. int shift = 0;
  301. compare_f cmpF;
  302. cv::Size sz;
  303. cv::GCompileArgs comp_args;
  304. std::tie(sz, pt1, pt2, color, thick, lt, shift, comp_args) = GetParam();
  305. cv::Mat y_ref_mat, uv_ref_mat;
  306. cv::Mat y_in_gapi_mat, uv_in_gapi_mat,
  307. y_out_gapi_mat, uv_out_gapi_mat;
  308. create_rand_mats(sz, CV_8UC1, y_ref_mat, y_in_gapi_mat);
  309. create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat, uv_in_gapi_mat);
  310. // G-API code //////////////////////////////////////////////////////////////
  311. cv::gapi::wip::draw::Prims prims;
  312. prims.emplace_back(cv::gapi::wip::draw::Line{pt1, pt2, color, thick, lt, shift});
  313. cv::GMat y_in, uv_in, y_out, uv_out;
  314. cv::GArray<cv::gapi::wip::draw::Prim> arr;
  315. std::tie(y_out, uv_out) = cv::gapi::wip::draw::renderNV12(y_in, uv_in, arr);
  316. cv::GComputation comp(cv::GIn(y_in, uv_in, arr), cv::GOut(y_out, uv_out));
  317. // Warm-up graph engine:
  318. comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims),
  319. cv::gout(y_out_gapi_mat, uv_out_gapi_mat), std::move(comp_args));
  320. TEST_CYCLE()
  321. {
  322. comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims),
  323. cv::gout(y_out_gapi_mat, uv_out_gapi_mat));
  324. }
  325. SANITY_CHECK_NOTHING();
  326. }
  327. PERF_TEST_P_(RenderTestMosaics, RenderMosaicsPerformanceBGROCVTest)
  328. {
  329. cv::Rect mos;
  330. int cellsz = 0;
  331. int decim = 0;
  332. cv::Size sz;
  333. cv::GCompileArgs comp_args;
  334. std::tie(sz, mos, cellsz, decim, comp_args) = GetParam();
  335. MatType type = CV_8UC3;
  336. cv::Mat gapi_mat, ref_mat;
  337. create_rand_mats(sz, type, ref_mat, gapi_mat);
  338. // G-API code //////////////////////////////////////////////////////////////
  339. cv::gapi::wip::draw::Prims prims;
  340. prims.emplace_back(cv::gapi::wip::draw::Mosaic{mos, cellsz, decim});
  341. cv::GMat in;
  342. cv::GArray<cv::gapi::wip::draw::Prim> arr;
  343. cv::GComputation comp(cv::GIn(in, arr),
  344. cv::GOut(cv::gapi::wip::draw::render3ch(in, arr)));
  345. // Warm-up graph engine:
  346. comp.apply(gin(gapi_mat, prims), gout(gapi_mat), std::move(comp_args));
  347. TEST_CYCLE()
  348. {
  349. comp.apply(gin(gapi_mat, prims), gout(gapi_mat));
  350. }
  351. SANITY_CHECK_NOTHING();
  352. }
  353. PERF_TEST_P_(RenderTestMosaics, RenderMosaicsPerformanceNV12OCVTest)
  354. {
  355. cv::Rect mos;
  356. int cellsz = 0;
  357. int decim = 0;
  358. cv::Size sz;
  359. cv::GCompileArgs comp_args;
  360. std::tie(sz, mos, cellsz, decim, comp_args) = GetParam();
  361. cv::Mat y_ref_mat, uv_ref_mat;
  362. cv::Mat y_in_gapi_mat, uv_in_gapi_mat,
  363. y_out_gapi_mat, uv_out_gapi_mat;
  364. create_rand_mats(sz, CV_8UC1, y_ref_mat, y_in_gapi_mat);
  365. create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat, uv_in_gapi_mat);
  366. // G-API code //////////////////////////////////////////////////////////////
  367. cv::gapi::wip::draw::Prims prims;
  368. prims.emplace_back(cv::gapi::wip::draw::Mosaic{mos, cellsz, decim});
  369. cv::GMat y_in, uv_in, y_out, uv_out;
  370. cv::GArray<cv::gapi::wip::draw::Prim> arr;
  371. std::tie(y_out, uv_out) = cv::gapi::wip::draw::renderNV12(y_in, uv_in, arr);
  372. cv::GComputation comp(cv::GIn(y_in, uv_in, arr), cv::GOut(y_out, uv_out));
  373. // Warm-up graph engine:
  374. comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims),
  375. cv::gout(y_out_gapi_mat, uv_out_gapi_mat), std::move(comp_args));
  376. TEST_CYCLE()
  377. {
  378. comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims),
  379. cv::gout(y_out_gapi_mat, uv_out_gapi_mat));
  380. }
  381. SANITY_CHECK_NOTHING();
  382. }
  383. PERF_TEST_P_(RenderTestImages, RenderImagesPerformanceBGROCVTest)
  384. {
  385. cv::Rect rect;
  386. cv::Scalar color;
  387. double transparency = 0.0;
  388. cv::Size sz;
  389. cv::GCompileArgs comp_args;
  390. std::tie(sz, rect, color, transparency, comp_args) = GetParam();
  391. MatType type = CV_8UC3;
  392. cv::Mat gapi_mat, ref_mat;
  393. create_rand_mats(sz, type, ref_mat, gapi_mat);
  394. cv::Mat img(rect.size(), CV_8UC3, color);
  395. cv::Mat alpha(rect.size(), CV_32FC1, transparency);
  396. auto tl = rect.tl();
  397. cv::Point org = {tl.x, tl.y + rect.size().height};
  398. // G-API code //////////////////////////////////////////////////////////////
  399. cv::gapi::wip::draw::Prims prims;
  400. prims.emplace_back(cv::gapi::wip::draw::Image{org, img, alpha});
  401. cv::gapi::wip::draw::render(gapi_mat, prims);
  402. cv::GMat in;
  403. cv::GArray<cv::gapi::wip::draw::Prim> arr;
  404. cv::GComputation comp(cv::GIn(in, arr),
  405. cv::GOut(cv::gapi::wip::draw::render3ch(in, arr)));
  406. // Warm-up graph engine:
  407. comp.apply(gin(gapi_mat, prims), gout(gapi_mat), std::move(comp_args));
  408. TEST_CYCLE()
  409. {
  410. comp.apply(gin(gapi_mat, prims), gout(gapi_mat));
  411. }
  412. SANITY_CHECK_NOTHING();
  413. }
  414. PERF_TEST_P_(RenderTestImages, RenderImagesPerformanceNV12OCVTest)
  415. {
  416. cv::Rect rect;
  417. cv::Scalar color;
  418. double transparency = 0.0;
  419. cv::Size sz;
  420. cv::GCompileArgs comp_args;
  421. std::tie(sz, rect, color, transparency, comp_args) = GetParam();
  422. cv::Mat y_ref_mat, uv_ref_mat;
  423. cv::Mat y_in_gapi_mat, uv_in_gapi_mat,
  424. y_out_gapi_mat, uv_out_gapi_mat;
  425. create_rand_mats(sz, CV_8UC1, y_ref_mat, y_in_gapi_mat);
  426. create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat, uv_in_gapi_mat);
  427. cv::Mat img(rect.size(), CV_8UC3, color);
  428. cv::Mat alpha(rect.size(), CV_32FC1, transparency);
  429. auto tl = rect.tl();
  430. cv::Point org = {tl.x, tl.y + rect.size().height};
  431. // G-API code //////////////////////////////////////////////////////////////
  432. cv::gapi::wip::draw::Prims prims;
  433. prims.emplace_back(cv::gapi::wip::draw::Image{org, img, alpha});
  434. cv::GMat y_in, uv_in, y_out, uv_out;
  435. cv::GArray<cv::gapi::wip::draw::Prim> arr;
  436. std::tie(y_out, uv_out) = cv::gapi::wip::draw::renderNV12(y_in, uv_in, arr);
  437. cv::GComputation comp(cv::GIn(y_in, uv_in, arr), cv::GOut(y_out, uv_out));
  438. // Warm-up graph engine:
  439. comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims),
  440. cv::gout(y_out_gapi_mat, uv_out_gapi_mat), std::move(comp_args));
  441. TEST_CYCLE()
  442. {
  443. comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims),
  444. cv::gout(y_out_gapi_mat, uv_out_gapi_mat));
  445. }
  446. SANITY_CHECK_NOTHING();
  447. }
  448. PERF_TEST_P_(RenderTestPolylines, RenderPolylinesPerformanceBGROCVTest)
  449. {
  450. std::vector<cv::Point> points;
  451. cv::Scalar color;
  452. int thick = 0;
  453. int lt = 0;
  454. int shift = 0;
  455. cv::Size sz;
  456. cv::GCompileArgs comp_args;
  457. std::tie(sz, points, color, thick, lt, shift, comp_args) = GetParam();
  458. MatType type = CV_8UC3;
  459. cv::Mat gapi_mat, ref_mat;
  460. create_rand_mats(sz, type, ref_mat, gapi_mat);
  461. // G-API code //////////////////////////////////////////////////////////////
  462. cv::gapi::wip::draw::Prims prims;
  463. prims.emplace_back(cv::gapi::wip::draw::Poly{points, color, thick, lt, shift});
  464. cv::GMat in;
  465. cv::GArray<cv::gapi::wip::draw::Prim> arr;
  466. cv::GComputation comp(cv::GIn(in, arr),
  467. cv::GOut(cv::gapi::wip::draw::render3ch(in, arr)));
  468. // Warm-up graph engine:
  469. comp.apply(gin(gapi_mat, prims), gout(gapi_mat), std::move(comp_args));
  470. TEST_CYCLE()
  471. {
  472. comp.apply(gin(gapi_mat, prims), gout(gapi_mat));
  473. }
  474. SANITY_CHECK_NOTHING();
  475. }
  476. PERF_TEST_P_(RenderTestPolylines, RenderPolylinesPerformanceNV12OCVTest)
  477. {
  478. std::vector<cv::Point> points;
  479. cv::Scalar color;
  480. int thick = 0;
  481. int lt = 0;
  482. int shift = 0;
  483. cv::Size sz;
  484. cv::GCompileArgs comp_args;
  485. std::tie(sz, points, color, thick, lt, shift, comp_args) = GetParam();
  486. cv::Mat y_ref_mat, uv_ref_mat;
  487. cv::Mat y_in_gapi_mat, uv_in_gapi_mat,
  488. y_out_gapi_mat, uv_out_gapi_mat;
  489. create_rand_mats(sz, CV_8UC1, y_ref_mat, y_in_gapi_mat);
  490. create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat, uv_in_gapi_mat);
  491. // G-API code //////////////////////////////////////////////////////////////
  492. cv::gapi::wip::draw::Prims prims;
  493. prims.emplace_back(cv::gapi::wip::draw::Poly{points, color, thick, lt, shift});
  494. cv::GMat y_in, uv_in, y_out, uv_out;
  495. cv::GArray<cv::gapi::wip::draw::Prim> arr;
  496. std::tie(y_out, uv_out) = cv::gapi::wip::draw::renderNV12(y_in, uv_in, arr);
  497. cv::GComputation comp(cv::GIn(y_in, uv_in, arr), cv::GOut(y_out, uv_out));
  498. // Warm-up graph engine:
  499. comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims),
  500. cv::gout(y_out_gapi_mat, uv_out_gapi_mat), std::move(comp_args));
  501. TEST_CYCLE()
  502. {
  503. comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims),
  504. cv::gout(y_out_gapi_mat, uv_out_gapi_mat));
  505. }
  506. SANITY_CHECK_NOTHING();
  507. }
  508. PERF_TEST_P_(RenderTestPolyItems, RenderPolyItemsPerformanceBGROCVTest)
  509. {
  510. cv::Size sz;
  511. int rects_num = 0;
  512. int text_num = 0;
  513. int image_num = 0;
  514. cv::GCompileArgs comp_args;
  515. std::tie(sz, rects_num, text_num, image_num, comp_args) = GetParam();
  516. int thick = 2;
  517. int lt = LINE_8;
  518. cv::Scalar color(100, 50, 150);
  519. MatType type = CV_8UC3;
  520. cv::Mat gapi_mat, ref_mat;
  521. create_rand_mats(sz, type, ref_mat, gapi_mat);
  522. cv::Mat gapi_out_mat(sz, type);
  523. gapi_mat.copyTo(gapi_out_mat);
  524. // G-API code //////////////////////////////////////////////////////////////
  525. cv::gapi::wip::draw::Prims prims;
  526. // Rects
  527. int shift = 0;
  528. for (int i = 0; i < rects_num; ++i) {
  529. cv::Rect rect(200 + i, 200 + i, 200, 200);
  530. prims.emplace_back(cv::gapi::wip::draw::Rect(rect, color, thick, lt, shift));
  531. }
  532. // Mosaic
  533. int cellsz = 25;
  534. int decim = 0;
  535. for (int i = 0; i < rects_num; ++i) {
  536. cv::Rect mos(200 + i, 200 + i, 200, 200);
  537. prims.emplace_back(cv::gapi::wip::draw::Mosaic(mos, cellsz, decim));
  538. }
  539. // Text
  540. std::string text = "Some text";
  541. int ff = FONT_HERSHEY_SIMPLEX;
  542. double fs = 2.0;
  543. bool blo = false;
  544. for (int i = 0; i < text_num; ++i) {
  545. cv::Point org(200 + i, 200 + i);
  546. prims.emplace_back(cv::gapi::wip::draw::Text(text, org, ff, fs, color, thick, lt, blo));
  547. }
  548. // Image
  549. double transparency = 1.0;
  550. cv::Rect rect_img(0 ,0 , 50, 50);
  551. cv::Mat img(rect_img.size(), CV_8UC3, color);
  552. cv::Mat alpha(rect_img.size(), CV_32FC1, transparency);
  553. auto tl = rect_img.tl();
  554. for (int i = 0; i < image_num; ++i) {
  555. cv::Point org_img = {tl.x + i, tl.y + rect_img.size().height + i};
  556. prims.emplace_back(cv::gapi::wip::draw::Image({org_img, img, alpha}));
  557. }
  558. cv::GMat in;
  559. cv::GArray<cv::gapi::wip::draw::Prim> arr;
  560. cv::GComputation comp(cv::GIn(in, arr),
  561. cv::GOut(cv::gapi::wip::draw::render3ch(in, arr)));
  562. // Warm-up graph engine:
  563. comp.apply(gin(gapi_mat, prims), gout(gapi_out_mat), std::move(comp_args));
  564. TEST_CYCLE()
  565. {
  566. comp.apply(gin(gapi_mat, prims), gout(gapi_out_mat));
  567. }
  568. SANITY_CHECK_NOTHING();
  569. }
  570. PERF_TEST_P_(RenderTestPolyItems, RenderPolyItemsPerformanceNV12OCVTest)
  571. {
  572. cv::Size sz;
  573. int rects_num = 0;
  574. int text_num = 0;
  575. int image_num = 0;
  576. cv::GCompileArgs comp_args;
  577. std::tie(sz, rects_num, text_num, image_num, comp_args) = GetParam();
  578. int thick = 2;
  579. int lt = LINE_8;
  580. cv::Scalar color(100, 50, 150);
  581. cv::Mat y_ref_mat, uv_ref_mat;
  582. cv::Mat y_in_gapi_mat, uv_in_gapi_mat,
  583. y_out_gapi_mat, uv_out_gapi_mat;
  584. create_rand_mats(sz, CV_8UC1, y_ref_mat, y_in_gapi_mat);
  585. create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat, uv_in_gapi_mat);
  586. // G-API code //////////////////////////////////////////////////////////////
  587. cv::gapi::wip::draw::Prims prims;
  588. // Rects
  589. int shift = 0;
  590. for (int i = 0; i < rects_num; ++i) {
  591. cv::Rect rect(200 + i, 200 + i, 200, 200);
  592. prims.emplace_back(cv::gapi::wip::draw::Rect(rect, color, thick, lt, shift));
  593. }
  594. // Mosaic
  595. int cellsz = 25;
  596. int decim = 0;
  597. for (int i = 0; i < rects_num; ++i) {
  598. cv::Rect mos(200 + i, 200 + i, 200, 200);
  599. prims.emplace_back(cv::gapi::wip::draw::Mosaic(mos, cellsz, decim));
  600. }
  601. // Text
  602. std::string text = "Some text";
  603. int ff = FONT_HERSHEY_SIMPLEX;
  604. double fs = 2.0;
  605. bool blo = false;
  606. for (int i = 0; i < text_num; ++i) {
  607. cv::Point org(200 + i, 200 + i);
  608. prims.emplace_back(cv::gapi::wip::draw::Text(text, org, ff, fs, color, thick, lt, blo));
  609. }
  610. // Image
  611. double transparency = 1.0;
  612. cv::Rect rect_img(0 ,0 , 50, 50);
  613. cv::Mat img(rect_img.size(), CV_8UC3, color);
  614. cv::Mat alpha(rect_img.size(), CV_32FC1, transparency);
  615. auto tl = rect_img.tl();
  616. for (int i = 0; i < image_num; ++i) {
  617. cv::Point org_img = {tl.x + i, tl.y + rect_img.size().height + i};
  618. prims.emplace_back(cv::gapi::wip::draw::Image({org_img, img, alpha}));
  619. }
  620. cv::GMat y_in, uv_in, y_out, uv_out;
  621. cv::GArray<cv::gapi::wip::draw::Prim> arr;
  622. std::tie(y_out, uv_out) = cv::gapi::wip::draw::renderNV12(y_in, uv_in, arr);
  623. cv::GComputation comp(cv::GIn(y_in, uv_in, arr), cv::GOut(y_out, uv_out));
  624. // Warm-up graph engine:
  625. comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims),
  626. cv::gout(y_out_gapi_mat, uv_out_gapi_mat), std::move(comp_args));
  627. TEST_CYCLE()
  628. {
  629. comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims),
  630. cv::gout(y_out_gapi_mat, uv_out_gapi_mat));
  631. }
  632. SANITY_CHECK_NOTHING();
  633. }
  634. } // namespace opencv_test