gapi_render_tests_ocv.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  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 Intel Corporation
  6. #ifdef HAVE_FREETYPE
  7. #include <codecvt>
  8. #endif // HAVE_FREETYPE
  9. #include "../test_precomp.hpp"
  10. #include "../common/gapi_render_tests.hpp"
  11. #include "api/render_priv.hpp"
  12. namespace opencv_test
  13. {
  14. #ifdef HAVE_FREETYPE
  15. GAPI_RENDER_TEST_FIXTURES(OCVTestFTexts, FIXTURE_API(std::wstring, cv::Point, int, cv::Scalar), 4, text, org, fh, color)
  16. #endif // HAVE_FREETYPE
  17. GAPI_RENDER_TEST_FIXTURES(OCVTestTexts, FIXTURE_API(std::string, cv::Point, int, double, cv::Scalar, int, int, bool), 8, text, org, ff, fs, color, thick, lt, blo)
  18. GAPI_RENDER_TEST_FIXTURES(OCVTestRects, FIXTURE_API(cv::Rect, cv::Scalar, int, int, int), 5, rect, color, thick, lt, shift)
  19. GAPI_RENDER_TEST_FIXTURES(OCVTestCircles, FIXTURE_API(cv::Point, int, cv::Scalar, int, int, int), 6, center, radius, color, thick, lt, shift)
  20. GAPI_RENDER_TEST_FIXTURES(OCVTestLines, FIXTURE_API(cv::Point, cv::Point, cv::Scalar, int, int, int), 6, pt1, pt2, color, thick, lt, shift)
  21. GAPI_RENDER_TEST_FIXTURES(OCVTestMosaics, FIXTURE_API(cv::Rect, int, int), 3, mos, cellsz, decim)
  22. GAPI_RENDER_TEST_FIXTURES(OCVTestImages, FIXTURE_API(cv::Rect, cv::Scalar, double), 3, rect, color, transparency)
  23. GAPI_RENDER_TEST_FIXTURES(OCVTestPolylines, FIXTURE_API(Points, cv::Scalar, int, int, int), 5, points, color, thick, lt, shift)
  24. TEST_P(RenderBGROCVTestTexts, AccuracyTest)
  25. {
  26. // G-API code //////////////////////////////////////////////////////////////
  27. cv::gapi::wip::draw::Prims prims;
  28. prims.emplace_back(cv::gapi::wip::draw::Text{text, org, ff, fs, color, thick, lt, blo});
  29. cv::gapi::wip::draw::render(gapi_mat, prims);
  30. // OpenCV code //////////////////////////////////////////////////////////////
  31. {
  32. cv::putText(ref_mat, text, org, ff, fs, color, thick, lt, blo);
  33. }
  34. // Comparison //////////////////////////////////////////////////////////////
  35. {
  36. EXPECT_EQ(0, cv::norm(gapi_mat, ref_mat));
  37. }
  38. }
  39. TEST_P(RenderNV12OCVTestTexts, AccuracyTest)
  40. {
  41. // G-API code //////////////////////////////////////////////////////////////
  42. cv::gapi::wip::draw::Prims prims;
  43. prims.emplace_back(cv::gapi::wip::draw::Text{text, org, ff, fs, color, thick, lt, blo});
  44. cv::gapi::wip::draw::render(y_gapi_mat, uv_gapi_mat, prims);
  45. // OpenCV code //////////////////////////////////////////////////////////////
  46. {
  47. // NV12 -> YUV
  48. cv::Mat yuv;
  49. cv::gapi::wip::draw::cvtNV12ToYUV(y_ref_mat, uv_ref_mat, yuv);
  50. cv::putText(yuv, text, org, ff, fs, cvtBGRToYUVC(color), thick, lt, blo);
  51. // YUV -> NV12
  52. cv::gapi::wip::draw::cvtYUVToNV12(yuv, y_ref_mat, uv_ref_mat);
  53. }
  54. // Comparison //////////////////////////////////////////////////////////////
  55. {
  56. EXPECT_EQ(0, cv::norm(y_gapi_mat, y_ref_mat));
  57. EXPECT_EQ(0, cv::norm(uv_gapi_mat, uv_ref_mat));
  58. }
  59. }
  60. class TestMediaNV12 final : public cv::MediaFrame::IAdapter {
  61. cv::Mat m_y;
  62. cv::Mat m_uv;
  63. public:
  64. TestMediaNV12(cv::Mat y, cv::Mat uv) : m_y(y), m_uv(uv) {
  65. }
  66. cv::GFrameDesc meta() const override {
  67. return cv::GFrameDesc{ cv::MediaFormat::NV12, cv::Size(m_y.cols, m_y.rows) };
  68. }
  69. cv::MediaFrame::View access(cv::MediaFrame::Access) override {
  70. cv::MediaFrame::View::Ptrs pp = {
  71. m_y.ptr(), m_uv.ptr(), nullptr, nullptr
  72. };
  73. cv::MediaFrame::View::Strides ss = {
  74. m_y.step, m_uv.step, 0u, 0u
  75. };
  76. return cv::MediaFrame::View(std::move(pp), std::move(ss));
  77. }
  78. };
  79. TEST_P(RenderMFrameOCVTestTexts, AccuracyTest)
  80. {
  81. // G-API code //////////////////////////////////////////////////////////////
  82. cv::gapi::wip::draw::Prims prims;
  83. prims.emplace_back(cv::gapi::wip::draw::Text{ text, org, ff, fs, color, thick, lt, blo });
  84. cv::MediaFrame nv12 = cv::MediaFrame::Create<TestMediaNV12>(y_gapi_mat, uv_gapi_mat);
  85. cv::gapi::wip::draw::render(nv12, prims);
  86. // OpenCV code //////////////////////////////////////////////////////////////
  87. {
  88. // NV12 -> YUV
  89. cv::Mat yuv;
  90. cv::gapi::wip::draw::cvtNV12ToYUV(y_ref_mat, uv_ref_mat, yuv);
  91. cv::putText(yuv, text, org, ff, fs, cvtBGRToYUVC(color), thick, lt, blo);
  92. // YUV -> NV12
  93. cv::gapi::wip::draw::cvtYUVToNV12(yuv, y_ref_mat, uv_ref_mat);
  94. }
  95. // Comparison //////////////////////////////////////////////////////////////
  96. {
  97. EXPECT_EQ(0, cv::norm(y_gapi_mat, y_ref_mat));
  98. EXPECT_EQ(0, cv::norm(uv_gapi_mat, uv_ref_mat));
  99. }
  100. }
  101. # ifdef HAVE_FREETYPE
  102. TEST_P(RenderBGROCVTestFTexts, AccuracyTest)
  103. {
  104. // G-API code //////////////////////////////////////////////////////////////
  105. cv::gapi::wip::draw::Prims prims;
  106. prims.emplace_back(cv::gapi::wip::draw::FText{text, org, fh, color});
  107. EXPECT_NO_THROW(cv::gapi::wip::draw::render(gapi_mat, prims,
  108. cv::compile_args(cv::gapi::wip::draw::freetype_font{
  109. "/usr/share/fonts/truetype/wqy/wqy-microhei.ttc"
  110. })));
  111. }
  112. TEST_P(RenderNV12OCVTestFTexts, AccuracyTest)
  113. {
  114. // G-API code //////////////////////////////////////////////////////////////
  115. cv::gapi::wip::draw::Prims prims;
  116. prims.emplace_back(cv::gapi::wip::draw::FText{text, org, fh, color});
  117. EXPECT_NO_THROW(cv::gapi::wip::draw::render(y_gapi_mat, uv_gapi_mat, prims,
  118. cv::compile_args(cv::gapi::wip::draw::freetype_font{
  119. "/usr/share/fonts/truetype/wqy/wqy-microhei.ttc"
  120. })));
  121. }
  122. TEST_P(RenderMFrameOCVTestFTexts, AccuracyTest)
  123. {
  124. // G-API code //////////////////////////////////////////////////////////////
  125. cv::Mat y_copy_mat = y_gapi_mat.clone();
  126. cv::Mat uv_copy_mat = uv_gapi_mat.clone();
  127. cv::gapi::wip::draw::Prims prims;
  128. prims.emplace_back(cv::gapi::wip::draw::FText{ text, org, fh, color });
  129. cv::MediaFrame nv12 = cv::MediaFrame::Create<TestMediaNV12>(y_gapi_mat, uv_gapi_mat);
  130. EXPECT_NO_THROW(cv::gapi::wip::draw::render(nv12, prims,
  131. cv::compile_args(cv::gapi::wip::draw::freetype_font{
  132. "/usr/share/fonts/truetype/wqy/wqy-microhei.ttc"
  133. })));
  134. EXPECT_NE(0, cv::norm(y_gapi_mat, y_copy_mat));
  135. EXPECT_NE(0, cv::norm(uv_gapi_mat, uv_copy_mat));
  136. }
  137. static std::wstring to_wstring(const char* bytes)
  138. {
  139. std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
  140. return converter.from_bytes(bytes);
  141. }
  142. TEST(RenderFText, FontsNotPassedToCompileArgs)
  143. {
  144. cv::Mat in_mat(640, 480, CV_8UC3, cv::Scalar::all(0));
  145. std::wstring text = to_wstring("\xe4\xbd\xa0\xe5\xa5\xbd");
  146. cv::Point org(100, 100);
  147. int fh = 60;
  148. cv::Scalar color(200, 100, 25);
  149. cv::gapi::wip::draw::Prims prims;
  150. prims.emplace_back(cv::gapi::wip::draw::FText{text, org, fh, color});
  151. EXPECT_ANY_THROW(cv::gapi::wip::draw::render(in_mat, prims));
  152. }
  153. #endif // HAVE_FREETYPE
  154. TEST_P(RenderBGROCVTestRects, AccuracyTest)
  155. {
  156. // G-API code //////////////////////////////////////////////////////////////
  157. cv::gapi::wip::draw::Prims prims;
  158. prims.emplace_back(cv::gapi::wip::draw::Rect{rect, color, thick, lt, shift});
  159. cv::gapi::wip::draw::render(gapi_mat, prims);
  160. // OpenCV code //////////////////////////////////////////////////////////////
  161. {
  162. cv::rectangle(ref_mat, rect, color, thick, lt, shift);
  163. }
  164. // Comparison //////////////////////////////////////////////////////////////
  165. {
  166. EXPECT_EQ(0, cv::norm(gapi_mat, ref_mat));
  167. }
  168. }
  169. TEST_P(RenderNV12OCVTestRects, AccuracyTest)
  170. {
  171. // G-API code //////////////////////////////////////////////////////////////
  172. cv::gapi::wip::draw::Prims prims;
  173. prims.emplace_back(cv::gapi::wip::draw::Rect{rect, color, thick, lt, shift});
  174. cv::gapi::wip::draw::render(y_gapi_mat, uv_gapi_mat, prims);
  175. // OpenCV code //////////////////////////////////////////////////////////////
  176. {
  177. // NV12 -> YUV
  178. cv::Mat yuv;
  179. cv::gapi::wip::draw::cvtNV12ToYUV(y_ref_mat, uv_ref_mat, yuv);
  180. cv::rectangle(yuv, rect, cvtBGRToYUVC(color), thick, lt, shift);
  181. // YUV -> NV12
  182. cv::gapi::wip::draw::cvtYUVToNV12(yuv, y_ref_mat, uv_ref_mat);
  183. }
  184. // Comparison //////////////////////////////////////////////////////////////
  185. {
  186. EXPECT_EQ(0, cv::norm(y_gapi_mat, y_ref_mat));
  187. EXPECT_EQ(0, cv::norm(uv_gapi_mat, uv_ref_mat));
  188. }
  189. }
  190. TEST_P(RenderMFrameOCVTestRects, AccuracyTest)
  191. {
  192. // G-API code //////////////////////////////////////////////////////////////
  193. cv::gapi::wip::draw::Prims prims;
  194. prims.emplace_back(cv::gapi::wip::draw::Rect{ rect, color, thick, lt, shift });
  195. cv::MediaFrame nv12 = cv::MediaFrame::Create<TestMediaNV12>(y_gapi_mat, uv_gapi_mat);
  196. cv::gapi::wip::draw::render(nv12, prims);
  197. // OpenCV code //////////////////////////////////////////////////////////////
  198. {
  199. // NV12 -> YUV
  200. cv::Mat yuv;
  201. cv::gapi::wip::draw::cvtNV12ToYUV(y_ref_mat, uv_ref_mat, yuv);
  202. cv::rectangle(yuv, rect, cvtBGRToYUVC(color), thick, lt, shift);
  203. // YUV -> NV12
  204. cv::gapi::wip::draw::cvtYUVToNV12(yuv, y_ref_mat, uv_ref_mat);
  205. }
  206. // Comparison //////////////////////////////////////////////////////////////
  207. {
  208. EXPECT_EQ(0, cv::norm(y_gapi_mat, y_ref_mat));
  209. EXPECT_EQ(0, cv::norm(uv_gapi_mat, uv_ref_mat));
  210. }
  211. }
  212. TEST_P(RenderBGROCVTestCircles, AccuracyTest)
  213. {
  214. // G-API code //////////////////////////////////////////////////////////////
  215. cv::gapi::wip::draw::Prims prims;
  216. prims.emplace_back(cv::gapi::wip::draw::Circle{center, radius, color, thick, lt, shift});
  217. cv::gapi::wip::draw::render(gapi_mat, prims);
  218. // OpenCV code //////////////////////////////////////////////////////////////
  219. {
  220. cv::circle(ref_mat, center, radius, color, thick, lt, shift);
  221. }
  222. // Comparison //////////////////////////////////////////////////////////////
  223. {
  224. EXPECT_EQ(0, cv::norm(gapi_mat, ref_mat));
  225. }
  226. }
  227. TEST_P(RenderNV12OCVTestCircles, AccuracyTest)
  228. {
  229. // G-API code //////////////////////////////////////////////////////////////
  230. cv::gapi::wip::draw::Prims prims;
  231. prims.emplace_back(cv::gapi::wip::draw::Circle{center, radius, color, thick, lt, shift});
  232. cv::gapi::wip::draw::render(y_gapi_mat, uv_gapi_mat, prims);
  233. // OpenCV code //////////////////////////////////////////////////////////////
  234. {
  235. // NV12 -> YUV
  236. cv::Mat yuv;
  237. cv::gapi::wip::draw::cvtNV12ToYUV(y_ref_mat, uv_ref_mat, yuv);
  238. cv::circle(yuv, center, radius, cvtBGRToYUVC(color), thick, lt, shift);
  239. // YUV -> NV12
  240. cv::gapi::wip::draw::cvtYUVToNV12(yuv, y_ref_mat, uv_ref_mat);
  241. }
  242. // Comparison //////////////////////////////////////////////////////////////
  243. {
  244. EXPECT_EQ(0, cv::norm(y_gapi_mat, y_ref_mat));
  245. EXPECT_EQ(0, cv::norm(uv_gapi_mat, uv_ref_mat));
  246. }
  247. }
  248. TEST_P(RenderMFrameOCVTestCircles, AccuracyTest)
  249. {
  250. // G-API code //////////////////////////////////////////////////////////////
  251. cv::gapi::wip::draw::Prims prims;
  252. prims.emplace_back(cv::gapi::wip::draw::Circle{ center, radius, color, thick, lt, shift });
  253. cv::MediaFrame nv12 = cv::MediaFrame::Create<TestMediaNV12>(y_gapi_mat, uv_gapi_mat);
  254. cv::gapi::wip::draw::render(nv12, prims);
  255. // OpenCV code //////////////////////////////////////////////////////////////
  256. {
  257. // NV12 -> YUV
  258. cv::Mat yuv;
  259. cv::gapi::wip::draw::cvtNV12ToYUV(y_ref_mat, uv_ref_mat, yuv);
  260. cv::circle(yuv, center, radius, cvtBGRToYUVC(color), thick, lt, shift);
  261. // YUV -> NV12
  262. cv::gapi::wip::draw::cvtYUVToNV12(yuv, y_ref_mat, uv_ref_mat);
  263. }
  264. // Comparison //////////////////////////////////////////////////////////////
  265. {
  266. EXPECT_EQ(0, cv::norm(y_gapi_mat, y_ref_mat));
  267. EXPECT_EQ(0, cv::norm(uv_gapi_mat, uv_ref_mat));
  268. }
  269. }
  270. TEST_P(RenderBGROCVTestLines, AccuracyTest)
  271. {
  272. // G-API code //////////////////////////////////////////////////////////////
  273. cv::gapi::wip::draw::Prims prims;
  274. prims.emplace_back(cv::gapi::wip::draw::Line{pt1, pt2, color, thick, lt, shift});
  275. cv::gapi::wip::draw::render(gapi_mat, prims);
  276. // OpenCV code //////////////////////////////////////////////////////////////
  277. {
  278. cv::line(ref_mat, pt1, pt2, color, thick, lt, shift);
  279. }
  280. // Comparison //////////////////////////////////////////////////////////////
  281. {
  282. EXPECT_EQ(0, cv::norm(gapi_mat, ref_mat));
  283. }
  284. }
  285. TEST_P(RenderNV12OCVTestLines, AccuracyTest)
  286. {
  287. // G-API code //////////////////////////////////////////////////////////////
  288. cv::gapi::wip::draw::Prims prims;
  289. prims.emplace_back(cv::gapi::wip::draw::Line{pt1, pt2, color, thick, lt, shift});
  290. cv::gapi::wip::draw::render(y_gapi_mat, uv_gapi_mat, prims);
  291. // OpenCV code //////////////////////////////////////////////////////////////
  292. {
  293. // NV12 -> YUV
  294. cv::Mat yuv;
  295. cv::gapi::wip::draw::cvtNV12ToYUV(y_ref_mat, uv_ref_mat, yuv);
  296. cv::line(yuv, pt1, pt2, cvtBGRToYUVC(color), thick, lt, shift);
  297. // YUV -> NV12
  298. cv::gapi::wip::draw::cvtYUVToNV12(yuv, y_ref_mat, uv_ref_mat);
  299. }
  300. // Comparison //////////////////////////////////////////////////////////////
  301. {
  302. EXPECT_EQ(0, cv::norm(y_gapi_mat, y_ref_mat));
  303. EXPECT_EQ(0, cv::norm(uv_gapi_mat, uv_ref_mat));
  304. }
  305. }
  306. TEST_P(RenderMFrameOCVTestLines, AccuracyTest)
  307. {
  308. // G-API code //////////////////////////////////////////////////////////////
  309. cv::gapi::wip::draw::Prims prims;
  310. prims.emplace_back(cv::gapi::wip::draw::Line{ pt1, pt2, color, thick, lt, shift });
  311. cv::MediaFrame nv12 = cv::MediaFrame::Create<TestMediaNV12>(y_gapi_mat, uv_gapi_mat);
  312. cv::gapi::wip::draw::render(nv12, prims);
  313. // OpenCV code //////////////////////////////////////////////////////////////
  314. {
  315. // NV12 -> YUV
  316. cv::Mat yuv;
  317. cv::gapi::wip::draw::cvtNV12ToYUV(y_ref_mat, uv_ref_mat, yuv);
  318. cv::line(yuv, pt1, pt2, cvtBGRToYUVC(color), thick, lt, shift);
  319. // YUV -> NV12
  320. cv::gapi::wip::draw::cvtYUVToNV12(yuv, y_ref_mat, uv_ref_mat);
  321. }
  322. // Comparison //////////////////////////////////////////////////////////////
  323. {
  324. EXPECT_EQ(0, cv::norm(y_gapi_mat, y_ref_mat));
  325. EXPECT_EQ(0, cv::norm(uv_gapi_mat, uv_ref_mat));
  326. }
  327. }
  328. TEST_P(RenderBGROCVTestMosaics, AccuracyTest)
  329. {
  330. // G-API code //////////////////////////////////////////////////////////////
  331. cv::gapi::wip::draw::Prims prims;
  332. prims.emplace_back(cv::gapi::wip::draw::Mosaic{mos, cellsz, decim});
  333. cv::gapi::wip::draw::render(gapi_mat, prims);
  334. // OpenCV code //////////////////////////////////////////////////////////////
  335. {
  336. drawMosaicRef(ref_mat, mos, cellsz);
  337. }
  338. // Comparison //////////////////////////////////////////////////////////////
  339. {
  340. EXPECT_EQ(0, cv::norm(gapi_mat, ref_mat));
  341. }
  342. }
  343. TEST_P(RenderNV12OCVTestMosaics, AccuracyTest)
  344. {
  345. // G-API code //////////////////////////////////////////////////////////////
  346. cv::gapi::wip::draw::Prims prims;
  347. prims.emplace_back(cv::gapi::wip::draw::Mosaic{mos, cellsz, decim});
  348. cv::gapi::wip::draw::render(y_gapi_mat, uv_gapi_mat, prims);
  349. // OpenCV code //////////////////////////////////////////////////////////////
  350. {
  351. // NV12 -> YUV
  352. cv::Mat yuv;
  353. cv::gapi::wip::draw::cvtNV12ToYUV(y_ref_mat, uv_ref_mat, yuv);
  354. drawMosaicRef(yuv, mos, cellsz);
  355. // YUV -> NV12
  356. cv::gapi::wip::draw::cvtYUVToNV12(yuv, y_ref_mat, uv_ref_mat);
  357. }
  358. // Comparison //////////////////////////////////////////////////////////////
  359. {
  360. EXPECT_EQ(0, cv::norm(y_gapi_mat, y_ref_mat));
  361. EXPECT_EQ(0, cv::norm(uv_gapi_mat, uv_ref_mat));
  362. }
  363. }
  364. TEST_P(RenderMFrameOCVTestMosaics, AccuracyTest)
  365. {
  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::MediaFrame nv12 = cv::MediaFrame::Create<TestMediaNV12>(y_gapi_mat, uv_gapi_mat);
  370. cv::gapi::wip::draw::render(nv12, prims);
  371. // OpenCV code //////////////////////////////////////////////////////////////
  372. {
  373. // NV12 -> YUV
  374. cv::Mat yuv;
  375. cv::gapi::wip::draw::cvtNV12ToYUV(y_ref_mat, uv_ref_mat, yuv);
  376. drawMosaicRef(yuv, mos, cellsz);
  377. // YUV -> NV12
  378. cv::gapi::wip::draw::cvtYUVToNV12(yuv, y_ref_mat, uv_ref_mat);
  379. }
  380. // Comparison //////////////////////////////////////////////////////////////
  381. {
  382. EXPECT_EQ(0, cv::norm(y_gapi_mat, y_ref_mat));
  383. EXPECT_EQ(0, cv::norm(uv_gapi_mat, uv_ref_mat));
  384. }
  385. }
  386. TEST_P(RenderBGROCVTestImages, AccuracyTest)
  387. {
  388. cv::Mat img(rect.size(), CV_8UC3, color);
  389. cv::Mat alpha(rect.size(), CV_32FC1, transparency);
  390. auto tl = rect.tl();
  391. cv::Point org = {tl.x, tl.y + rect.size().height};
  392. // G-API code //////////////////////////////////////////////////////////////
  393. cv::gapi::wip::draw::Prims prims;
  394. prims.emplace_back(cv::gapi::wip::draw::Image{org, img, alpha});
  395. cv::gapi::wip::draw::render(gapi_mat, prims);
  396. // OpenCV code //////////////////////////////////////////////////////////////
  397. {
  398. blendImageRef(ref_mat, org, img, alpha);
  399. }
  400. // Comparison //////////////////////////////////////////////////////////////
  401. {
  402. EXPECT_EQ(0, cv::norm(gapi_mat, ref_mat));
  403. }
  404. }
  405. TEST_P(RenderNV12OCVTestImages, AccuracyTest)
  406. {
  407. cv::Mat img(rect.size(), CV_8UC3, color);
  408. cv::Mat alpha(rect.size(), CV_32FC1, transparency);
  409. auto tl = rect.tl();
  410. cv::Point org = {tl.x, tl.y + rect.size().height};
  411. // G-API code //////////////////////////////////////////////////////////////
  412. cv::gapi::wip::draw::Prims prims;
  413. prims.emplace_back(cv::gapi::wip::draw::Image{org, img, alpha});
  414. cv::gapi::wip::draw::render(y_gapi_mat, uv_gapi_mat, prims);
  415. // OpenCV code //////////////////////////////////////////////////////////////
  416. {
  417. // NV12 -> YUV
  418. cv::Mat yuv;
  419. cv::gapi::wip::draw::cvtNV12ToYUV(y_ref_mat, uv_ref_mat, yuv);
  420. cv::Mat yuv_img;
  421. cv::cvtColor(img, yuv_img, cv::COLOR_BGR2YUV);
  422. blendImageRef(yuv, org, yuv_img, alpha);
  423. // YUV -> NV12
  424. cv::gapi::wip::draw::cvtYUVToNV12(yuv, y_ref_mat, uv_ref_mat);
  425. }
  426. // Comparison //////////////////////////////////////////////////////////////
  427. {
  428. EXPECT_EQ(0, cv::norm(y_gapi_mat, y_ref_mat));
  429. EXPECT_EQ(0, cv::norm(uv_gapi_mat, uv_ref_mat));
  430. }
  431. }
  432. TEST_P(RenderMFrameOCVTestImages, AccuracyTest)
  433. {
  434. cv::Mat img(rect.size(), CV_8UC3, color);
  435. cv::Mat alpha(rect.size(), CV_32FC1, transparency);
  436. auto tl = rect.tl();
  437. cv::Point org = { tl.x, tl.y + rect.size().height };
  438. // G-API code //////////////////////////////////////////////////////////////
  439. cv::gapi::wip::draw::Prims prims;
  440. prims.emplace_back(cv::gapi::wip::draw::Image{ org, img, alpha });
  441. cv::MediaFrame nv12 = cv::MediaFrame::Create<TestMediaNV12>(y_gapi_mat, uv_gapi_mat);
  442. cv::gapi::wip::draw::render(nv12, prims);
  443. // OpenCV code //////////////////////////////////////////////////////////////
  444. {
  445. // NV12 -> YUV
  446. cv::Mat yuv;
  447. cv::gapi::wip::draw::cvtNV12ToYUV(y_ref_mat, uv_ref_mat, yuv);
  448. cv::Mat yuv_img;
  449. cv::cvtColor(img, yuv_img, cv::COLOR_BGR2YUV);
  450. blendImageRef(yuv, org, yuv_img, alpha);
  451. // YUV -> NV12
  452. cv::gapi::wip::draw::cvtYUVToNV12(yuv, y_ref_mat, uv_ref_mat);
  453. }
  454. // Comparison //////////////////////////////////////////////////////////////
  455. {
  456. EXPECT_EQ(0, cv::norm(y_gapi_mat, y_ref_mat));
  457. EXPECT_EQ(0, cv::norm(uv_gapi_mat, uv_ref_mat));
  458. }
  459. }
  460. TEST_P(RenderBGROCVTestPolylines, AccuracyTest)
  461. {
  462. // G-API code //////////////////////////////////////////////////////////////
  463. cv::gapi::wip::draw::Prims prims;
  464. prims.emplace_back(cv::gapi::wip::draw::Poly{points, color, thick, lt, shift});
  465. cv::gapi::wip::draw::render(gapi_mat, prims);
  466. // OpenCV code //////////////////////////////////////////////////////////////
  467. {
  468. std::vector<std::vector<cv::Point>> array_points{points};
  469. cv::fillPoly(ref_mat, array_points, color, lt, shift);
  470. }
  471. // Comparison //////////////////////////////////////////////////////////////
  472. {
  473. EXPECT_EQ(0, cv::norm(gapi_mat, ref_mat));
  474. }
  475. }
  476. TEST_P(RenderNV12OCVTestPolylines, AccuracyTest)
  477. {
  478. // G-API code //////////////////////////////////////////////////////////////
  479. cv::gapi::wip::draw::Prims prims;
  480. prims.emplace_back(cv::gapi::wip::draw::Poly{points, color, thick, lt, shift});
  481. cv::gapi::wip::draw::render(y_gapi_mat, uv_gapi_mat, prims);
  482. // OpenCV code //////////////////////////////////////////////////////////////
  483. {
  484. // NV12 -> YUV
  485. cv::Mat yuv;
  486. cv::gapi::wip::draw::cvtNV12ToYUV(y_ref_mat, uv_ref_mat, yuv);
  487. std::vector<std::vector<cv::Point>> pp{points};
  488. cv::fillPoly(yuv, pp, cvtBGRToYUVC(color), lt, shift);
  489. // YUV -> NV12
  490. cv::gapi::wip::draw::cvtYUVToNV12(yuv, y_ref_mat, uv_ref_mat);
  491. }
  492. // Comparison //////////////////////////////////////////////////////////////
  493. {
  494. EXPECT_EQ(0, cv::norm(y_gapi_mat, y_ref_mat));
  495. EXPECT_EQ(0, cv::norm(uv_gapi_mat, uv_ref_mat));
  496. }
  497. }
  498. TEST_P(RenderMFrameOCVTestPolylines, AccuracyTest)
  499. {
  500. // G-API code //////////////////////////////////////////////////////////////
  501. cv::gapi::wip::draw::Prims prims;
  502. prims.emplace_back(cv::gapi::wip::draw::Poly{ points, color, thick, lt, shift });
  503. cv::MediaFrame nv12 = cv::MediaFrame::Create<TestMediaNV12>(y_gapi_mat, uv_gapi_mat);
  504. cv::gapi::wip::draw::render(nv12, prims);
  505. // OpenCV code //////////////////////////////////////////////////////////////
  506. {
  507. // NV12 -> YUV
  508. cv::Mat yuv;
  509. cv::gapi::wip::draw::cvtNV12ToYUV(y_ref_mat, uv_ref_mat, yuv);
  510. std::vector<std::vector<cv::Point>> pp{ points };
  511. cv::fillPoly(yuv, pp, cvtBGRToYUVC(color), lt, shift);
  512. // YUV -> NV12
  513. cv::gapi::wip::draw::cvtYUVToNV12(yuv, y_ref_mat, uv_ref_mat);
  514. }
  515. // Comparison //////////////////////////////////////////////////////////////
  516. {
  517. EXPECT_EQ(0, cv::norm(y_gapi_mat, y_ref_mat));
  518. EXPECT_EQ(0, cv::norm(uv_gapi_mat, uv_ref_mat));
  519. }
  520. }
  521. // FIXME avoid code duplicate for NV12 and BGR cases
  522. INSTANTIATE_TEST_CASE_P(RenderBGROCVTestRectsImpl, RenderBGROCVTestRects,
  523. Combine(Values(cv::Size(1280, 720)),
  524. Values(cv::Rect(100, 100, 200, 200)),
  525. Values(cv::Scalar(100, 50, 150)),
  526. Values(2),
  527. Values(LINE_8, LINE_4),
  528. Values(0, 1)));
  529. INSTANTIATE_TEST_CASE_P(RenderNV12OCVTestRectsImpl, RenderNV12OCVTestRects,
  530. Combine(Values(cv::Size(1280, 720)),
  531. Values(cv::Rect(100, 100, 200, 200)),
  532. Values(cv::Scalar(100, 50, 150)),
  533. Values(2),
  534. Values(LINE_8),
  535. Values(0)));
  536. INSTANTIATE_TEST_CASE_P(RenderMFrameOCVTestRectsImpl, RenderMFrameOCVTestRects,
  537. Combine(Values(cv::Size(1280, 720)),
  538. Values(cv::Rect(100, 100, 200, 200)),
  539. Values(cv::Scalar(100, 50, 150)),
  540. Values(2),
  541. Values(LINE_8),
  542. Values(0)));
  543. INSTANTIATE_TEST_CASE_P(RenderBGROCVTestCirclesImpl, RenderBGROCVTestCircles,
  544. Combine(Values(cv::Size(1280, 720)),
  545. Values(cv::Point(100, 100)),
  546. Values(10),
  547. Values(cv::Scalar(100, 50, 150)),
  548. Values(2),
  549. Values(LINE_8),
  550. Values(0)));
  551. INSTANTIATE_TEST_CASE_P(RenderNV12OCVTestCirclesImpl, RenderNV12OCVTestCircles,
  552. Combine(Values(cv::Size(1280, 720)),
  553. Values(cv::Point(100, 100)),
  554. Values(10),
  555. Values(cv::Scalar(100, 50, 150)),
  556. Values(2),
  557. Values(LINE_8, LINE_4),
  558. Values(0, 1)));
  559. INSTANTIATE_TEST_CASE_P(RenderMFrameOCVTestCirclesImpl, RenderMFrameOCVTestCircles,
  560. Combine(Values(cv::Size(1280, 720)),
  561. Values(cv::Point(100, 100)),
  562. Values(10),
  563. Values(cv::Scalar(100, 50, 150)),
  564. Values(2),
  565. Values(LINE_8),
  566. Values(0)));
  567. INSTANTIATE_TEST_CASE_P(RenderBGROCVTestLinesImpl, RenderBGROCVTestLines,
  568. Combine(Values(cv::Size(1280, 720)),
  569. Values(cv::Point(100, 100)),
  570. Values(cv::Point(200, 200)),
  571. Values(cv::Scalar(100, 50, 150)),
  572. Values(2),
  573. Values(LINE_8),
  574. Values(0)));
  575. INSTANTIATE_TEST_CASE_P(RenderNV12OCVTestLinesImpl, RenderNV12OCVTestLines,
  576. Combine(Values(cv::Size(1280, 720)),
  577. Values(cv::Point(100, 100)),
  578. Values(cv::Point(200, 200)),
  579. Values(cv::Scalar(100, 50, 150)),
  580. Values(2),
  581. Values(LINE_8),
  582. Values(0)));
  583. INSTANTIATE_TEST_CASE_P(RenderMFrameOCVTestLinesImpl, RenderMFrameOCVTestLines,
  584. Combine(Values(cv::Size(1280, 720)),
  585. Values(cv::Point(100, 100)),
  586. Values(cv::Point(200, 200)),
  587. Values(cv::Scalar(100, 50, 150)),
  588. Values(2),
  589. Values(LINE_8),
  590. Values(0)));
  591. INSTANTIATE_TEST_CASE_P(RenderBGROCVTestTextsImpl, RenderBGROCVTestTexts,
  592. Combine(Values(cv::Size(1280, 720)),
  593. Values("SomeText"),
  594. Values(cv::Point(200, 200)),
  595. Values(FONT_HERSHEY_SIMPLEX),
  596. Values(2.0),
  597. Values(cv::Scalar(0, 255, 0)),
  598. Values(2),
  599. Values(LINE_8),
  600. Values(false)));
  601. INSTANTIATE_TEST_CASE_P(RenderNV12OCVTestTextsImpl, RenderNV12OCVTestTexts,
  602. Combine(Values(cv::Size(1280, 720)),
  603. Values("SomeText"),
  604. Values(cv::Point(200, 200)),
  605. Values(FONT_HERSHEY_SIMPLEX),
  606. Values(2.0),
  607. Values(cv::Scalar(0, 255, 0)),
  608. Values(2),
  609. Values(LINE_8),
  610. Values(false)));
  611. INSTANTIATE_TEST_CASE_P(RenderMFrameOCVTestTextsImpl, RenderMFrameOCVTestTexts,
  612. Combine(Values(cv::Size(1280, 720)),
  613. Values("SomeText"),
  614. Values(cv::Point(200, 200)),
  615. Values(FONT_HERSHEY_SIMPLEX),
  616. Values(2.0),
  617. Values(cv::Scalar(0, 255, 0)),
  618. Values(2),
  619. Values(LINE_8),
  620. Values(false)));
  621. #ifdef HAVE_FREETYPE
  622. INSTANTIATE_TEST_CASE_P(RenderBGROCVTestFTextsImpl, RenderBGROCVTestFTexts,
  623. Combine(Values(cv::Size(1280, 720)),
  624. Values(to_wstring("\xe4\xbd\xa0\xe5\xa5\xbd\xef\xbc\x8c\xe4\xb8\x96\xe7\x95\x8c"),
  625. to_wstring("\xe3\x80\xa4\xe3\x80\xa5\xe3\x80\xa6\xe3\x80\xa7\xe3\x80\xa8\xe3\x80\x85\xe3\x80\x86")),
  626. Values(cv::Point(200, 200)),
  627. Values(64),
  628. Values(cv::Scalar(0, 255, 0))));
  629. INSTANTIATE_TEST_CASE_P(RenderNV12OCVTestFTextsImpl, RenderNV12OCVTestFTexts,
  630. Combine(Values(cv::Size(1280, 720)),
  631. Values(to_wstring("\xe4\xbd\xa0\xe5\xa5\xbd\xef\xbc\x8c\xe4\xb8\x96\xe7\x95\x8c"),
  632. to_wstring("\xe3\x80\xa4\xe3\x80\xa5\xe3\x80\xa6\xe3\x80\xa7\xe3\x80\xa8\xe3\x80\x85\xe3\x80\x86")),
  633. Values(cv::Point(200, 200)),
  634. Values(64),
  635. Values(cv::Scalar(0, 255, 0))));
  636. INSTANTIATE_TEST_CASE_P(RenderMFrameOCVTestFTextsImpl, RenderMFrameOCVTestFTexts,
  637. Combine(Values(cv::Size(1280, 720)),
  638. Values(to_wstring("\xe4\xbd\xa0\xe5\xa5\xbd\xef\xbc\x8c\xe4\xb8\x96\xe7\x95\x8c"),
  639. to_wstring("\xe3\x80\xa4\xe3\x80\xa5\xe3\x80\xa6\xe3\x80\xa7\xe3\x80\xa8\xe3\x80\x85\xe3\x80\x86")),
  640. Values(cv::Point(200, 200)),
  641. Values(64),
  642. Values(cv::Scalar(0, 255, 0))));
  643. #endif // HAVE_FREETYPE
  644. // FIXME Implement a macros to instantiate the tests because BGR and NV12 have the same parameters
  645. INSTANTIATE_TEST_CASE_P(RenderBGROCVTestMosaicsImpl, RenderBGROCVTestMosaics,
  646. Combine(Values(cv::Size(1280, 720)),
  647. Values(cv::Rect(100, 100, 200, 200), // Normal case
  648. cv::Rect(-50, -50, 200, 200), // Intersection with left-top corner
  649. cv::Rect(-50, 100, 200, 200), // Intersection with left side
  650. cv::Rect(-50, 600, 200, 200), // Intersection with left-bottom corner
  651. cv::Rect(100, 600, 200, 200), // Intersection with bottom side
  652. cv::Rect(1200, 700, 200, 200), // Intersection with right-bottom corner
  653. cv::Rect(1200, 400, 200, 200), // Intersection with right side
  654. cv::Rect(1200, -50, 200, 200), // Intersection with right-top corner
  655. cv::Rect(500, -50, 200, 200), // Intersection with top side
  656. cv::Rect(-100, 300, 1480, 300), // From left to right side with intersection
  657. cv::Rect(5000, 2000, 100, 100), // Outside image
  658. cv::Rect(-300, -300, 3000, 3000), // Cover all image
  659. cv::Rect(100, 100, -500, -500)), // Negative width and height
  660. Values(25),
  661. Values(0)));
  662. INSTANTIATE_TEST_CASE_P(RenderNV12OCVTestMosaicsImpl, RenderNV12OCVTestMosaics,
  663. Combine(Values(cv::Size(1280, 720)),
  664. Values(cv::Rect(100, 100, 200, 200), // Normal case
  665. cv::Rect(-50, -50, 200, 200), // Intersection with left-top corner
  666. cv::Rect(-50, 100, 200, 200), // Intersection with left side
  667. cv::Rect(-50, 600, 200, 200), // Intersection with left-bottom corner
  668. cv::Rect(100, 600, 200, 200), // Intersection with bottom side
  669. cv::Rect(1200, 700, 200, 200), // Intersection with right-bottom corner
  670. cv::Rect(1200, 400, 200, 200), // Intersection with right side
  671. cv::Rect(1200, -50, 200, 200), // Intersection with right-top corner
  672. cv::Rect(500, -50, 200, 200), // Intersection with top side
  673. cv::Rect(-100, 300, 1480, 300), // From left to right side with intersection
  674. cv::Rect(5000, 2000, 100, 100), // Outside image
  675. cv::Rect(-300, -300, 3000, 3000), // Cover all image
  676. cv::Rect(100, 100, -500, -500)), // Negative width and height
  677. Values(25),
  678. Values(0)));
  679. INSTANTIATE_TEST_CASE_P(RenderMFrameOCVTestMosaicsImpl, RenderMFrameOCVTestMosaics,
  680. Combine(Values(cv::Size(1280, 720)),
  681. Values(cv::Rect(100, 100, 200, 200), // Normal case
  682. cv::Rect(-50, -50, 200, 200), // Intersection with left-top corner
  683. cv::Rect(-50, 100, 200, 200), // Intersection with left side
  684. cv::Rect(-50, 600, 200, 200), // Intersection with left-bottom corner
  685. cv::Rect(100, 600, 200, 200), // Intersection with bottom side
  686. cv::Rect(1200, 700, 200, 200), // Intersection with right-bottom corner
  687. cv::Rect(1200, 400, 200, 200), // Intersection with right side
  688. cv::Rect(1200, -50, 200, 200), // Intersection with right-top corner
  689. cv::Rect(500, -50, 200, 200), // Intersection with top side
  690. cv::Rect(-100, 300, 1480, 300), // From left to right side with intersection
  691. cv::Rect(5000, 2000, 100, 100), // Outside image
  692. cv::Rect(-300, -300, 3000, 3000), // Cover all image
  693. cv::Rect(100, 100, -500, -500)), // Negative width and height
  694. Values(25),
  695. Values(0)));
  696. INSTANTIATE_TEST_CASE_P(RenderBGROCVTestImagesImpl, RenderBGROCVTestImages,
  697. Combine(Values(cv::Size(1280, 720)),
  698. Values(cv::Rect(100, 100, 200, 200)),
  699. Values(cv::Scalar(100, 150, 60)),
  700. Values(1.0)));
  701. INSTANTIATE_TEST_CASE_P(RenderNV12OCVTestImagesImpl, RenderNV12OCVTestImages,
  702. Combine(Values(cv::Size(1280, 720)),
  703. Values(cv::Rect(100, 100, 200, 200)),
  704. Values(cv::Scalar(100, 150, 60)),
  705. Values(1.0)));
  706. INSTANTIATE_TEST_CASE_P(RenderMFrameOCVTestImagesImpl, RenderMFrameOCVTestImages,
  707. Combine(Values(cv::Size(1280, 720)),
  708. Values(cv::Rect(100, 100, 200, 200)),
  709. Values(cv::Scalar(100, 150, 60)),
  710. Values(1.0)));
  711. INSTANTIATE_TEST_CASE_P(RenderBGROCVTestPolylinesImpl, RenderBGROCVTestPolylines,
  712. Combine(Values(cv::Size(1280, 720)),
  713. Values(std::vector<cv::Point>{{100, 100}, {200, 200}, {150, 300}, {400, 150}}),
  714. Values(cv::Scalar(100, 150, 60)),
  715. Values(2),
  716. Values(LINE_8),
  717. Values(0)));
  718. INSTANTIATE_TEST_CASE_P(RenderNV12OCVTestPolylinesImpl, RenderNV12OCVTestPolylines,
  719. Combine(Values(cv::Size(1280, 720)),
  720. Values(std::vector<cv::Point>{{100, 100}, {200, 200}, {150, 300}, {400, 150}}),
  721. Values(cv::Scalar(100, 150, 60)),
  722. Values(2),
  723. Values(LINE_8),
  724. Values(0)));
  725. INSTANTIATE_TEST_CASE_P(RenderMFrameOCVTestPolylinesImpl, RenderMFrameOCVTestPolylines,
  726. Combine(Values(cv::Size(1280, 720)),
  727. Values(std::vector<cv::Point>{ {100, 100}, { 200, 200 }, { 150, 300 }, { 400, 150 }}),
  728. Values(cv::Scalar(100, 150, 60)),
  729. Values(2),
  730. Values(LINE_8),
  731. Values(0)));
  732. }