gapi_imgproc_tests_inl.hpp 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  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_TESTS_INL_HPP
  7. #define OPENCV_GAPI_IMGPROC_TESTS_INL_HPP
  8. #include <opencv2/gapi/imgproc.hpp>
  9. #include "gapi_imgproc_tests.hpp"
  10. #include "gapi_imgproc_tests_common.hpp"
  11. namespace opencv_test
  12. {
  13. // FIXME avoid this code duplicate in perf tests
  14. namespace
  15. {
  16. void rgb2yuyv(const uchar* rgb_line, uchar* yuv422_line, int width)
  17. {
  18. CV_Assert(width % 2 == 0);
  19. for (int i = 0; i < width; i += 2)
  20. {
  21. uchar r = rgb_line[i * 3 ];
  22. uchar g = rgb_line[i * 3 + 1];
  23. uchar b = rgb_line[i * 3 + 2];
  24. yuv422_line[i * 2 ] = cv::saturate_cast<uchar>(-0.14713 * r - 0.28886 * g + 0.436 * b + 128.f); // U0
  25. yuv422_line[i * 2 + 1] = cv::saturate_cast<uchar>( 0.299 * r + 0.587 * g + 0.114 * b ); // Y0
  26. yuv422_line[i * 2 + 2] = cv::saturate_cast<uchar>( 0.615 * r - 0.51499 * g - 0.10001 * b + 128.f); // V0
  27. r = rgb_line[i * 3 + 3];
  28. g = rgb_line[i * 3 + 4];
  29. b = rgb_line[i * 3 + 5];
  30. yuv422_line[i * 2 + 3] = cv::saturate_cast<uchar>(0.299 * r + 0.587 * g + 0.114 * b); // Y1
  31. }
  32. }
  33. void convertRGB2YUV422Ref(const cv::Mat& in, cv::Mat &out)
  34. {
  35. out.create(in.size(), CV_8UC2);
  36. for (int i = 0; i < in.rows; ++i)
  37. {
  38. const uchar* in_line_p = in.ptr<uchar>(i);
  39. uchar* out_line_p = out.ptr<uchar>(i);
  40. rgb2yuyv(in_line_p, out_line_p, in.cols);
  41. }
  42. }
  43. }
  44. TEST_P(Filter2DTest, AccuracyTest)
  45. {
  46. cv::Point anchor = {-1, -1};
  47. double delta = 0;
  48. cv::Mat kernel = cv::Mat(filterSize, CV_32FC1);
  49. cv::Scalar kernMean, kernStddev;
  50. const auto kernSize = filterSize.width * filterSize.height;
  51. const auto bigKernSize = 49;
  52. if (kernSize < bigKernSize)
  53. {
  54. kernMean = cv::Scalar(0.3);
  55. kernStddev = cv::Scalar(0.5);
  56. }
  57. else
  58. {
  59. kernMean = cv::Scalar(0.008);
  60. kernStddev = cv::Scalar(0.008);
  61. }
  62. randn(kernel, kernMean, kernStddev);
  63. // G-API code //////////////////////////////////////////////////////////////
  64. cv::GMat in;
  65. auto out = cv::gapi::filter2D(in, dtype, kernel, anchor, delta, borderType);
  66. cv::GComputation c(in, out);
  67. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  68. // OpenCV code /////////////////////////////////////////////////////////////
  69. {
  70. cv::filter2D(in_mat1, out_mat_ocv, dtype, kernel, anchor, delta, borderType);
  71. }
  72. // Comparison //////////////////////////////////////////////////////////////
  73. {
  74. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  75. EXPECT_EQ(sz, out_mat_gapi.size());
  76. }
  77. }
  78. TEST_P(BoxFilterTest, AccuracyTest)
  79. {
  80. cv::Point anchor = {-1, -1};
  81. bool normalize = true;
  82. // G-API code //////////////////////////////////////////////////////////////
  83. cv::GMat in;
  84. auto out = cv::gapi::boxFilter(in, dtype, cv::Size(filterSize, filterSize), anchor, normalize,
  85. borderType);
  86. cv::GComputation c(in, out);
  87. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  88. // OpenCV code /////////////////////////////////////////////////////////////
  89. {
  90. cv::boxFilter(in_mat1, out_mat_ocv, dtype, cv::Size(filterSize, filterSize), anchor,
  91. normalize, borderType);
  92. }
  93. // Comparison //////////////////////////////////////////////////////////////
  94. {
  95. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  96. EXPECT_EQ(sz, out_mat_gapi.size());
  97. }
  98. }
  99. TEST_P(SepFilterTest, AccuracyTest)
  100. {
  101. cv::Mat kernelX(kernSize, 1, CV_32F);
  102. cv::Mat kernelY(kernSize, 1, CV_32F);
  103. randu(kernelX, -1, 1);
  104. randu(kernelY, -1, 1);
  105. cv::Point anchor = cv::Point(-1, -1);
  106. // G-API code //////////////////////////////////////////////////////////////
  107. cv::GMat in;
  108. auto out = cv::gapi::sepFilter(in, dtype, kernelX, kernelY, anchor, cv::Scalar() );
  109. cv::GComputation c(in, out);
  110. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  111. // OpenCV code /////////////////////////////////////////////////////////////
  112. {
  113. cv::sepFilter2D(in_mat1, out_mat_ocv, dtype, kernelX, kernelY );
  114. }
  115. // Comparison //////////////////////////////////////////////////////////////
  116. {
  117. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  118. EXPECT_EQ(sz, out_mat_gapi.size());
  119. }
  120. }
  121. TEST_P(BlurTest, AccuracyTest)
  122. {
  123. cv::Point anchor = {-1, -1};
  124. // G-API code //////////////////////////////////////////////////////////////
  125. cv::GMat in;
  126. auto out = cv::gapi::blur(in, cv::Size(filterSize, filterSize), anchor, borderType);
  127. cv::GComputation c(in, out);
  128. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  129. // OpenCV code /////////////////////////////////////////////////////////////
  130. {
  131. cv::blur(in_mat1, out_mat_ocv, cv::Size(filterSize, filterSize), anchor, borderType);
  132. }
  133. // Comparison //////////////////////////////////////////////////////////////
  134. {
  135. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  136. EXPECT_EQ(sz, out_mat_gapi.size());
  137. }
  138. }
  139. TEST_P(GaussianBlurTest, AccuracyTest)
  140. {
  141. cv::Size kSize = cv::Size(kernSize, kernSize);
  142. double sigmaX = rand();
  143. // G-API code //////////////////////////////////////////////////////////////
  144. cv::GMat in;
  145. auto out = cv::gapi::gaussianBlur(in, kSize, sigmaX);
  146. cv::GComputation c(in, out);
  147. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  148. // OpenCV code /////////////////////////////////////////////////////////////
  149. {
  150. cv::GaussianBlur(in_mat1, out_mat_ocv, kSize, sigmaX);
  151. }
  152. // Comparison //////////////////////////////////////////////////////////////
  153. {
  154. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  155. EXPECT_EQ(sz, out_mat_gapi.size());
  156. }
  157. }
  158. TEST_P(MedianBlurTest, AccuracyTest)
  159. {
  160. // G-API code //////////////////////////////////////////////////////////////
  161. cv::GMat in;
  162. auto out = cv::gapi::medianBlur(in, kernSize);
  163. cv::GComputation c(in, out);
  164. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  165. // OpenCV code /////////////////////////////////////////////////////////////
  166. {
  167. cv::medianBlur(in_mat1, out_mat_ocv, kernSize);
  168. }
  169. // Comparison //////////////////////////////////////////////////////////////
  170. {
  171. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  172. EXPECT_EQ(sz, out_mat_gapi.size());
  173. }
  174. }
  175. TEST_P(ErodeTest, AccuracyTest)
  176. {
  177. cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize));
  178. // G-API code //////////////////////////////////////////////////////////////
  179. cv::GMat in;
  180. auto out = cv::gapi::erode(in, kernel);
  181. cv::GComputation c(in, out);
  182. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  183. // OpenCV code /////////////////////////////////////////////////////////////
  184. {
  185. cv::erode(in_mat1, out_mat_ocv, kernel);
  186. }
  187. // Comparison //////////////////////////////////////////////////////////////
  188. {
  189. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  190. EXPECT_EQ(sz, out_mat_gapi.size());
  191. }
  192. }
  193. TEST_P(Erode3x3Test, AccuracyTest)
  194. {
  195. cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3,3));
  196. // G-API code //////////////////////////////////////////////////////////////
  197. cv::GMat in;
  198. auto out = cv::gapi::erode3x3(in, numIters);
  199. cv::GComputation c(in, out);
  200. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  201. // OpenCV code /////////////////////////////////////////////////////////////
  202. {
  203. cv::erode(in_mat1, out_mat_ocv, kernel, cv::Point(-1, -1), numIters);
  204. }
  205. // Comparison //////////////////////////////////////////////////////////////
  206. {
  207. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  208. EXPECT_EQ(sz, out_mat_gapi.size());
  209. }
  210. }
  211. TEST_P(DilateTest, AccuracyTest)
  212. {
  213. cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize));
  214. // G-API code //////////////////////////////////////////////////////////////
  215. cv::GMat in;
  216. auto out = cv::gapi::dilate(in, kernel);
  217. cv::GComputation c(in, out);
  218. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  219. // OpenCV code /////////////////////////////////////////////////////////////
  220. {
  221. cv::dilate(in_mat1, out_mat_ocv, kernel);
  222. }
  223. // Comparison //////////////////////////////////////////////////////////////
  224. {
  225. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  226. EXPECT_EQ(sz, out_mat_gapi.size());
  227. }
  228. }
  229. TEST_P(Dilate3x3Test, AccuracyTest)
  230. {
  231. cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3,3));
  232. // G-API code //////////////////////////////////////////////////////////////
  233. cv::GMat in;
  234. auto out = cv::gapi::dilate3x3(in, numIters);
  235. cv::GComputation c(in, out);
  236. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  237. // OpenCV code /////////////////////////////////////////////////////////////
  238. {
  239. cv::dilate(in_mat1, out_mat_ocv, kernel, cv::Point(-1,-1), numIters);
  240. }
  241. // Comparison //////////////////////////////////////////////////////////////
  242. {
  243. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  244. EXPECT_EQ(sz, out_mat_gapi.size());
  245. }
  246. }
  247. TEST_P(MorphologyExTest, AccuracyTest)
  248. {
  249. cv::MorphShapes defShape = cv::MORPH_RECT;
  250. int defKernSize = 3;
  251. cv::Mat kernel = cv::getStructuringElement(defShape, cv::Size(defKernSize, defKernSize));
  252. // G-API code //////////////////////////////////////////////////////////////
  253. cv::GMat in;
  254. auto out = cv::gapi::morphologyEx(in, op, kernel);
  255. cv::GComputation c(in, out);
  256. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  257. // OpenCV code /////////////////////////////////////////////////////////////
  258. {
  259. cv::morphologyEx(in_mat1, out_mat_ocv, op, kernel);
  260. }
  261. // Comparison //////////////////////////////////////////////////////////////
  262. {
  263. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  264. EXPECT_EQ(sz, out_mat_gapi.size());
  265. }
  266. }
  267. TEST_P(SobelTest, AccuracyTest)
  268. {
  269. // G-API code //////////////////////////////////////////////////////////////
  270. cv::GMat in;
  271. auto out = cv::gapi::Sobel(in, dtype, dx, dy, kernSize );
  272. cv::GComputation c(in, out);
  273. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  274. // OpenCV code /////////////////////////////////////////////////////////////
  275. {
  276. cv::Sobel(in_mat1, out_mat_ocv, dtype, dx, dy, kernSize);
  277. }
  278. // Comparison //////////////////////////////////////////////////////////////
  279. {
  280. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  281. EXPECT_EQ(sz, out_mat_gapi.size());
  282. }
  283. }
  284. TEST_P(SobelXYTest, AccuracyTest)
  285. {
  286. cv::Mat out_mat_ocv2;
  287. cv::Mat out_mat_gapi2;
  288. // G-API code //////////////////////////////////////////////////////////////
  289. cv::GMat in;
  290. auto out = cv::gapi::SobelXY(in, dtype, order, kernSize, 1, 0, border_type, border_val);
  291. cv::GComputation c(cv::GIn(in), cv::GOut(std::get<0>(out), std::get<1>(out)));
  292. c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat_gapi2), getCompileArgs());
  293. // OpenCV code /////////////////////////////////////////////////////////////
  294. {
  295. // workaround for cv::Sobel
  296. cv::Mat temp_in;
  297. if(border_type == cv::BORDER_CONSTANT)
  298. {
  299. int n_pixels = (kernSize - 1) / 2;
  300. cv::copyMakeBorder(in_mat1, temp_in, n_pixels, n_pixels, n_pixels, n_pixels, border_type, border_val);
  301. in_mat1 = temp_in(cv::Rect(n_pixels, n_pixels, in_mat1.cols, in_mat1.rows));
  302. }
  303. cv::Sobel(in_mat1, out_mat_ocv, dtype, order, 0, kernSize, 1, 0, border_type);
  304. cv::Sobel(in_mat1, out_mat_ocv2, dtype, 0, order, kernSize, 1, 0, border_type);
  305. }
  306. // Comparison //////////////////////////////////////////////////////////////
  307. {
  308. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  309. EXPECT_TRUE(cmpF(out_mat_gapi2, out_mat_ocv2));
  310. EXPECT_EQ(sz, out_mat_gapi.size());
  311. EXPECT_EQ(sz, out_mat_gapi2.size());
  312. }
  313. }
  314. TEST_P(LaplacianTest, AccuracyTest)
  315. {
  316. double delta = 10;
  317. // G-API code //////////////////////////////////////////////////////////////
  318. cv::GMat in;
  319. auto out = cv::gapi::Laplacian(in, dtype, kernSize, scale, delta, borderType);
  320. cv::GComputation c(in, out);
  321. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  322. // OpenCV code /////////////////////////////////////////////////////////////
  323. {
  324. cv::Laplacian(in_mat1, out_mat_ocv, dtype, kernSize, scale, delta, borderType);
  325. }
  326. // Comparison //////////////////////////////////////////////////////////////
  327. {
  328. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  329. EXPECT_EQ(sz, out_mat_gapi.size());
  330. }
  331. }
  332. TEST_P(BilateralFilterTest, AccuracyTest)
  333. {
  334. // G-API code //////////////////////////////////////////////////////////////
  335. cv::GMat in;
  336. auto out = cv::gapi::bilateralFilter(in, d, sigmaColor, sigmaSpace, borderType);
  337. cv::GComputation c(in, out);
  338. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  339. // OpenCV code /////////////////////////////////////////////////////////////
  340. {
  341. cv::bilateralFilter(in_mat1, out_mat_ocv, d, sigmaColor, sigmaSpace, borderType);
  342. }
  343. // Comparison //////////////////////////////////////////////////////////////
  344. {
  345. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  346. EXPECT_EQ(sz, out_mat_gapi.size());
  347. }
  348. }
  349. TEST_P(EqHistTest, AccuracyTest)
  350. {
  351. // G-API code //////////////////////////////////////////////////////////////
  352. cv::GMat in;
  353. auto out = cv::gapi::equalizeHist(in);
  354. cv::GComputation c(in, out);
  355. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  356. // OpenCV code /////////////////////////////////////////////////////////////
  357. {
  358. cv::equalizeHist(in_mat1, out_mat_ocv);
  359. }
  360. // Comparison //////////////////////////////////////////////////////////////
  361. {
  362. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  363. EXPECT_EQ(sz, out_mat_gapi.size());
  364. }
  365. }
  366. TEST_P(CannyTest, AccuracyTest)
  367. {
  368. // G-API code //////////////////////////////////////////////////////////////
  369. cv::GMat in;
  370. auto out = cv::gapi::Canny(in, thrLow, thrUp, apSize, l2gr);
  371. cv::GComputation c(in, out);
  372. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  373. // OpenCV code /////////////////////////////////////////////////////////////
  374. {
  375. cv::Canny(in_mat1, out_mat_ocv, thrLow, thrUp, apSize, l2gr);
  376. }
  377. // Comparison //////////////////////////////////////////////////////////////
  378. {
  379. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  380. EXPECT_EQ(sz, out_mat_gapi.size());
  381. }
  382. }
  383. TEST_P(GoodFeaturesTest, AccuracyTest)
  384. {
  385. double k = 0.04;
  386. initMatFromImage(type, fileName);
  387. std::vector<cv::Point2f> outVecOCV, outVecGAPI;
  388. // G-API code //////////////////////////////////////////////////////////////
  389. cv::GMat in;
  390. auto out = cv::gapi::goodFeaturesToTrack(in, maxCorners, qualityLevel, minDistance, cv::Mat(),
  391. blockSize, useHarrisDetector, k);
  392. cv::GComputation c(cv::GIn(in), cv::GOut(out));
  393. c.apply(cv::gin(in_mat1), cv::gout(outVecGAPI), getCompileArgs());
  394. // OpenCV code /////////////////////////////////////////////////////////////
  395. {
  396. cv::goodFeaturesToTrack(in_mat1, outVecOCV, maxCorners, qualityLevel, minDistance,
  397. cv::noArray(), blockSize, useHarrisDetector, k);
  398. }
  399. // Comparison //////////////////////////////////////////////////////////////
  400. {
  401. EXPECT_TRUE(cmpF(outVecGAPI, outVecOCV));
  402. }
  403. }
  404. TEST_P(FindContoursNoOffsetTest, AccuracyTest)
  405. {
  406. findContoursTestBody(sz, type, mode, method, cmpF, getCompileArgs());
  407. }
  408. TEST_P(FindContoursOffsetTest, AccuracyTest)
  409. {
  410. const cv::Size sz(1280, 720);
  411. const MatType2 type = CV_8UC1;
  412. const cv::RetrievalModes mode = cv::RETR_EXTERNAL;
  413. const cv::ContourApproximationModes method = cv::CHAIN_APPROX_NONE;
  414. const CompareMats cmpF = AbsExact().to_compare_obj();
  415. const cv::Point offset(15, 15);
  416. findContoursTestBody(sz, type, mode, method, cmpF, getCompileArgs(), offset);
  417. }
  418. TEST_P(FindContoursHNoOffsetTest, AccuracyTest)
  419. {
  420. findContoursTestBody<HIERARCHY>(sz, type, mode, method, cmpF, getCompileArgs());
  421. }
  422. TEST_P(FindContoursHOffsetTest, AccuracyTest)
  423. {
  424. const cv::Size sz(1280, 720);
  425. const MatType2 type = CV_8UC1;
  426. const cv::RetrievalModes mode = cv::RETR_EXTERNAL;
  427. const cv::ContourApproximationModes method = cv::CHAIN_APPROX_NONE;
  428. const CompareMats cmpF = AbsExact().to_compare_obj();
  429. const cv::Point offset(15, 15);
  430. std::vector<std::vector<cv::Point>> outCtsOCV, outCtsGAPI;
  431. std::vector<cv::Vec4i> outHierOCV, outHierGAPI;
  432. findContoursTestBody<HIERARCHY>(sz, type, mode, method, cmpF, getCompileArgs(), offset);
  433. }
  434. TEST_P(BoundingRectMatTest, AccuracyTest)
  435. {
  436. if (initByVector)
  437. {
  438. initMatByPointsVectorRandU<cv::Point_>(type, sz, dtype);
  439. }
  440. else
  441. {
  442. initMatrixRandU(type, sz, dtype);
  443. }
  444. boundingRectTestBody(in_mat1, cmpF, getCompileArgs());
  445. }
  446. TEST_P(BoundingRectVector32STest, AccuracyTest)
  447. {
  448. std::vector<cv::Point2i> in_vector;
  449. initPointsVectorRandU(sz.width, in_vector);
  450. boundingRectTestBody(in_vector, cmpF, getCompileArgs());
  451. }
  452. TEST_P(BoundingRectVector32FTest, AccuracyTest)
  453. {
  454. std::vector<cv::Point2f> in_vector;
  455. initPointsVectorRandU(sz.width, in_vector);
  456. boundingRectTestBody(in_vector, cmpF, getCompileArgs());
  457. }
  458. TEST_P(FitLine2DMatVectorTest, AccuracyTest)
  459. {
  460. fitLineTestBody(in_mat1, distType, cmpF, getCompileArgs());
  461. }
  462. TEST_P(FitLine2DVector32STest, AccuracyTest)
  463. {
  464. std::vector<cv::Point2i> in_vec;
  465. initPointsVectorRandU(sz.width, in_vec);
  466. fitLineTestBody(in_vec, distType, cmpF, getCompileArgs());
  467. }
  468. TEST_P(FitLine2DVector32FTest, AccuracyTest)
  469. {
  470. std::vector<cv::Point2f> in_vec;
  471. initPointsVectorRandU(sz.width, in_vec);
  472. fitLineTestBody(in_vec, distType, cmpF, getCompileArgs());
  473. }
  474. TEST_P(FitLine2DVector64FTest, AccuracyTest)
  475. {
  476. std::vector<cv::Point2d> in_vec;
  477. initPointsVectorRandU(sz.width, in_vec);
  478. fitLineTestBody(in_vec, distType, cmpF, getCompileArgs());
  479. }
  480. TEST_P(FitLine3DMatVectorTest, AccuracyTest)
  481. {
  482. fitLineTestBody(in_mat1, distType, cmpF, getCompileArgs());
  483. }
  484. TEST_P(FitLine3DVector32STest, AccuracyTest)
  485. {
  486. std::vector<cv::Point3i> in_vec;
  487. initPointsVectorRandU(sz.width, in_vec);
  488. fitLineTestBody(in_vec, distType, cmpF, getCompileArgs());
  489. }
  490. TEST_P(FitLine3DVector32FTest, AccuracyTest)
  491. {
  492. std::vector<cv::Point3f> in_vec;
  493. initPointsVectorRandU(sz.width, in_vec);
  494. fitLineTestBody(in_vec, distType, cmpF, getCompileArgs());
  495. }
  496. TEST_P(FitLine3DVector64FTest, AccuracyTest)
  497. {
  498. std::vector<cv::Point3d> in_vec;
  499. initPointsVectorRandU(sz.width, in_vec);
  500. fitLineTestBody(in_vec, distType, cmpF, getCompileArgs());
  501. }
  502. TEST_P(BGR2RGBTest, AccuracyTest)
  503. {
  504. // G-API code //////////////////////////////////////////////////////////////
  505. cv::GMat in;
  506. auto out = cv::gapi::BGR2RGB(in);
  507. cv::GComputation c(in, out);
  508. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  509. // OpenCV code /////////////////////////////////////////////////////////////
  510. {
  511. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2RGB);
  512. }
  513. // Comparison //////////////////////////////////////////////////////////////
  514. {
  515. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  516. EXPECT_EQ(sz, out_mat_gapi.size());
  517. }
  518. }
  519. TEST_P(RGB2GrayTest, AccuracyTest)
  520. {
  521. // G-API code //////////////////////////////////////////////////////////////
  522. cv::GMat in;
  523. auto out = cv::gapi::RGB2Gray(in);
  524. cv::GComputation c(in, out);
  525. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  526. // OpenCV code /////////////////////////////////////////////////////////////
  527. {
  528. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2GRAY);
  529. }
  530. // Comparison //////////////////////////////////////////////////////////////
  531. {
  532. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  533. EXPECT_EQ(sz, out_mat_gapi.size());
  534. }
  535. }
  536. TEST_P(BGR2GrayTest, AccuracyTest)
  537. {
  538. // G-API code //////////////////////////////////////////////////////////////
  539. cv::GMat in;
  540. auto out = cv::gapi::BGR2Gray(in);
  541. cv::GComputation c(in, out);
  542. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  543. // OpenCV code /////////////////////////////////////////////////////////////
  544. {
  545. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2GRAY);
  546. }
  547. // Comparison //////////////////////////////////////////////////////////////
  548. {
  549. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  550. EXPECT_EQ(sz, out_mat_gapi.size());
  551. }
  552. }
  553. TEST_P(RGB2YUVTest, AccuracyTest)
  554. {
  555. // G-API code //////////////////////////////////////////////////////////////
  556. cv::GMat in;
  557. auto out = cv::gapi::RGB2YUV(in);
  558. cv::GComputation c(in, out);
  559. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  560. // OpenCV code /////////////////////////////////////////////////////////////
  561. {
  562. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2YUV);
  563. }
  564. // Comparison //////////////////////////////////////////////////////////////
  565. {
  566. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  567. EXPECT_EQ(sz, out_mat_gapi.size());
  568. }
  569. }
  570. TEST_P(YUV2RGBTest, AccuracyTest)
  571. {
  572. // G-API code //////////////////////////////////////////////////////////////
  573. cv::GMat in;
  574. auto out = cv::gapi::YUV2RGB(in);
  575. cv::GComputation c(in, out);
  576. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  577. // OpenCV code /////////////////////////////////////////////////////////////
  578. {
  579. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2RGB);
  580. }
  581. // Comparison //////////////////////////////////////////////////////////////
  582. {
  583. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  584. EXPECT_EQ(sz, out_mat_gapi.size());
  585. }
  586. }
  587. TEST_P(BGR2I420Test, AccuracyTest)
  588. {
  589. // G-API code //////////////////////////////////////////////////////////////
  590. cv::GMat in;
  591. auto out = cv::gapi::BGR2I420(in);
  592. cv::GComputation c(in, out);
  593. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  594. // OpenCV code /////////////////////////////////////////////////////////////
  595. {
  596. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2YUV_I420);
  597. }
  598. // Comparison //////////////////////////////////////////////////////////////
  599. {
  600. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  601. EXPECT_EQ(Size(sz.width, sz.height * 3 / 2), out_mat_gapi.size());
  602. }
  603. }
  604. TEST_P(RGB2I420Test, AccuracyTest)
  605. {
  606. // G-API code //////////////////////////////////////////////////////////////
  607. cv::GMat in;
  608. auto out = cv::gapi::RGB2I420(in);
  609. cv::GComputation c(in, out);
  610. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  611. // OpenCV code /////////////////////////////////////////////////////////////
  612. {
  613. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2YUV_I420);
  614. }
  615. // Comparison //////////////////////////////////////////////////////////////
  616. {
  617. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  618. EXPECT_EQ(Size(sz.width, sz.height * 3 / 2), out_mat_gapi.size());
  619. }
  620. }
  621. TEST_P(I4202BGRTest, AccuracyTest)
  622. {
  623. // G-API code //////////////////////////////////////////////////////////////
  624. cv::GMat in;
  625. auto out = cv::gapi::I4202BGR(in);
  626. cv::GComputation c(in, out);
  627. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  628. // OpenCV code /////////////////////////////////////////////////////////////
  629. {
  630. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2BGR_I420);
  631. }
  632. // Comparison //////////////////////////////////////////////////////////////
  633. {
  634. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  635. EXPECT_EQ(Size(sz.width, sz.height * 2 / 3), out_mat_gapi.size());
  636. }
  637. }
  638. TEST_P(I4202RGBTest, AccuracyTest)
  639. {
  640. // G-API code //////////////////////////////////////////////////////////////
  641. cv::GMat in;
  642. auto out = cv::gapi::I4202RGB(in);
  643. cv::GComputation c(in, out);
  644. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  645. // OpenCV code /////////////////////////////////////////////////////////////
  646. {
  647. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2RGB_I420);
  648. }
  649. // Comparison //////////////////////////////////////////////////////////////
  650. {
  651. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  652. EXPECT_EQ(Size(sz.width, sz.height * 2 / 3), out_mat_gapi.size());
  653. }
  654. }
  655. TEST_P(NV12toRGBTest, AccuracyTest)
  656. {
  657. // G-API code //////////////////////////////////////////////////////////////
  658. cv::GMat in_y;
  659. cv::GMat in_uv;
  660. auto out = cv::gapi::NV12toRGB(in_y, in_uv);
  661. // Additional mat for uv
  662. cv::Mat in_mat_uv(cv::Size(sz.width / 2, sz.height / 2), CV_8UC2);
  663. cv::randn(in_mat_uv, cv::Scalar::all(127), cv::Scalar::all(40.f));
  664. cv::GComputation c(cv::GIn(in_y, in_uv), cv::GOut(out));
  665. c.apply(cv::gin(in_mat1, in_mat_uv), cv::gout(out_mat_gapi), getCompileArgs());
  666. // OpenCV code /////////////////////////////////////////////////////////////
  667. {
  668. cv::cvtColorTwoPlane(in_mat1, in_mat_uv, out_mat_ocv, cv::COLOR_YUV2RGB_NV12);
  669. }
  670. // Comparison //////////////////////////////////////////////////////////////
  671. {
  672. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  673. EXPECT_EQ(sz, out_mat_gapi.size());
  674. }
  675. }
  676. TEST_P(NV12toBGRTest, AccuracyTest)
  677. {
  678. // G-API code //////////////////////////////////////////////////////////////
  679. cv::GMat in_y;
  680. cv::GMat in_uv;
  681. auto out = cv::gapi::NV12toBGR(in_y, in_uv);
  682. // Additional mat for uv
  683. cv::Mat in_mat_uv(cv::Size(sz.width / 2, sz.height / 2), CV_8UC2);
  684. cv::randn(in_mat_uv, cv::Scalar::all(127), cv::Scalar::all(40.f));
  685. cv::GComputation c(cv::GIn(in_y, in_uv), cv::GOut(out));
  686. c.apply(cv::gin(in_mat1, in_mat_uv), cv::gout(out_mat_gapi), getCompileArgs());
  687. // OpenCV code /////////////////////////////////////////////////////////////
  688. {
  689. cv::cvtColorTwoPlane(in_mat1, in_mat_uv, out_mat_ocv, cv::COLOR_YUV2BGR_NV12);
  690. }
  691. // Comparison //////////////////////////////////////////////////////////////
  692. {
  693. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  694. EXPECT_EQ(sz, out_mat_gapi.size());
  695. }
  696. }
  697. TEST_P(NV12toGrayTest, AccuracyTest)
  698. {
  699. // G-API code //////////////////////////////////////////////////////////////
  700. cv::GMat in_y;
  701. cv::GMat in_uv;
  702. auto out = cv::gapi::NV12toGray(in_y, in_uv);
  703. // Additional mat for uv
  704. cv::Mat in_mat_uv(cv::Size(sz.width / 2, sz.height / 2), CV_8UC2);
  705. cv::randn(in_mat_uv, cv::Scalar::all(127), cv::Scalar::all(40.f));
  706. cv::GComputation c(cv::GIn(in_y, in_uv), cv::GOut(out));
  707. c.apply(cv::gin(in_mat1, in_mat_uv), cv::gout(out_mat_gapi), getCompileArgs());
  708. cv::Mat out_mat_ocv_planar;
  709. cv::Mat uv_planar(in_mat1.rows / 2, in_mat1.cols, CV_8UC1, in_mat_uv.data);
  710. // OpenCV code /////////////////////////////////////////////////////////////
  711. {
  712. cv::vconcat(in_mat1, uv_planar, out_mat_ocv_planar);
  713. cv::cvtColor(out_mat_ocv_planar, out_mat_ocv, cv::COLOR_YUV2GRAY_NV12);
  714. }
  715. // Comparison //////////////////////////////////////////////////////////////
  716. {
  717. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  718. EXPECT_EQ(sz, out_mat_gapi.size());
  719. }
  720. }
  721. static void toPlanar(const cv::Mat& in, cv::Mat& out)
  722. {
  723. GAPI_Assert(out.depth() == in.depth());
  724. GAPI_Assert(out.channels() == 1);
  725. GAPI_Assert(in.channels() == 3);
  726. GAPI_Assert(out.cols == in.cols);
  727. GAPI_Assert(out.rows == 3*in.rows);
  728. std::vector<cv::Mat> outs(3);
  729. for (int i = 0; i < 3; i++) {
  730. outs[i] = out(cv::Rect(0, i*in.rows, in.cols, in.rows));
  731. }
  732. cv::split(in, outs);
  733. }
  734. TEST_P(NV12toRGBpTest, AccuracyTest)
  735. {
  736. cv::Size sz_p = cv::Size(sz.width, sz.height * 3);
  737. // G-API code //////////////////////////////////////////////////////////////
  738. cv::GMat in_y;
  739. cv::GMat in_uv;
  740. auto out = cv::gapi::NV12toRGBp(in_y, in_uv);
  741. // Additional mat for uv
  742. cv::Mat in_mat_uv(cv::Size(sz.width / 2, sz.height / 2), CV_8UC2);
  743. cv::randn(in_mat_uv, cv::Scalar::all(127), cv::Scalar::all(40.f));
  744. cv::GComputation c(cv::GIn(in_y, in_uv), cv::GOut(out));
  745. cv::Mat out_mat_gapi_planar(cv::Size(sz.width, sz.height * 3), CV_8UC1);
  746. c.apply(cv::gin(in_mat1, in_mat_uv), cv::gout(out_mat_gapi_planar), getCompileArgs());
  747. // OpenCV code /////////////////////////////////////////////////////////////
  748. cv::Mat out_mat_ocv_planar(cv::Size(sz.width, sz.height * 3), CV_8UC1);
  749. {
  750. cv::cvtColorTwoPlane(in_mat1, in_mat_uv, out_mat_ocv, cv::COLOR_YUV2RGB_NV12);
  751. toPlanar(out_mat_ocv, out_mat_ocv_planar);
  752. }
  753. // Comparison //////////////////////////////////////////////////////////////
  754. {
  755. EXPECT_TRUE(cmpF(out_mat_gapi_planar, out_mat_ocv_planar));
  756. EXPECT_EQ(sz_p, out_mat_gapi_planar.size());
  757. }
  758. }
  759. TEST_P(NV12toBGRpTest, AccuracyTest)
  760. {
  761. cv::Size sz_p = cv::Size(sz.width, sz.height * 3);
  762. // G-API code //////////////////////////////////////////////////////////////
  763. cv::GMat in_y;
  764. cv::GMat in_uv;
  765. auto out = cv::gapi::NV12toBGRp(in_y, in_uv);
  766. // Additional mat for uv
  767. cv::Mat in_mat_uv(cv::Size(sz.width / 2, sz.height / 2), CV_8UC2);
  768. cv::randn(in_mat_uv, cv::Scalar::all(127), cv::Scalar::all(40.f));
  769. cv::GComputation c(cv::GIn(in_y, in_uv), cv::GOut(out));
  770. cv::Mat out_mat_gapi_planar(cv::Size(sz.width, sz.height * 3), CV_8UC1);
  771. c.apply(cv::gin(in_mat1, in_mat_uv), cv::gout(out_mat_gapi_planar), getCompileArgs());
  772. // OpenCV code /////////////////////////////////////////////////////////////
  773. cv::Mat out_mat_ocv_planar(cv::Size(sz.width, sz.height * 3), CV_8UC1);
  774. {
  775. cv::cvtColorTwoPlane(in_mat1, in_mat_uv, out_mat_ocv, cv::COLOR_YUV2BGR_NV12);
  776. toPlanar(out_mat_ocv, out_mat_ocv_planar);
  777. }
  778. // Comparison //////////////////////////////////////////////////////////////
  779. {
  780. EXPECT_TRUE(cmpF(out_mat_gapi_planar, out_mat_ocv_planar));
  781. EXPECT_EQ(sz_p, out_mat_gapi_planar.size());
  782. }
  783. }
  784. TEST_P(RGB2LabTest, AccuracyTest)
  785. {
  786. // G-API code //////////////////////////////////////////////////////////////
  787. cv::GMat in;
  788. auto out = cv::gapi::RGB2Lab(in);
  789. cv::GComputation c(in, out);
  790. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  791. // OpenCV code /////////////////////////////////////////////////////////////
  792. {
  793. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2Lab);
  794. }
  795. // Comparison //////////////////////////////////////////////////////////////
  796. {
  797. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  798. EXPECT_EQ(sz, out_mat_gapi.size());
  799. }
  800. }
  801. TEST_P(BGR2LUVTest, AccuracyTest)
  802. {
  803. // G-API code //////////////////////////////////////////////////////////////
  804. cv::GMat in;
  805. auto out = cv::gapi::BGR2LUV(in);
  806. cv::GComputation c(in, out);
  807. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  808. // OpenCV code /////////////////////////////////////////////////////////////
  809. {
  810. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2Luv);
  811. }
  812. // Comparison //////////////////////////////////////////////////////////////
  813. {
  814. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  815. EXPECT_EQ(sz, out_mat_gapi.size());
  816. }
  817. }
  818. TEST_P(LUV2BGRTest, AccuracyTest)
  819. {
  820. // G-API code //////////////////////////////////////////////////////////////
  821. cv::GMat in;
  822. auto out = cv::gapi::LUV2BGR(in);
  823. cv::GComputation c(in, out);
  824. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  825. // OpenCV code /////////////////////////////////////////////////////////////
  826. {
  827. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_Luv2BGR);
  828. }
  829. // Comparison //////////////////////////////////////////////////////////////
  830. {
  831. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  832. EXPECT_EQ(sz, out_mat_gapi.size());
  833. }
  834. }
  835. TEST_P(BGR2YUVTest, AccuracyTest)
  836. {
  837. // G-API code //////////////////////////////////////////////////////////////
  838. cv::GMat in;
  839. auto out = cv::gapi::BGR2YUV(in);
  840. cv::GComputation c(in, out);
  841. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  842. // OpenCV code /////////////////////////////////////////////////////////////
  843. {
  844. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2YUV);
  845. }
  846. // Comparison //////////////////////////////////////////////////////////////
  847. {
  848. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  849. EXPECT_EQ(sz, out_mat_gapi.size());
  850. }
  851. }
  852. TEST_P(YUV2BGRTest, AccuracyTest)
  853. {
  854. // G-API code //////////////////////////////////////////////////////////////
  855. cv::GMat in;
  856. auto out = cv::gapi::YUV2BGR(in);
  857. cv::GComputation c(in, out);
  858. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  859. // OpenCV code /////////////////////////////////////////////////////////////
  860. {
  861. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2BGR);
  862. }
  863. // Comparison //////////////////////////////////////////////////////////////
  864. {
  865. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  866. EXPECT_EQ(sz, out_mat_gapi.size());
  867. }
  868. }
  869. TEST_P(RGB2HSVTest, AccuracyTest)
  870. {
  871. // G-API code //////////////////////////////////////////////////////////////
  872. cv::GMat in;
  873. auto out = cv::gapi::RGB2HSV(in);
  874. cv::GComputation c(in, out);
  875. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  876. // OpenCV code /////////////////////////////////////////////////////////////
  877. {
  878. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2HSV);
  879. }
  880. // Comparison //////////////////////////////////////////////////////////////
  881. {
  882. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  883. EXPECT_EQ(sz, out_mat_gapi.size());
  884. }
  885. }
  886. TEST_P(BayerGR2RGBTest, AccuracyTest)
  887. {
  888. // G-API code //////////////////////////////////////////////////////////////
  889. cv::GMat in;
  890. auto out = cv::gapi::BayerGR2RGB(in);
  891. cv::GComputation c(in, out);
  892. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  893. // OpenCV code /////////////////////////////////////////////////////////////
  894. {
  895. cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BayerGR2RGB);
  896. }
  897. // Comparison //////////////////////////////////////////////////////////////
  898. {
  899. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  900. EXPECT_EQ(sz, out_mat_gapi.size());
  901. }
  902. }
  903. TEST_P(RGB2YUV422Test, AccuracyTest)
  904. {
  905. // G-API code //////////////////////////////////////////////////////////////
  906. cv::GMat in;
  907. auto out = cv::gapi::RGB2YUV422(in);
  908. cv::GComputation c(in, out);
  909. c.apply(in_mat1, out_mat_gapi, getCompileArgs());
  910. // OpenCV code /////////////////////////////////////////////////////////////
  911. {
  912. convertRGB2YUV422Ref(in_mat1, out_mat_ocv);
  913. }
  914. // Comparison //////////////////////////////////////////////////////////////
  915. {
  916. EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
  917. EXPECT_EQ(sz, out_mat_gapi.size());
  918. }
  919. }
  920. static void ResizeAccuracyTest(const CompareMats& cmpF, int type, int interp, cv::Size sz_in,
  921. cv::Size sz_out, double fx, double fy, cv::GCompileArgs&& compile_args)
  922. {
  923. cv::Mat in_mat1 (sz_in, type );
  924. cv::Scalar mean = cv::Scalar::all(127);
  925. cv::Scalar stddev = cv::Scalar::all(40.f);
  926. cv::randn(in_mat1, mean, stddev);
  927. auto out_mat_sz = sz_out.area() == 0 ? cv::Size(saturate_cast<int>(sz_in.width *fx),
  928. saturate_cast<int>(sz_in.height*fy))
  929. : sz_out;
  930. cv::Mat out_mat(out_mat_sz, type);
  931. cv::Mat out_mat_ocv(out_mat_sz, type);
  932. // G-API code //////////////////////////////////////////////////////////////
  933. cv::GMat in;
  934. auto out = cv::gapi::resize(in, sz_out, fx, fy, interp);
  935. cv::GComputation c(in, out);
  936. c.apply(in_mat1, out_mat, std::move(compile_args));
  937. // OpenCV code /////////////////////////////////////////////////////////////
  938. {
  939. cv::resize(in_mat1, out_mat_ocv, sz_out, fx, fy, interp);
  940. }
  941. // Comparison //////////////////////////////////////////////////////////////
  942. {
  943. EXPECT_TRUE(cmpF(out_mat, out_mat_ocv));
  944. }
  945. }
  946. TEST_P(ResizeTest, AccuracyTest)
  947. {
  948. ResizeAccuracyTest(cmpF, type, interp, sz, sz_out, 0.0, 0.0, getCompileArgs());
  949. }
  950. TEST_P(ResizeTestFxFy, AccuracyTest)
  951. {
  952. ResizeAccuracyTest(cmpF, type, interp, sz, cv::Size{0, 0}, fx, fy, getCompileArgs());
  953. }
  954. TEST_P(ResizePTest, AccuracyTest)
  955. {
  956. constexpr int planeNum = 3;
  957. cv::Size sz_in_p {sz.width, sz.height*planeNum};
  958. cv::Size sz_out_p{sz_out.width, sz_out.height*planeNum};
  959. cv::Mat in_mat(sz_in_p, CV_8UC1);
  960. cv::randn(in_mat, cv::Scalar::all(127.0f), cv::Scalar::all(40.f));
  961. cv::Mat out_mat (sz_out_p, CV_8UC1);
  962. cv::Mat out_mat_ocv_p(sz_out_p, CV_8UC1);
  963. cv::GMatP in;
  964. auto out = cv::gapi::resizeP(in, sz_out, interp);
  965. cv::GComputation c(cv::GIn(in), cv::GOut(out));
  966. c.compile(cv::descr_of(in_mat).asPlanar(planeNum), getCompileArgs())
  967. (cv::gin(in_mat), cv::gout(out_mat));
  968. for (int i = 0; i < planeNum; i++) {
  969. const cv::Mat in_mat_roi = in_mat(cv::Rect(0, i*sz.height, sz.width, sz.height));
  970. cv::Mat out_mat_roi = out_mat_ocv_p(cv::Rect(0, i*sz_out.height, sz_out.width, sz_out.height));
  971. cv::resize(in_mat_roi, out_mat_roi, sz_out, 0, 0, interp);
  972. }
  973. // Comparison //////////////////////////////////////////////////////////////
  974. {
  975. EXPECT_TRUE(cmpF(out_mat, out_mat_ocv_p));
  976. }
  977. }
  978. } // opencv_test
  979. #endif //OPENCV_GAPI_IMGPROC_TESTS_INL_HPP