imgproc.hpp 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678
  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_HPP
  7. #define OPENCV_GAPI_IMGPROC_HPP
  8. #include <opencv2/imgproc.hpp>
  9. #include <utility> // std::tuple
  10. #include <opencv2/gapi/gkernel.hpp>
  11. #include <opencv2/gapi/gmat.hpp>
  12. #include <opencv2/gapi/gscalar.hpp>
  13. /** \defgroup gapi_imgproc G-API Image processing functionality
  14. @{
  15. @defgroup gapi_filters Graph API: Image filters
  16. @defgroup gapi_colorconvert Graph API: Converting image from one color space to another
  17. @defgroup gapi_feature Graph API: Image Feature Detection
  18. @defgroup gapi_shape Graph API: Image Structural Analysis and Shape Descriptors
  19. @}
  20. */
  21. namespace {
  22. void validateFindingContoursMeta(const int depth, const int chan, const int mode)
  23. {
  24. GAPI_Assert(chan == 1);
  25. switch (mode)
  26. {
  27. case cv::RETR_CCOMP:
  28. GAPI_Assert(depth == CV_8U || depth == CV_32S);
  29. break;
  30. case cv::RETR_FLOODFILL:
  31. GAPI_Assert(depth == CV_32S);
  32. break;
  33. default:
  34. GAPI_Assert(depth == CV_8U);
  35. break;
  36. }
  37. }
  38. } // anonymous namespace
  39. namespace cv { namespace gapi {
  40. namespace imgproc {
  41. using GMat2 = std::tuple<GMat,GMat>;
  42. using GMat3 = std::tuple<GMat,GMat,GMat>; // FIXME: how to avoid this?
  43. using GFindContoursOutput = std::tuple<GArray<GArray<Point>>,GArray<Vec4i>>;
  44. G_TYPED_KERNEL(GFilter2D, <GMat(GMat,int,Mat,Point,Scalar,int,Scalar)>,"org.opencv.imgproc.filters.filter2D") {
  45. static GMatDesc outMeta(GMatDesc in, int ddepth, Mat, Point, Scalar, int, Scalar) {
  46. return in.withDepth(ddepth);
  47. }
  48. };
  49. G_TYPED_KERNEL(GSepFilter, <GMat(GMat,int,Mat,Mat,Point,Scalar,int,Scalar)>, "org.opencv.imgproc.filters.sepfilter") {
  50. static GMatDesc outMeta(GMatDesc in, int ddepth, Mat, Mat, Point, Scalar, int, Scalar) {
  51. return in.withDepth(ddepth);
  52. }
  53. };
  54. G_TYPED_KERNEL(GBoxFilter, <GMat(GMat,int,Size,Point,bool,int,Scalar)>, "org.opencv.imgproc.filters.boxfilter") {
  55. static GMatDesc outMeta(GMatDesc in, int ddepth, Size, Point, bool, int, Scalar) {
  56. return in.withDepth(ddepth);
  57. }
  58. };
  59. G_TYPED_KERNEL(GBlur, <GMat(GMat,Size,Point,int,Scalar)>, "org.opencv.imgproc.filters.blur"){
  60. static GMatDesc outMeta(GMatDesc in, Size, Point, int, Scalar) {
  61. return in;
  62. }
  63. };
  64. G_TYPED_KERNEL(GGaussBlur, <GMat(GMat,Size,double,double,int,Scalar)>, "org.opencv.imgproc.filters.gaussianBlur") {
  65. static GMatDesc outMeta(GMatDesc in, Size, double, double, int, Scalar) {
  66. return in;
  67. }
  68. };
  69. G_TYPED_KERNEL(GMedianBlur, <GMat(GMat,int)>, "org.opencv.imgproc.filters.medianBlur") {
  70. static GMatDesc outMeta(GMatDesc in, int) {
  71. return in;
  72. }
  73. };
  74. G_TYPED_KERNEL(GErode, <GMat(GMat,Mat,Point,int,int,Scalar)>, "org.opencv.imgproc.filters.erode") {
  75. static GMatDesc outMeta(GMatDesc in, Mat, Point, int, int, Scalar) {
  76. return in;
  77. }
  78. };
  79. G_TYPED_KERNEL(GDilate, <GMat(GMat,Mat,Point,int,int,Scalar)>, "org.opencv.imgproc.filters.dilate") {
  80. static GMatDesc outMeta(GMatDesc in, Mat, Point, int, int, Scalar) {
  81. return in;
  82. }
  83. };
  84. G_TYPED_KERNEL(GMorphologyEx, <GMat(GMat,MorphTypes,Mat,Point,int,BorderTypes,Scalar)>,
  85. "org.opencv.imgproc.filters.morphologyEx") {
  86. static GMatDesc outMeta(const GMatDesc &in, MorphTypes, Mat, Point, int,
  87. BorderTypes, Scalar) {
  88. return in;
  89. }
  90. };
  91. G_TYPED_KERNEL(GSobel, <GMat(GMat,int,int,int,int,double,double,int,Scalar)>, "org.opencv.imgproc.filters.sobel") {
  92. static GMatDesc outMeta(GMatDesc in, int ddepth, int, int, int, double, double, int, Scalar) {
  93. return in.withDepth(ddepth);
  94. }
  95. };
  96. G_TYPED_KERNEL_M(GSobelXY, <GMat2(GMat,int,int,int,double,double,int,Scalar)>, "org.opencv.imgproc.filters.sobelxy") {
  97. static std::tuple<GMatDesc, GMatDesc> outMeta(GMatDesc in, int ddepth, int, int, double, double, int, Scalar) {
  98. return std::make_tuple(in.withDepth(ddepth), in.withDepth(ddepth));
  99. }
  100. };
  101. G_TYPED_KERNEL(GLaplacian, <GMat(GMat,int, int, double, double, int)>,
  102. "org.opencv.imgproc.filters.laplacian") {
  103. static GMatDesc outMeta(GMatDesc in, int ddepth, int, double, double, int) {
  104. return in.withDepth(ddepth);
  105. }
  106. };
  107. G_TYPED_KERNEL(GBilateralFilter, <GMat(GMat,int, double, double, int)>,
  108. "org.opencv.imgproc.filters.bilateralfilter") {
  109. static GMatDesc outMeta(GMatDesc in, int, double, double, int) {
  110. return in;
  111. }
  112. };
  113. G_TYPED_KERNEL(GEqHist, <GMat(GMat)>, "org.opencv.imgproc.equalizeHist"){
  114. static GMatDesc outMeta(GMatDesc in) {
  115. return in.withType(CV_8U, 1);
  116. }
  117. };
  118. G_TYPED_KERNEL(GCanny, <GMat(GMat,double,double,int,bool)>, "org.opencv.imgproc.feature.canny"){
  119. static GMatDesc outMeta(GMatDesc in, double, double, int, bool) {
  120. return in.withType(CV_8U, 1);
  121. }
  122. };
  123. G_TYPED_KERNEL(GGoodFeatures,
  124. <cv::GArray<cv::Point2f>(GMat,int,double,double,Mat,int,bool,double)>,
  125. "org.opencv.imgproc.feature.goodFeaturesToTrack") {
  126. static GArrayDesc outMeta(GMatDesc, int, double, double, const Mat&, int, bool, double) {
  127. return empty_array_desc();
  128. }
  129. };
  130. using RetrMode = RetrievalModes;
  131. using ContMethod = ContourApproximationModes;
  132. G_TYPED_KERNEL(GFindContours, <GArray<GArray<Point>>(GMat,RetrMode,ContMethod,GOpaque<Point>)>,
  133. "org.opencv.imgproc.shape.findContours")
  134. {
  135. static GArrayDesc outMeta(GMatDesc in, RetrMode mode, ContMethod, GOpaqueDesc)
  136. {
  137. validateFindingContoursMeta(in.depth, in.chan, mode);
  138. return empty_array_desc();
  139. }
  140. };
  141. // FIXME oc: make default value offset = Point()
  142. G_TYPED_KERNEL(GFindContoursNoOffset, <GArray<GArray<Point>>(GMat,RetrMode,ContMethod)>,
  143. "org.opencv.imgproc.shape.findContoursNoOffset")
  144. {
  145. static GArrayDesc outMeta(GMatDesc in, RetrMode mode, ContMethod)
  146. {
  147. validateFindingContoursMeta(in.depth, in.chan, mode);
  148. return empty_array_desc();
  149. }
  150. };
  151. G_TYPED_KERNEL(GFindContoursH,<GFindContoursOutput(GMat,RetrMode,ContMethod,GOpaque<Point>)>,
  152. "org.opencv.imgproc.shape.findContoursH")
  153. {
  154. static std::tuple<GArrayDesc,GArrayDesc>
  155. outMeta(GMatDesc in, RetrMode mode, ContMethod, GOpaqueDesc)
  156. {
  157. validateFindingContoursMeta(in.depth, in.chan, mode);
  158. return std::make_tuple(empty_array_desc(), empty_array_desc());
  159. }
  160. };
  161. // FIXME oc: make default value offset = Point()
  162. G_TYPED_KERNEL(GFindContoursHNoOffset,<GFindContoursOutput(GMat,RetrMode,ContMethod)>,
  163. "org.opencv.imgproc.shape.findContoursHNoOffset")
  164. {
  165. static std::tuple<GArrayDesc,GArrayDesc>
  166. outMeta(GMatDesc in, RetrMode mode, ContMethod)
  167. {
  168. validateFindingContoursMeta(in.depth, in.chan, mode);
  169. return std::make_tuple(empty_array_desc(), empty_array_desc());
  170. }
  171. };
  172. G_TYPED_KERNEL(GBoundingRectMat, <GOpaque<Rect>(GMat)>,
  173. "org.opencv.imgproc.shape.boundingRectMat") {
  174. static GOpaqueDesc outMeta(GMatDesc in) {
  175. if (in.depth == CV_8U)
  176. {
  177. GAPI_Assert(in.chan == 1);
  178. }
  179. else
  180. {
  181. GAPI_Assert (in.depth == CV_32S || in.depth == CV_32F);
  182. int amount = detail::checkVector(in, 2u);
  183. GAPI_Assert(amount != -1 &&
  184. "Input Mat can't be described as vector of 2-dimentional points");
  185. }
  186. return empty_gopaque_desc();
  187. }
  188. };
  189. G_TYPED_KERNEL(GBoundingRectVector32S, <GOpaque<Rect>(GArray<Point2i>)>,
  190. "org.opencv.imgproc.shape.boundingRectVector32S") {
  191. static GOpaqueDesc outMeta(GArrayDesc) {
  192. return empty_gopaque_desc();
  193. }
  194. };
  195. G_TYPED_KERNEL(GBoundingRectVector32F, <GOpaque<Rect>(GArray<Point2f>)>,
  196. "org.opencv.imgproc.shape.boundingRectVector32F") {
  197. static GOpaqueDesc outMeta(GArrayDesc) {
  198. return empty_gopaque_desc();
  199. }
  200. };
  201. G_TYPED_KERNEL(GFitLine2DMat, <GOpaque<Vec4f>(GMat,DistanceTypes,double,double,double)>,
  202. "org.opencv.imgproc.shape.fitLine2DMat") {
  203. static GOpaqueDesc outMeta(GMatDesc in,DistanceTypes,double,double,double) {
  204. int amount = detail::checkVector(in, 2u);
  205. GAPI_Assert(amount != -1 &&
  206. "Input Mat can't be described as vector of 2-dimentional points");
  207. return empty_gopaque_desc();
  208. }
  209. };
  210. G_TYPED_KERNEL(GFitLine2DVector32S,
  211. <GOpaque<Vec4f>(GArray<Point2i>,DistanceTypes,double,double,double)>,
  212. "org.opencv.imgproc.shape.fitLine2DVector32S") {
  213. static GOpaqueDesc outMeta(GArrayDesc,DistanceTypes,double,double,double) {
  214. return empty_gopaque_desc();
  215. }
  216. };
  217. G_TYPED_KERNEL(GFitLine2DVector32F,
  218. <GOpaque<Vec4f>(GArray<Point2f>,DistanceTypes,double,double,double)>,
  219. "org.opencv.imgproc.shape.fitLine2DVector32F") {
  220. static GOpaqueDesc outMeta(GArrayDesc,DistanceTypes,double,double,double) {
  221. return empty_gopaque_desc();
  222. }
  223. };
  224. G_TYPED_KERNEL(GFitLine2DVector64F,
  225. <GOpaque<Vec4f>(GArray<Point2d>,DistanceTypes,double,double,double)>,
  226. "org.opencv.imgproc.shape.fitLine2DVector64F") {
  227. static GOpaqueDesc outMeta(GArrayDesc,DistanceTypes,double,double,double) {
  228. return empty_gopaque_desc();
  229. }
  230. };
  231. G_TYPED_KERNEL(GFitLine3DMat, <GOpaque<Vec6f>(GMat,DistanceTypes,double,double,double)>,
  232. "org.opencv.imgproc.shape.fitLine3DMat") {
  233. static GOpaqueDesc outMeta(GMatDesc in,int,double,double,double) {
  234. int amount = detail::checkVector(in, 3u);
  235. GAPI_Assert(amount != -1 &&
  236. "Input Mat can't be described as vector of 3-dimentional points");
  237. return empty_gopaque_desc();
  238. }
  239. };
  240. G_TYPED_KERNEL(GFitLine3DVector32S,
  241. <GOpaque<Vec6f>(GArray<Point3i>,DistanceTypes,double,double,double)>,
  242. "org.opencv.imgproc.shape.fitLine3DVector32S") {
  243. static GOpaqueDesc outMeta(GArrayDesc,DistanceTypes,double,double,double) {
  244. return empty_gopaque_desc();
  245. }
  246. };
  247. G_TYPED_KERNEL(GFitLine3DVector32F,
  248. <GOpaque<Vec6f>(GArray<Point3f>,DistanceTypes,double,double,double)>,
  249. "org.opencv.imgproc.shape.fitLine3DVector32F") {
  250. static GOpaqueDesc outMeta(GArrayDesc,DistanceTypes,double,double,double) {
  251. return empty_gopaque_desc();
  252. }
  253. };
  254. G_TYPED_KERNEL(GFitLine3DVector64F,
  255. <GOpaque<Vec6f>(GArray<Point3d>,DistanceTypes,double,double,double)>,
  256. "org.opencv.imgproc.shape.fitLine3DVector64F") {
  257. static GOpaqueDesc outMeta(GArrayDesc,DistanceTypes,double,double,double) {
  258. return empty_gopaque_desc();
  259. }
  260. };
  261. G_TYPED_KERNEL(GBGR2RGB, <GMat(GMat)>, "org.opencv.imgproc.colorconvert.bgr2rgb") {
  262. static GMatDesc outMeta(GMatDesc in) {
  263. return in; // type still remains CV_8UC3;
  264. }
  265. };
  266. G_TYPED_KERNEL(GRGB2YUV, <GMat(GMat)>, "org.opencv.imgproc.colorconvert.rgb2yuv") {
  267. static GMatDesc outMeta(GMatDesc in) {
  268. return in; // type still remains CV_8UC3;
  269. }
  270. };
  271. G_TYPED_KERNEL(GYUV2RGB, <GMat(GMat)>, "org.opencv.imgproc.colorconvert.yuv2rgb") {
  272. static GMatDesc outMeta(GMatDesc in) {
  273. return in; // type still remains CV_8UC3;
  274. }
  275. };
  276. G_TYPED_KERNEL(GBGR2I420, <GMat(GMat)>, "org.opencv.imgproc.colorconvert.bgr2i420") {
  277. static GMatDesc outMeta(GMatDesc in) {
  278. GAPI_Assert(in.depth == CV_8U);
  279. GAPI_Assert(in.chan == 3);
  280. GAPI_Assert(in.size.height % 2 == 0);
  281. return in.withType(in.depth, 1).withSize(Size(in.size.width, in.size.height * 3 / 2));
  282. }
  283. };
  284. G_TYPED_KERNEL(GRGB2I420, <GMat(GMat)>, "org.opencv.imgproc.colorconvert.rgb2i420") {
  285. static GMatDesc outMeta(GMatDesc in) {
  286. GAPI_Assert(in.depth == CV_8U);
  287. GAPI_Assert(in.chan == 3);
  288. GAPI_Assert(in.size.height % 2 == 0);
  289. return in.withType(in.depth, 1).withSize(Size(in.size.width, in.size.height * 3 / 2));
  290. }
  291. };
  292. G_TYPED_KERNEL(GI4202BGR, <GMat(GMat)>, "org.opencv.imgproc.colorconvert.i4202bgr") {
  293. static GMatDesc outMeta(GMatDesc in) {
  294. GAPI_Assert(in.depth == CV_8U);
  295. GAPI_Assert(in.chan == 1);
  296. GAPI_Assert(in.size.height % 3 == 0);
  297. return in.withType(in.depth, 3).withSize(Size(in.size.width, in.size.height * 2 / 3));
  298. }
  299. };
  300. G_TYPED_KERNEL(GI4202RGB, <GMat(GMat)>, "org.opencv.imgproc.colorconvert.i4202rgb") {
  301. static GMatDesc outMeta(GMatDesc in) {
  302. GAPI_Assert(in.depth == CV_8U);
  303. GAPI_Assert(in.chan == 1);
  304. GAPI_Assert(in.size.height % 3 == 0);
  305. return in.withType(in.depth, 3).withSize(Size(in.size.width, in.size.height * 2 / 3));
  306. }
  307. };
  308. G_TYPED_KERNEL(GNV12toRGB, <GMat(GMat, GMat)>, "org.opencv.imgproc.colorconvert.nv12torgb") {
  309. static GMatDesc outMeta(GMatDesc in_y, GMatDesc in_uv) {
  310. GAPI_Assert(in_y.chan == 1);
  311. GAPI_Assert(in_uv.chan == 2);
  312. GAPI_Assert(in_y.depth == CV_8U);
  313. GAPI_Assert(in_uv.depth == CV_8U);
  314. // UV size should be aligned with Y
  315. GAPI_Assert(in_y.size.width == 2 * in_uv.size.width);
  316. GAPI_Assert(in_y.size.height == 2 * in_uv.size.height);
  317. return in_y.withType(CV_8U, 3); // type will be CV_8UC3;
  318. }
  319. };
  320. G_TYPED_KERNEL(GNV12toBGR, <GMat(GMat, GMat)>, "org.opencv.imgproc.colorconvert.nv12tobgr") {
  321. static GMatDesc outMeta(GMatDesc in_y, GMatDesc in_uv) {
  322. GAPI_Assert(in_y.chan == 1);
  323. GAPI_Assert(in_uv.chan == 2);
  324. GAPI_Assert(in_y.depth == CV_8U);
  325. GAPI_Assert(in_uv.depth == CV_8U);
  326. // UV size should be aligned with Y
  327. GAPI_Assert(in_y.size.width == 2 * in_uv.size.width);
  328. GAPI_Assert(in_y.size.height == 2 * in_uv.size.height);
  329. return in_y.withType(CV_8U, 3); // type will be CV_8UC3;
  330. }
  331. };
  332. G_TYPED_KERNEL(GRGB2Lab, <GMat(GMat)>, "org.opencv.imgproc.colorconvert.rgb2lab") {
  333. static GMatDesc outMeta(GMatDesc in) {
  334. return in; // type still remains CV_8UC3;
  335. }
  336. };
  337. G_TYPED_KERNEL(GBGR2LUV, <GMat(GMat)>, "org.opencv.imgproc.colorconvert.bgr2luv") {
  338. static GMatDesc outMeta(GMatDesc in) {
  339. return in; // type still remains CV_8UC3;
  340. }
  341. };
  342. G_TYPED_KERNEL(GLUV2BGR, <GMat(GMat)>, "org.opencv.imgproc.colorconvert.luv2bgr") {
  343. static GMatDesc outMeta(GMatDesc in) {
  344. return in; // type still remains CV_8UC3;
  345. }
  346. };
  347. G_TYPED_KERNEL(GYUV2BGR, <GMat(GMat)>, "org.opencv.imgproc.colorconvert.yuv2bgr") {
  348. static GMatDesc outMeta(GMatDesc in) {
  349. return in; // type still remains CV_8UC3;
  350. }
  351. };
  352. G_TYPED_KERNEL(GBGR2YUV, <GMat(GMat)>, "org.opencv.imgproc.colorconvert.bgr2yuv") {
  353. static GMatDesc outMeta(GMatDesc in) {
  354. return in; // type still remains CV_8UC3;
  355. }
  356. };
  357. G_TYPED_KERNEL(GRGB2Gray, <GMat(GMat)>, "org.opencv.imgproc.colorconvert.rgb2gray") {
  358. static GMatDesc outMeta(GMatDesc in) {
  359. return in.withType(CV_8U, 1);
  360. }
  361. };
  362. G_TYPED_KERNEL(GRGB2GrayCustom, <GMat(GMat,float,float,float)>, "org.opencv.imgproc.colorconvert.rgb2graycustom") {
  363. static GMatDesc outMeta(GMatDesc in, float, float, float) {
  364. return in.withType(CV_8U, 1);
  365. }
  366. };
  367. G_TYPED_KERNEL(GBGR2Gray, <GMat(GMat)>, "org.opencv.imgproc.colorconvert.bgr2gray") {
  368. static GMatDesc outMeta(GMatDesc in) {
  369. return in.withType(CV_8U, 1);
  370. }
  371. };
  372. G_TYPED_KERNEL(GBayerGR2RGB, <cv::GMat(cv::GMat)>, "org.opencv.imgproc.colorconvert.bayergr2rgb") {
  373. static cv::GMatDesc outMeta(cv::GMatDesc in) {
  374. return in.withType(CV_8U, 3);
  375. }
  376. };
  377. G_TYPED_KERNEL(GRGB2HSV, <cv::GMat(cv::GMat)>, "org.opencv.imgproc.colorconvert.rgb2hsv") {
  378. static cv::GMatDesc outMeta(cv::GMatDesc in) {
  379. return in;
  380. }
  381. };
  382. G_TYPED_KERNEL(GRGB2YUV422, <cv::GMat(cv::GMat)>, "org.opencv.imgproc.colorconvert.rgb2yuv422") {
  383. static cv::GMatDesc outMeta(cv::GMatDesc in) {
  384. GAPI_Assert(in.depth == CV_8U);
  385. GAPI_Assert(in.chan == 3);
  386. return in.withType(in.depth, 2);
  387. }
  388. };
  389. G_TYPED_KERNEL(GNV12toRGBp, <GMatP(GMat,GMat)>, "org.opencv.imgproc.colorconvert.nv12torgbp") {
  390. static GMatDesc outMeta(GMatDesc inY, GMatDesc inUV) {
  391. GAPI_Assert(inY.depth == CV_8U);
  392. GAPI_Assert(inUV.depth == CV_8U);
  393. GAPI_Assert(inY.chan == 1);
  394. GAPI_Assert(inY.planar == false);
  395. GAPI_Assert(inUV.chan == 2);
  396. GAPI_Assert(inUV.planar == false);
  397. GAPI_Assert(inY.size.width == 2 * inUV.size.width);
  398. GAPI_Assert(inY.size.height == 2 * inUV.size.height);
  399. return inY.withType(CV_8U, 3).asPlanar();
  400. }
  401. };
  402. G_TYPED_KERNEL(GNV12toGray, <GMat(GMat,GMat)>, "org.opencv.imgproc.colorconvert.nv12togray") {
  403. static GMatDesc outMeta(GMatDesc inY, GMatDesc inUV) {
  404. GAPI_Assert(inY.depth == CV_8U);
  405. GAPI_Assert(inUV.depth == CV_8U);
  406. GAPI_Assert(inY.chan == 1);
  407. GAPI_Assert(inY.planar == false);
  408. GAPI_Assert(inUV.chan == 2);
  409. GAPI_Assert(inUV.planar == false);
  410. GAPI_Assert(inY.size.width == 2 * inUV.size.width);
  411. GAPI_Assert(inY.size.height == 2 * inUV.size.height);
  412. return inY.withType(CV_8U, 1);
  413. }
  414. };
  415. G_TYPED_KERNEL(GNV12toBGRp, <GMatP(GMat,GMat)>, "org.opencv.imgproc.colorconvert.nv12tobgrp") {
  416. static GMatDesc outMeta(GMatDesc inY, GMatDesc inUV) {
  417. GAPI_Assert(inY.depth == CV_8U);
  418. GAPI_Assert(inUV.depth == CV_8U);
  419. GAPI_Assert(inY.chan == 1);
  420. GAPI_Assert(inY.planar == false);
  421. GAPI_Assert(inUV.chan == 2);
  422. GAPI_Assert(inUV.planar == false);
  423. GAPI_Assert(inY.size.width == 2 * inUV.size.width);
  424. GAPI_Assert(inY.size.height == 2 * inUV.size.height);
  425. return inY.withType(CV_8U, 3).asPlanar();
  426. }
  427. };
  428. } //namespace imgproc
  429. //! @addtogroup gapi_filters
  430. //! @{
  431. /** @brief Applies a separable linear filter to a matrix(image).
  432. The function applies a separable linear filter to the matrix. That is, first, every row of src is
  433. filtered with the 1D kernel kernelX. Then, every column of the result is filtered with the 1D
  434. kernel kernelY. The final result is returned.
  435. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  436. Output image must have the same type, size, and number of channels as the input image.
  437. @note
  438. - In case of floating-point computation, rounding to nearest even is procedeed
  439. if hardware supports it (if not - to nearest value).
  440. - Function textual ID is "org.opencv.imgproc.filters.sepfilter"
  441. @param src Source image.
  442. @param ddepth desired depth of the destination image (the following combinations of src.depth() and ddepth are supported:
  443. src.depth() = CV_8U, ddepth = -1/CV_16S/CV_32F/CV_64F
  444. src.depth() = CV_16U/CV_16S, ddepth = -1/CV_32F/CV_64F
  445. src.depth() = CV_32F, ddepth = -1/CV_32F/CV_64F
  446. src.depth() = CV_64F, ddepth = -1/CV_64F
  447. when ddepth=-1, the output image will have the same depth as the source)
  448. @param kernelX Coefficients for filtering each row.
  449. @param kernelY Coefficients for filtering each column.
  450. @param anchor Anchor position within the kernel. The default value \f$(-1,-1)\f$ means that the anchor
  451. is at the kernel center.
  452. @param delta Value added to the filtered results before storing them.
  453. @param borderType Pixel extrapolation method, see cv::BorderTypes
  454. @param borderValue border value in case of constant border type
  455. @sa boxFilter, gaussianBlur, medianBlur
  456. */
  457. GAPI_EXPORTS GMat sepFilter(const GMat& src, int ddepth, const Mat& kernelX, const Mat& kernelY, const Point& anchor /*FIXME: = Point(-1,-1)*/,
  458. const Scalar& delta /*FIXME = GScalar(0)*/, int borderType = BORDER_DEFAULT,
  459. const Scalar& borderValue = Scalar(0));
  460. /** @brief Convolves an image with the kernel.
  461. The function applies an arbitrary linear filter to an image. When
  462. the aperture is partially outside the image, the function interpolates outlier pixel values
  463. according to the specified border mode.
  464. The function does actually compute correlation, not the convolution:
  465. \f[\texttt{dst} (x,y) = \sum _{ \substack{0\leq x' < \texttt{kernel.cols}\\{0\leq y' < \texttt{kernel.rows}}}} \texttt{kernel} (x',y')* \texttt{src} (x+x'- \texttt{anchor.x} ,y+y'- \texttt{anchor.y} )\f]
  466. That is, the kernel is not mirrored around the anchor point. If you need a real convolution, flip
  467. the kernel using flip and set the new anchor to `(kernel.cols - anchor.x - 1, kernel.rows -
  468. anchor.y - 1)`.
  469. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  470. Output image must have the same size and number of channels an input image.
  471. @note
  472. - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest.
  473. - Function textual ID is "org.opencv.imgproc.filters.filter2D"
  474. @param src input image.
  475. @param ddepth desired depth of the destination image
  476. @param kernel convolution kernel (or rather a correlation kernel), a single-channel floating point
  477. matrix; if you want to apply different kernels to different channels, split the image into
  478. separate color planes using split and process them individually.
  479. @param anchor anchor of the kernel that indicates the relative position of a filtered point within
  480. the kernel; the anchor should lie within the kernel; default value (-1,-1) means that the anchor
  481. is at the kernel center.
  482. @param delta optional value added to the filtered pixels before storing them in dst.
  483. @param borderType pixel extrapolation method, see cv::BorderTypes
  484. @param borderValue border value in case of constant border type
  485. @sa sepFilter
  486. */
  487. GAPI_EXPORTS GMat filter2D(const GMat& src, int ddepth, const Mat& kernel, const Point& anchor = Point(-1,-1), const Scalar& delta = Scalar(0),
  488. int borderType = BORDER_DEFAULT, const Scalar& borderValue = Scalar(0));
  489. /** @brief Blurs an image using the box filter.
  490. The function smooths an image using the kernel:
  491. \f[\texttt{K} = \alpha \begin{bmatrix} 1 & 1 & 1 & \cdots & 1 & 1 \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \hdotsfor{6} \\ 1 & 1 & 1 & \cdots & 1 & 1 \end{bmatrix}\f]
  492. where
  493. \f[\alpha = \begin{cases} \frac{1}{\texttt{ksize.width*ksize.height}} & \texttt{when } \texttt{normalize=true} \\1 & \texttt{otherwise} \end{cases}\f]
  494. Unnormalized box filter is useful for computing various integral characteristics over each pixel
  495. neighborhood, such as covariance matrices of image derivatives (used in dense optical flow
  496. algorithms, and so on). If you need to compute pixel sums over variable-size windows, use cv::integral.
  497. Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  498. Output image must have the same type, size, and number of channels as the input image.
  499. @note
  500. - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest.
  501. - Function textual ID is "org.opencv.imgproc.filters.boxfilter"
  502. @param src Source image.
  503. @param dtype the output image depth (-1 to set the input image data type).
  504. @param ksize blurring kernel size.
  505. @param anchor Anchor position within the kernel. The default value \f$(-1,-1)\f$ means that the anchor
  506. is at the kernel center.
  507. @param normalize flag, specifying whether the kernel is normalized by its area or not.
  508. @param borderType Pixel extrapolation method, see cv::BorderTypes
  509. @param borderValue border value in case of constant border type
  510. @sa sepFilter, gaussianBlur, medianBlur, integral
  511. */
  512. GAPI_EXPORTS GMat boxFilter(const GMat& src, int dtype, const Size& ksize, const Point& anchor = Point(-1,-1),
  513. bool normalize = true, int borderType = BORDER_DEFAULT,
  514. const Scalar& borderValue = Scalar(0));
  515. /** @brief Blurs an image using the normalized box filter.
  516. The function smooths an image using the kernel:
  517. \f[\texttt{K} = \frac{1}{\texttt{ksize.width*ksize.height}} \begin{bmatrix} 1 & 1 & 1 & \cdots & 1 & 1 \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \hdotsfor{6} \\ 1 & 1 & 1 & \cdots & 1 & 1 \\ \end{bmatrix}\f]
  518. The call `blur(src, ksize, anchor, borderType)` is equivalent to `boxFilter(src, src.type(), ksize, anchor,
  519. true, borderType)`.
  520. Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  521. Output image must have the same type, size, and number of channels as the input image.
  522. @note
  523. - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest.
  524. - Function textual ID is "org.opencv.imgproc.filters.blur"
  525. @param src Source image.
  526. @param ksize blurring kernel size.
  527. @param anchor anchor point; default value Point(-1,-1) means that the anchor is at the kernel
  528. center.
  529. @param borderType border mode used to extrapolate pixels outside of the image, see cv::BorderTypes
  530. @param borderValue border value in case of constant border type
  531. @sa boxFilter, bilateralFilter, GaussianBlur, medianBlur
  532. */
  533. GAPI_EXPORTS GMat blur(const GMat& src, const Size& ksize, const Point& anchor = Point(-1,-1),
  534. int borderType = BORDER_DEFAULT, const Scalar& borderValue = Scalar(0));
  535. //GAPI_EXPORTS_W void blur( InputArray src, OutputArray dst,
  536. // Size ksize, Point anchor = Point(-1,-1),
  537. // int borderType = BORDER_DEFAULT );
  538. /** @brief Blurs an image using a Gaussian filter.
  539. The function filter2Ds the source image with the specified Gaussian kernel.
  540. Output image must have the same type and number of channels an input image.
  541. Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  542. Output image must have the same type, size, and number of channels as the input image.
  543. @note
  544. - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest.
  545. - Function textual ID is "org.opencv.imgproc.filters.gaussianBlur"
  546. @param src input image;
  547. @param ksize Gaussian kernel size. ksize.width and ksize.height can differ but they both must be
  548. positive and odd. Or, they can be zero's and then they are computed from sigma.
  549. @param sigmaX Gaussian kernel standard deviation in X direction.
  550. @param sigmaY Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be
  551. equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height,
  552. respectively (see cv::getGaussianKernel for details); to fully control the result regardless of
  553. possible future modifications of all this semantics, it is recommended to specify all of ksize,
  554. sigmaX, and sigmaY.
  555. @param borderType pixel extrapolation method, see cv::BorderTypes
  556. @param borderValue border value in case of constant border type
  557. @sa sepFilter, boxFilter, medianBlur
  558. */
  559. GAPI_EXPORTS GMat gaussianBlur(const GMat& src, const Size& ksize, double sigmaX, double sigmaY = 0,
  560. int borderType = BORDER_DEFAULT, const Scalar& borderValue = Scalar(0));
  561. /** @brief Blurs an image using the median filter.
  562. The function smoothes an image using the median filter with the \f$\texttt{ksize} \times
  563. \texttt{ksize}\f$ aperture. Each channel of a multi-channel image is processed independently.
  564. Output image must have the same type, size, and number of channels as the input image.
  565. @note
  566. - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest.
  567. The median filter uses cv::BORDER_REPLICATE internally to cope with border pixels, see cv::BorderTypes
  568. - Function textual ID is "org.opencv.imgproc.filters.medianBlur"
  569. @param src input matrix (image)
  570. @param ksize aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 ...
  571. @sa boxFilter, gaussianBlur
  572. */
  573. GAPI_EXPORTS_W GMat medianBlur(const GMat& src, int ksize);
  574. /** @brief Erodes an image by using a specific structuring element.
  575. The function erodes the source image using the specified structuring element that determines the
  576. shape of a pixel neighborhood over which the minimum is taken:
  577. \f[\texttt{dst} (x,y) = \min _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f]
  578. Erosion can be applied several (iterations) times. In case of multi-channel images, each channel is processed independently.
  579. Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, and @ref CV_32FC1.
  580. Output image must have the same type, size, and number of channels as the input image.
  581. @note
  582. - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest.
  583. - Function textual ID is "org.opencv.imgproc.filters.erode"
  584. @param src input image
  585. @param kernel structuring element used for erosion; if `element=Mat()`, a `3 x 3` rectangular
  586. structuring element is used. Kernel can be created using getStructuringElement.
  587. @param anchor position of the anchor within the element; default value (-1, -1) means that the
  588. anchor is at the element center.
  589. @param iterations number of times erosion is applied.
  590. @param borderType pixel extrapolation method, see cv::BorderTypes
  591. @param borderValue border value in case of a constant border
  592. @sa dilate, morphologyEx
  593. */
  594. GAPI_EXPORTS GMat erode(const GMat& src, const Mat& kernel, const Point& anchor = Point(-1,-1), int iterations = 1,
  595. int borderType = BORDER_CONSTANT,
  596. const Scalar& borderValue = morphologyDefaultBorderValue());
  597. /** @brief Erodes an image by using 3 by 3 rectangular structuring element.
  598. The function erodes the source image using the rectangular structuring element with rectangle center as an anchor.
  599. Erosion can be applied several (iterations) times. In case of multi-channel images, each channel is processed independently.
  600. Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, and @ref CV_32FC1.
  601. Output image must have the same type, size, and number of channels as the input image.
  602. @note
  603. - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest.
  604. - Function textual ID is "org.opencv.imgproc.filters.erode"
  605. @param src input image
  606. @param iterations number of times erosion is applied.
  607. @param borderType pixel extrapolation method, see cv::BorderTypes
  608. @param borderValue border value in case of a constant border
  609. @sa erode, dilate3x3
  610. */
  611. GAPI_EXPORTS GMat erode3x3(const GMat& src, int iterations = 1,
  612. int borderType = BORDER_CONSTANT,
  613. const Scalar& borderValue = morphologyDefaultBorderValue());
  614. /** @brief Dilates an image by using a specific structuring element.
  615. The function dilates the source image using the specified structuring element that determines the
  616. shape of a pixel neighborhood over which the maximum is taken:
  617. \f[\texttt{dst} (x,y) = \max _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f]
  618. Dilation can be applied several (iterations) times. In case of multi-channel images, each channel is processed independently.
  619. Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, and @ref CV_32FC1.
  620. Output image must have the same type, size, and number of channels as the input image.
  621. @note
  622. - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest.
  623. - Function textual ID is "org.opencv.imgproc.filters.dilate"
  624. @param src input image.
  625. @param kernel structuring element used for dilation; if elemenat=Mat(), a 3 x 3 rectangular
  626. structuring element is used. Kernel can be created using getStructuringElement
  627. @param anchor position of the anchor within the element; default value (-1, -1) means that the
  628. anchor is at the element center.
  629. @param iterations number of times dilation is applied.
  630. @param borderType pixel extrapolation method, see cv::BorderTypes
  631. @param borderValue border value in case of a constant border
  632. @sa erode, morphologyEx, getStructuringElement
  633. */
  634. GAPI_EXPORTS GMat dilate(const GMat& src, const Mat& kernel, const Point& anchor = Point(-1,-1), int iterations = 1,
  635. int borderType = BORDER_CONSTANT,
  636. const Scalar& borderValue = morphologyDefaultBorderValue());
  637. /** @brief Dilates an image by using 3 by 3 rectangular structuring element.
  638. The function dilates the source image using the specified structuring element that determines the
  639. shape of a pixel neighborhood over which the maximum is taken:
  640. \f[\texttt{dst} (x,y) = \max _{(x',y'): \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')\f]
  641. Dilation can be applied several (iterations) times. In case of multi-channel images, each channel is processed independently.
  642. Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, and @ref CV_32FC1.
  643. Output image must have the same type, size, and number of channels as the input image.
  644. @note
  645. - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest.
  646. - Function textual ID is "org.opencv.imgproc.filters.dilate"
  647. @param src input image.
  648. @param iterations number of times dilation is applied.
  649. @param borderType pixel extrapolation method, see cv::BorderTypes
  650. @param borderValue border value in case of a constant border
  651. @sa dilate, erode3x3
  652. */
  653. GAPI_EXPORTS GMat dilate3x3(const GMat& src, int iterations = 1,
  654. int borderType = BORDER_CONSTANT,
  655. const Scalar& borderValue = morphologyDefaultBorderValue());
  656. /** @brief Performs advanced morphological transformations.
  657. The function can perform advanced morphological transformations using an erosion and dilation as
  658. basic operations.
  659. Any of the operations can be done in-place. In case of multi-channel images, each channel is
  660. processed independently.
  661. @note
  662. - Function textual ID is "org.opencv.imgproc.filters.morphologyEx"
  663. - The number of iterations is the number of times erosion or dilatation operation will be
  664. applied. For instance, an opening operation (#MORPH_OPEN) with two iterations is equivalent to
  665. apply successively: erode -> erode -> dilate -> dilate
  666. (and not erode -> dilate -> erode -> dilate).
  667. @param src Input image.
  668. @param op Type of a morphological operation, see #MorphTypes
  669. @param kernel Structuring element. It can be created using #getStructuringElement.
  670. @param anchor Anchor position within the element. Both negative values mean that the anchor is at
  671. the kernel center.
  672. @param iterations Number of times erosion and dilation are applied.
  673. @param borderType Pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported.
  674. @param borderValue Border value in case of a constant border. The default value has a special
  675. meaning.
  676. @sa dilate, erode, getStructuringElement
  677. */
  678. GAPI_EXPORTS GMat morphologyEx(const GMat &src, const MorphTypes op, const Mat &kernel,
  679. const Point &anchor = Point(-1,-1),
  680. const int iterations = 1,
  681. const BorderTypes borderType = BORDER_CONSTANT,
  682. const Scalar &borderValue = morphologyDefaultBorderValue());
  683. /** @brief Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator.
  684. In all cases except one, the \f$\texttt{ksize} \times \texttt{ksize}\f$ separable kernel is used to
  685. calculate the derivative. When \f$\texttt{ksize = 1}\f$, the \f$3 \times 1\f$ or \f$1 \times 3\f$
  686. kernel is used (that is, no Gaussian smoothing is done). `ksize = 1` can only be used for the first
  687. or the second x- or y- derivatives.
  688. There is also the special value `ksize = FILTER_SCHARR (-1)` that corresponds to the \f$3\times3\f$ Scharr
  689. filter that may give more accurate results than the \f$3\times3\f$ Sobel. The Scharr aperture is
  690. \f[\vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}\f]
  691. for the x-derivative, or transposed for the y-derivative.
  692. The function calculates an image derivative by convolving the image with the appropriate kernel:
  693. \f[\texttt{dst} = \frac{\partial^{xorder+yorder} \texttt{src}}{\partial x^{xorder} \partial y^{yorder}}\f]
  694. The Sobel operators combine Gaussian smoothing and differentiation, so the result is more or less
  695. resistant to the noise. Most often, the function is called with ( xorder = 1, yorder = 0, ksize = 3)
  696. or ( xorder = 0, yorder = 1, ksize = 3) to calculate the first x- or y- image derivative. The first
  697. case corresponds to a kernel of:
  698. \f[\vecthreethree{-1}{0}{1}{-2}{0}{2}{-1}{0}{1}\f]
  699. The second case corresponds to a kernel of:
  700. \f[\vecthreethree{-1}{-2}{-1}{0}{0}{0}{1}{2}{1}\f]
  701. @note
  702. - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest.
  703. - Function textual ID is "org.opencv.imgproc.filters.sobel"
  704. @param src input image.
  705. @param ddepth output image depth, see @ref filter_depths "combinations"; in the case of
  706. 8-bit input images it will result in truncated derivatives.
  707. @param dx order of the derivative x.
  708. @param dy order of the derivative y.
  709. @param ksize size of the extended Sobel kernel; it must be odd.
  710. @param scale optional scale factor for the computed derivative values; by default, no scaling is
  711. applied (see cv::getDerivKernels for details).
  712. @param delta optional delta value that is added to the results prior to storing them in dst.
  713. @param borderType pixel extrapolation method, see cv::BorderTypes
  714. @param borderValue border value in case of constant border type
  715. @sa filter2D, gaussianBlur, cartToPolar
  716. */
  717. GAPI_EXPORTS GMat Sobel(const GMat& src, int ddepth, int dx, int dy, int ksize = 3,
  718. double scale = 1, double delta = 0,
  719. int borderType = BORDER_DEFAULT,
  720. const Scalar& borderValue = Scalar(0));
  721. /** @brief Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator.
  722. In all cases except one, the \f$\texttt{ksize} \times \texttt{ksize}\f$ separable kernel is used to
  723. calculate the derivative. When \f$\texttt{ksize = 1}\f$, the \f$3 \times 1\f$ or \f$1 \times 3\f$
  724. kernel is used (that is, no Gaussian smoothing is done). `ksize = 1` can only be used for the first
  725. or the second x- or y- derivatives.
  726. There is also the special value `ksize = FILTER_SCHARR (-1)` that corresponds to the \f$3\times3\f$ Scharr
  727. filter that may give more accurate results than the \f$3\times3\f$ Sobel. The Scharr aperture is
  728. \f[\vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}\f]
  729. for the x-derivative, or transposed for the y-derivative.
  730. The function calculates an image derivative by convolving the image with the appropriate kernel:
  731. \f[\texttt{dst} = \frac{\partial^{xorder+yorder} \texttt{src}}{\partial x^{xorder} \partial y^{yorder}}\f]
  732. The Sobel operators combine Gaussian smoothing and differentiation, so the result is more or less
  733. resistant to the noise. Most often, the function is called with ( xorder = 1, yorder = 0, ksize = 3)
  734. or ( xorder = 0, yorder = 1, ksize = 3) to calculate the first x- or y- image derivative. The first
  735. case corresponds to a kernel of:
  736. \f[\vecthreethree{-1}{0}{1}{-2}{0}{2}{-1}{0}{1}\f]
  737. The second case corresponds to a kernel of:
  738. \f[\vecthreethree{-1}{-2}{-1}{0}{0}{0}{1}{2}{1}\f]
  739. @note
  740. - First returned matrix correspons to dx derivative while the second one to dy.
  741. - Rounding to nearest even is procedeed if hardware supports it, if not - to nearest.
  742. - Function textual ID is "org.opencv.imgproc.filters.sobelxy"
  743. @param src input image.
  744. @param ddepth output image depth, see @ref filter_depths "combinations"; in the case of
  745. 8-bit input images it will result in truncated derivatives.
  746. @param order order of the derivatives.
  747. @param ksize size of the extended Sobel kernel; it must be odd.
  748. @param scale optional scale factor for the computed derivative values; by default, no scaling is
  749. applied (see cv::getDerivKernels for details).
  750. @param delta optional delta value that is added to the results prior to storing them in dst.
  751. @param borderType pixel extrapolation method, see cv::BorderTypes
  752. @param borderValue border value in case of constant border type
  753. @sa filter2D, gaussianBlur, cartToPolar
  754. */
  755. GAPI_EXPORTS std::tuple<GMat, GMat> SobelXY(const GMat& src, int ddepth, int order, int ksize = 3,
  756. double scale = 1, double delta = 0,
  757. int borderType = BORDER_DEFAULT,
  758. const Scalar& borderValue = Scalar(0));
  759. /** @brief Calculates the Laplacian of an image.
  760. The function calculates the Laplacian of the source image by adding up the second x and y
  761. derivatives calculated using the Sobel operator:
  762. \f[\texttt{dst} = \Delta \texttt{src} = \frac{\partial^2 \texttt{src}}{\partial x^2} + \frac{\partial^2 \texttt{src}}{\partial y^2}\f]
  763. This is done when `ksize > 1`. When `ksize == 1`, the Laplacian is computed by filtering the image
  764. with the following \f$3 \times 3\f$ aperture:
  765. \f[\vecthreethree {0}{1}{0}{1}{-4}{1}{0}{1}{0}\f]
  766. @note Function textual ID is "org.opencv.imgproc.filters.laplacian"
  767. @param src Source image.
  768. @param ddepth Desired depth of the destination image.
  769. @param ksize Aperture size used to compute the second-derivative filters. See #getDerivKernels for
  770. details. The size must be positive and odd.
  771. @param scale Optional scale factor for the computed Laplacian values. By default, no scaling is
  772. applied. See #getDerivKernels for details.
  773. @param delta Optional delta value that is added to the results prior to storing them in dst .
  774. @param borderType Pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported.
  775. @return Destination image of the same size and the same number of channels as src.
  776. @sa Sobel, Scharr
  777. */
  778. GAPI_EXPORTS GMat Laplacian(const GMat& src, int ddepth, int ksize = 1,
  779. double scale = 1, double delta = 0, int borderType = BORDER_DEFAULT);
  780. /** @brief Applies the bilateral filter to an image.
  781. The function applies bilateral filtering to the input image, as described in
  782. http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html
  783. bilateralFilter can reduce unwanted noise very well while keeping edges fairly sharp. However, it is
  784. very slow compared to most filters.
  785. _Sigma values_: For simplicity, you can set the 2 sigma values to be the same. If they are small (\<
  786. 10), the filter will not have much effect, whereas if they are large (\> 150), they will have a very
  787. strong effect, making the image look "cartoonish".
  788. _Filter size_: Large filters (d \> 5) are very slow, so it is recommended to use d=5 for real-time
  789. applications, and perhaps d=9 for offline applications that need heavy noise filtering.
  790. This filter does not work inplace.
  791. @note Function textual ID is "org.opencv.imgproc.filters.bilateralfilter"
  792. @param src Source 8-bit or floating-point, 1-channel or 3-channel image.
  793. @param d Diameter of each pixel neighborhood that is used during filtering. If it is non-positive,
  794. it is computed from sigmaSpace.
  795. @param sigmaColor Filter sigma in the color space. A larger value of the parameter means that
  796. farther colors within the pixel neighborhood (see sigmaSpace) will be mixed together, resulting
  797. in larger areas of semi-equal color.
  798. @param sigmaSpace Filter sigma in the coordinate space. A larger value of the parameter means that
  799. farther pixels will influence each other as long as their colors are close enough (see sigmaColor
  800. ). When d\>0, it specifies the neighborhood size regardless of sigmaSpace. Otherwise, d is
  801. proportional to sigmaSpace.
  802. @param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes
  803. @return Destination image of the same size and type as src.
  804. */
  805. GAPI_EXPORTS GMat bilateralFilter(const GMat& src, int d, double sigmaColor, double sigmaSpace,
  806. int borderType = BORDER_DEFAULT);
  807. //! @} gapi_filters
  808. //! @addtogroup gapi_feature
  809. //! @{
  810. /** @brief Finds edges in an image using the Canny algorithm.
  811. The function finds edges in the input image and marks them in the output map edges using the
  812. Canny algorithm. The smallest value between threshold1 and threshold2 is used for edge linking. The
  813. largest value is used to find initial segments of strong edges. See
  814. <http://en.wikipedia.org/wiki/Canny_edge_detector>
  815. @note Function textual ID is "org.opencv.imgproc.feature.canny"
  816. @param image 8-bit input image.
  817. @param threshold1 first threshold for the hysteresis procedure.
  818. @param threshold2 second threshold for the hysteresis procedure.
  819. @param apertureSize aperture size for the Sobel operator.
  820. @param L2gradient a flag, indicating whether a more accurate \f$L_2\f$ norm
  821. \f$=\sqrt{(dI/dx)^2 + (dI/dy)^2}\f$ should be used to calculate the image gradient magnitude (
  822. L2gradient=true ), or whether the default \f$L_1\f$ norm \f$=|dI/dx|+|dI/dy|\f$ is enough (
  823. L2gradient=false ).
  824. */
  825. GAPI_EXPORTS GMat Canny(const GMat& image, double threshold1, double threshold2,
  826. int apertureSize = 3, bool L2gradient = false);
  827. /** @brief Determines strong corners on an image.
  828. The function finds the most prominent corners in the image or in the specified image region, as
  829. described in @cite Shi94
  830. - Function calculates the corner quality measure at every source image pixel using the
  831. #cornerMinEigenVal or #cornerHarris .
  832. - Function performs a non-maximum suppression (the local maximums in *3 x 3* neighborhood are
  833. retained).
  834. - The corners with the minimal eigenvalue less than
  835. \f$\texttt{qualityLevel} \cdot \max_{x,y} qualityMeasureMap(x,y)\f$ are rejected.
  836. - The remaining corners are sorted by the quality measure in the descending order.
  837. - Function throws away each corner for which there is a stronger corner at a distance less than
  838. maxDistance.
  839. The function can be used to initialize a point-based tracker of an object.
  840. @note
  841. - If the function is called with different values A and B of the parameter qualityLevel , and
  842. A \> B, the vector of returned corners with qualityLevel=A will be the prefix of the output vector
  843. with qualityLevel=B .
  844. - Function textual ID is "org.opencv.imgproc.feature.goodFeaturesToTrack"
  845. @param image Input 8-bit or floating-point 32-bit, single-channel image.
  846. @param maxCorners Maximum number of corners to return. If there are more corners than are found,
  847. the strongest of them is returned. `maxCorners <= 0` implies that no limit on the maximum is set
  848. and all detected corners are returned.
  849. @param qualityLevel Parameter characterizing the minimal accepted quality of image corners. The
  850. parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue
  851. (see #cornerMinEigenVal ) or the Harris function response (see #cornerHarris ). The corners with the
  852. quality measure less than the product are rejected. For example, if the best corner has the
  853. quality measure = 1500, and the qualityLevel=0.01 , then all the corners with the quality measure
  854. less than 15 are rejected.
  855. @param minDistance Minimum possible Euclidean distance between the returned corners.
  856. @param mask Optional region of interest. If the image is not empty (it needs to have the type
  857. CV_8UC1 and the same size as image ), it specifies the region in which the corners are detected.
  858. @param blockSize Size of an average block for computing a derivative covariation matrix over each
  859. pixel neighborhood. See cornerEigenValsAndVecs .
  860. @param useHarrisDetector Parameter indicating whether to use a Harris detector (see #cornerHarris)
  861. or #cornerMinEigenVal.
  862. @param k Free parameter of the Harris detector.
  863. @return vector of detected corners.
  864. */
  865. GAPI_EXPORTS_W GArray<Point2f> goodFeaturesToTrack(const GMat &image,
  866. int maxCorners,
  867. double qualityLevel,
  868. double minDistance,
  869. const Mat &mask = Mat(),
  870. int blockSize = 3,
  871. bool useHarrisDetector = false,
  872. double k = 0.04);
  873. /** @brief Equalizes the histogram of a grayscale image.
  874. //! @} gapi_feature
  875. The function equalizes the histogram of the input image using the following algorithm:
  876. - Calculate the histogram \f$H\f$ for src .
  877. - Normalize the histogram so that the sum of histogram bins is 255.
  878. - Compute the integral of the histogram:
  879. \f[H'_i = \sum _{0 \le j < i} H(j)\f]
  880. - Transform the image using \f$H'\f$ as a look-up table: \f$\texttt{dst}(x,y) = H'(\texttt{src}(x,y))\f$
  881. The algorithm normalizes the brightness and increases the contrast of the image.
  882. @note
  883. - The returned image is of the same size and type as input.
  884. - Function textual ID is "org.opencv.imgproc.equalizeHist"
  885. @param src Source 8-bit single channel image.
  886. */
  887. GAPI_EXPORTS GMat equalizeHist(const GMat& src);
  888. //! @addtogroup gapi_shape
  889. //! @{
  890. /** @brief Finds contours in a binary image.
  891. The function retrieves contours from the binary image using the algorithm @cite Suzuki85 .
  892. The contours are a useful tool for shape analysis and object detection and recognition.
  893. See squares.cpp in the OpenCV sample directory.
  894. @note Function textual ID is "org.opencv.imgproc.shape.findContours"
  895. @param src Input gray-scale image @ref CV_8UC1. Non-zero pixels are treated as 1's. Zero
  896. pixels remain 0's, so the image is treated as binary . You can use #compare, #inRange, #threshold ,
  897. #adaptiveThreshold, #Canny, and others to create a binary image out of a grayscale or color one.
  898. If mode equals to #RETR_CCOMP, the input can also be a 32-bit integer
  899. image of labels ( @ref CV_32SC1 ). If #RETR_FLOODFILL then @ref CV_32SC1 is supported only.
  900. @param mode Contour retrieval mode, see #RetrievalModes
  901. @param method Contour approximation method, see #ContourApproximationModes
  902. @param offset Optional offset by which every contour point is shifted. This is useful if the
  903. contours are extracted from the image ROI and then they should be analyzed in the whole image
  904. context.
  905. @return GArray of detected contours. Each contour is stored as a GArray of points.
  906. */
  907. GAPI_EXPORTS GArray<GArray<Point>>
  908. findContours(const GMat &src, const RetrievalModes mode, const ContourApproximationModes method,
  909. const GOpaque<Point> &offset);
  910. // FIXME oc: make default value offset = Point()
  911. /** @overload
  912. @note Function textual ID is "org.opencv.imgproc.shape.findContoursNoOffset"
  913. */
  914. GAPI_EXPORTS GArray<GArray<Point>>
  915. findContours(const GMat &src, const RetrievalModes mode, const ContourApproximationModes method);
  916. /** @brief Finds contours and their hierarchy in a binary image.
  917. The function retrieves contours from the binary image using the algorithm @cite Suzuki85
  918. and calculates their hierarchy.
  919. The contours are a useful tool for shape analysis and object detection and recognition.
  920. See squares.cpp in the OpenCV sample directory.
  921. @note Function textual ID is "org.opencv.imgproc.shape.findContoursH"
  922. @param src Input gray-scale image @ref CV_8UC1. Non-zero pixels are treated as 1's. Zero
  923. pixels remain 0's, so the image is treated as binary . You can use #compare, #inRange, #threshold ,
  924. #adaptiveThreshold, #Canny, and others to create a binary image out of a grayscale or color one.
  925. If mode equals to #RETR_CCOMP, the input can also be a 32-bit integer
  926. image of labels ( @ref CV_32SC1 ). If #RETR_FLOODFILL -- @ref CV_32SC1 supports only.
  927. @param mode Contour retrieval mode, see #RetrievalModes
  928. @param method Contour approximation method, see #ContourApproximationModes
  929. @param offset Optional offset by which every contour point is shifted. This is useful if the
  930. contours are extracted from the image ROI and then they should be analyzed in the whole image
  931. context.
  932. @return
  933. - GArray of detected contours. Each contour is stored as a GArray of points.
  934. - Optional output GArray of cv::Vec4i, containing information about the image topology.
  935. It has as many elements as the number of contours. For each i-th contour contours[i], the elements
  936. hierarchy[i][0] , hierarchy[i][1] , hierarchy[i][2] , and hierarchy[i][3] are set to 0-based
  937. indices in contours of the next and previous contours at the same hierarchical level, the first
  938. child contour and the parent contour, respectively. If for the contour i there are no next,
  939. previous, parent, or nested contours, the corresponding elements of hierarchy[i] will be negative.
  940. */
  941. GAPI_EXPORTS std::tuple<GArray<GArray<Point>>,GArray<Vec4i>>
  942. findContoursH(const GMat &src, const RetrievalModes mode, const ContourApproximationModes method,
  943. const GOpaque<Point> &offset);
  944. // FIXME oc: make default value offset = Point()
  945. /** @overload
  946. @note Function textual ID is "org.opencv.imgproc.shape.findContoursHNoOffset"
  947. */
  948. GAPI_EXPORTS std::tuple<GArray<GArray<Point>>,GArray<Vec4i>>
  949. findContoursH(const GMat &src, const RetrievalModes mode, const ContourApproximationModes method);
  950. /** @brief Calculates the up-right bounding rectangle of a point set or non-zero pixels
  951. of gray-scale image.
  952. The function calculates and returns the minimal up-right bounding rectangle for the specified
  953. point set or non-zero pixels of gray-scale image.
  954. @note
  955. - Function textual ID is "org.opencv.imgproc.shape.boundingRectMat"
  956. - In case of a 2D points' set given, Mat should be 2-dimensional, have a single row or column
  957. if there are 2 channels, or have 2 columns if there is a single channel. Mat should have either
  958. @ref CV_32S or @ref CV_32F depth
  959. @param src Input gray-scale image @ref CV_8UC1; or input set of @ref CV_32S or @ref CV_32F
  960. 2D points stored in Mat.
  961. */
  962. GAPI_EXPORTS GOpaque<Rect> boundingRect(const GMat& src);
  963. /** @overload
  964. Calculates the up-right bounding rectangle of a point set.
  965. @note Function textual ID is "org.opencv.imgproc.shape.boundingRectVector32S"
  966. @param src Input 2D point set, stored in std::vector<cv::Point2i>.
  967. */
  968. GAPI_EXPORTS GOpaque<Rect> boundingRect(const GArray<Point2i>& src);
  969. /** @overload
  970. Calculates the up-right bounding rectangle of a point set.
  971. @note Function textual ID is "org.opencv.imgproc.shape.boundingRectVector32F"
  972. @param src Input 2D point set, stored in std::vector<cv::Point2f>.
  973. */
  974. GAPI_EXPORTS GOpaque<Rect> boundingRect(const GArray<Point2f>& src);
  975. /** @brief Fits a line to a 2D point set.
  976. The function fits a line to a 2D point set by minimizing \f$\sum_i \rho(r_i)\f$ where
  977. \f$r_i\f$ is a distance between the \f$i^{th}\f$ point, the line and \f$\rho(r)\f$ is a distance
  978. function, one of the following:
  979. - DIST_L2
  980. \f[\rho (r) = r^2/2 \quad \text{(the simplest and the fastest least-squares method)}\f]
  981. - DIST_L1
  982. \f[\rho (r) = r\f]
  983. - DIST_L12
  984. \f[\rho (r) = 2 \cdot ( \sqrt{1 + \frac{r^2}{2}} - 1)\f]
  985. - DIST_FAIR
  986. \f[\rho \left (r \right ) = C^2 \cdot \left ( \frac{r}{C} - \log{\left(1 + \frac{r}{C}\right)} \right ) \quad \text{where} \quad C=1.3998\f]
  987. - DIST_WELSCH
  988. \f[\rho \left (r \right ) = \frac{C^2}{2} \cdot \left ( 1 - \exp{\left(-\left(\frac{r}{C}\right)^2\right)} \right ) \quad \text{where} \quad C=2.9846\f]
  989. - DIST_HUBER
  990. \f[\rho (r) = \fork{r^2/2}{if \(r < C\)}{C \cdot (r-C/2)}{otherwise} \quad \text{where} \quad C=1.345\f]
  991. The algorithm is based on the M-estimator ( <http://en.wikipedia.org/wiki/M-estimator> ) technique
  992. that iteratively fits the line using the weighted least-squares algorithm. After each iteration the
  993. weights \f$w_i\f$ are adjusted to be inversely proportional to \f$\rho(r_i)\f$ .
  994. @note
  995. - Function textual ID is "org.opencv.imgproc.shape.fitLine2DMat"
  996. - In case of an N-dimentional points' set given, Mat should be 2-dimensional, have a single row
  997. or column if there are N channels, or have N columns if there is a single channel.
  998. @param src Input set of 2D points stored in one of possible containers: Mat,
  999. std::vector<cv::Point2i>, std::vector<cv::Point2f>, std::vector<cv::Point2d>.
  1000. @param distType Distance used by the M-estimator, see #DistanceTypes. @ref DIST_USER
  1001. and @ref DIST_C are not suppored.
  1002. @param param Numerical parameter ( C ) for some types of distances. If it is 0, an optimal value
  1003. is chosen.
  1004. @param reps Sufficient accuracy for the radius (distance between the coordinate origin and the
  1005. line). 1.0 would be a good default value for reps. If it is 0, a default value is chosen.
  1006. @param aeps Sufficient accuracy for the angle. 0.01 would be a good default value for aeps.
  1007. If it is 0, a default value is chosen.
  1008. @return Output line parameters: a vector of 4 elements (like Vec4f) - (vx, vy, x0, y0),
  1009. where (vx, vy) is a normalized vector collinear to the line and (x0, y0) is a point on the line.
  1010. */
  1011. GAPI_EXPORTS GOpaque<Vec4f> fitLine2D(const GMat& src, const DistanceTypes distType,
  1012. const double param = 0., const double reps = 0.,
  1013. const double aeps = 0.);
  1014. /** @overload
  1015. @note Function textual ID is "org.opencv.imgproc.shape.fitLine2DVector32S"
  1016. */
  1017. GAPI_EXPORTS GOpaque<Vec4f> fitLine2D(const GArray<Point2i>& src, const DistanceTypes distType,
  1018. const double param = 0., const double reps = 0.,
  1019. const double aeps = 0.);
  1020. /** @overload
  1021. @note Function textual ID is "org.opencv.imgproc.shape.fitLine2DVector32F"
  1022. */
  1023. GAPI_EXPORTS GOpaque<Vec4f> fitLine2D(const GArray<Point2f>& src, const DistanceTypes distType,
  1024. const double param = 0., const double reps = 0.,
  1025. const double aeps = 0.);
  1026. /** @overload
  1027. @note Function textual ID is "org.opencv.imgproc.shape.fitLine2DVector64F"
  1028. */
  1029. GAPI_EXPORTS GOpaque<Vec4f> fitLine2D(const GArray<Point2d>& src, const DistanceTypes distType,
  1030. const double param = 0., const double reps = 0.,
  1031. const double aeps = 0.);
  1032. /** @brief Fits a line to a 3D point set.
  1033. The function fits a line to a 3D point set by minimizing \f$\sum_i \rho(r_i)\f$ where
  1034. \f$r_i\f$ is a distance between the \f$i^{th}\f$ point, the line and \f$\rho(r)\f$ is a distance
  1035. function, one of the following:
  1036. - DIST_L2
  1037. \f[\rho (r) = r^2/2 \quad \text{(the simplest and the fastest least-squares method)}\f]
  1038. - DIST_L1
  1039. \f[\rho (r) = r\f]
  1040. - DIST_L12
  1041. \f[\rho (r) = 2 \cdot ( \sqrt{1 + \frac{r^2}{2}} - 1)\f]
  1042. - DIST_FAIR
  1043. \f[\rho \left (r \right ) = C^2 \cdot \left ( \frac{r}{C} - \log{\left(1 + \frac{r}{C}\right)} \right ) \quad \text{where} \quad C=1.3998\f]
  1044. - DIST_WELSCH
  1045. \f[\rho \left (r \right ) = \frac{C^2}{2} \cdot \left ( 1 - \exp{\left(-\left(\frac{r}{C}\right)^2\right)} \right ) \quad \text{where} \quad C=2.9846\f]
  1046. - DIST_HUBER
  1047. \f[\rho (r) = \fork{r^2/2}{if \(r < C\)}{C \cdot (r-C/2)}{otherwise} \quad \text{where} \quad C=1.345\f]
  1048. The algorithm is based on the M-estimator ( <http://en.wikipedia.org/wiki/M-estimator> ) technique
  1049. that iteratively fits the line using the weighted least-squares algorithm. After each iteration the
  1050. weights \f$w_i\f$ are adjusted to be inversely proportional to \f$\rho(r_i)\f$ .
  1051. @note
  1052. - Function textual ID is "org.opencv.imgproc.shape.fitLine3DMat"
  1053. - In case of an N-dimentional points' set given, Mat should be 2-dimensional, have a single row
  1054. or column if there are N channels, or have N columns if there is a single channel.
  1055. @param src Input set of 3D points stored in one of possible containers: Mat,
  1056. std::vector<cv::Point3i>, std::vector<cv::Point3f>, std::vector<cv::Point3d>.
  1057. @param distType Distance used by the M-estimator, see #DistanceTypes. @ref DIST_USER
  1058. and @ref DIST_C are not suppored.
  1059. @param param Numerical parameter ( C ) for some types of distances. If it is 0, an optimal value
  1060. is chosen.
  1061. @param reps Sufficient accuracy for the radius (distance between the coordinate origin and the
  1062. line). 1.0 would be a good default value for reps. If it is 0, a default value is chosen.
  1063. @param aeps Sufficient accuracy for the angle. 0.01 would be a good default value for aeps.
  1064. If it is 0, a default value is chosen.
  1065. @return Output line parameters: a vector of 6 elements (like Vec6f) - (vx, vy, vz, x0, y0, z0),
  1066. where (vx, vy, vz) is a normalized vector collinear to the line and (x0, y0, z0) is a point on
  1067. the line.
  1068. */
  1069. GAPI_EXPORTS GOpaque<Vec6f> fitLine3D(const GMat& src, const DistanceTypes distType,
  1070. const double param = 0., const double reps = 0.,
  1071. const double aeps = 0.);
  1072. /** @overload
  1073. @note Function textual ID is "org.opencv.imgproc.shape.fitLine3DVector32S"
  1074. */
  1075. GAPI_EXPORTS GOpaque<Vec6f> fitLine3D(const GArray<Point3i>& src, const DistanceTypes distType,
  1076. const double param = 0., const double reps = 0.,
  1077. const double aeps = 0.);
  1078. /** @overload
  1079. @note Function textual ID is "org.opencv.imgproc.shape.fitLine3DVector32F"
  1080. */
  1081. GAPI_EXPORTS GOpaque<Vec6f> fitLine3D(const GArray<Point3f>& src, const DistanceTypes distType,
  1082. const double param = 0., const double reps = 0.,
  1083. const double aeps = 0.);
  1084. /** @overload
  1085. @note Function textual ID is "org.opencv.imgproc.shape.fitLine3DVector64F"
  1086. */
  1087. GAPI_EXPORTS GOpaque<Vec6f> fitLine3D(const GArray<Point3d>& src, const DistanceTypes distType,
  1088. const double param = 0., const double reps = 0.,
  1089. const double aeps = 0.);
  1090. //! @} gapi_shape
  1091. //! @addtogroup gapi_colorconvert
  1092. //! @{
  1093. /** @brief Converts an image from BGR color space to RGB color space.
  1094. The function converts an input image from BGR color space to RGB.
  1095. The conventional ranges for B, G, and R channel values are 0 to 255.
  1096. Output image is 8-bit unsigned 3-channel image @ref CV_8UC3.
  1097. @note Function textual ID is "org.opencv.imgproc.colorconvert.bgr2rgb"
  1098. @param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3.
  1099. @sa RGB2BGR
  1100. */
  1101. GAPI_EXPORTS GMat BGR2RGB(const GMat& src);
  1102. /** @brief Converts an image from RGB color space to gray-scaled.
  1103. The conventional ranges for R, G, and B channel values are 0 to 255.
  1104. Resulting gray color value computed as
  1105. \f[\texttt{dst} (I)= \texttt{0.299} * \texttt{src}(I).R + \texttt{0.587} * \texttt{src}(I).G + \texttt{0.114} * \texttt{src}(I).B \f]
  1106. @note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2gray"
  1107. @param src input image: 8-bit unsigned 3-channel image @ref CV_8UC1.
  1108. @sa RGB2YUV
  1109. */
  1110. GAPI_EXPORTS_W GMat RGB2Gray(const GMat& src);
  1111. /** @overload
  1112. Resulting gray color value computed as
  1113. \f[\texttt{dst} (I)= \texttt{rY} * \texttt{src}(I).R + \texttt{gY} * \texttt{src}(I).G + \texttt{bY} * \texttt{src}(I).B \f]
  1114. @note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2graycustom"
  1115. @param src input image: 8-bit unsigned 3-channel image @ref CV_8UC1.
  1116. @param rY float multiplier for R channel.
  1117. @param gY float multiplier for G channel.
  1118. @param bY float multiplier for B channel.
  1119. @sa RGB2YUV
  1120. */
  1121. GAPI_EXPORTS GMat RGB2Gray(const GMat& src, float rY, float gY, float bY);
  1122. /** @brief Converts an image from BGR color space to gray-scaled.
  1123. The conventional ranges for B, G, and R channel values are 0 to 255.
  1124. Resulting gray color value computed as
  1125. \f[\texttt{dst} (I)= \texttt{0.114} * \texttt{src}(I).B + \texttt{0.587} * \texttt{src}(I).G + \texttt{0.299} * \texttt{src}(I).R \f]
  1126. @note Function textual ID is "org.opencv.imgproc.colorconvert.bgr2gray"
  1127. @param src input image: 8-bit unsigned 3-channel image @ref CV_8UC1.
  1128. @sa BGR2LUV
  1129. */
  1130. GAPI_EXPORTS GMat BGR2Gray(const GMat& src);
  1131. /** @brief Converts an image from RGB color space to YUV color space.
  1132. The function converts an input image from RGB color space to YUV.
  1133. The conventional ranges for R, G, and B channel values are 0 to 255.
  1134. In case of linear transformations, the range does not matter. But in case of a non-linear
  1135. transformation, an input RGB image should be normalized to the proper value range to get the correct
  1136. results, like here, at RGB \f$\rightarrow\f$ Y\*u\*v\* transformation.
  1137. Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3.
  1138. @note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2yuv"
  1139. @param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3.
  1140. @sa YUV2RGB, RGB2Lab
  1141. */
  1142. GAPI_EXPORTS GMat RGB2YUV(const GMat& src);
  1143. /** @brief Converts an image from BGR color space to I420 color space.
  1144. The function converts an input image from BGR color space to I420.
  1145. The conventional ranges for R, G, and B channel values are 0 to 255.
  1146. Output image must be 8-bit unsigned 1-channel image. @ref CV_8UC1.
  1147. Width of I420 output image must be the same as width of input image.
  1148. Height of I420 output image must be equal 3/2 from height of input image.
  1149. @note Function textual ID is "org.opencv.imgproc.colorconvert.bgr2i420"
  1150. @param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3.
  1151. @sa I4202BGR
  1152. */
  1153. GAPI_EXPORTS GMat BGR2I420(const GMat& src);
  1154. /** @brief Converts an image from RGB color space to I420 color space.
  1155. The function converts an input image from RGB color space to I420.
  1156. The conventional ranges for R, G, and B channel values are 0 to 255.
  1157. Output image must be 8-bit unsigned 1-channel image. @ref CV_8UC1.
  1158. Width of I420 output image must be the same as width of input image.
  1159. Height of I420 output image must be equal 3/2 from height of input image.
  1160. @note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2i420"
  1161. @param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3.
  1162. @sa I4202RGB
  1163. */
  1164. GAPI_EXPORTS GMat RGB2I420(const GMat& src);
  1165. /** @brief Converts an image from I420 color space to BGR color space.
  1166. The function converts an input image from I420 color space to BGR.
  1167. The conventional ranges for B, G, and R channel values are 0 to 255.
  1168. Output image must be 8-bit unsigned 3-channel image. @ref CV_8UC3.
  1169. Width of BGR output image must be the same as width of input image.
  1170. Height of BGR output image must be equal 2/3 from height of input image.
  1171. @note Function textual ID is "org.opencv.imgproc.colorconvert.i4202bgr"
  1172. @param src input image: 8-bit unsigned 1-channel image @ref CV_8UC1.
  1173. @sa BGR2I420
  1174. */
  1175. GAPI_EXPORTS GMat I4202BGR(const GMat& src);
  1176. /** @brief Converts an image from I420 color space to BGR color space.
  1177. The function converts an input image from I420 color space to BGR.
  1178. The conventional ranges for B, G, and R channel values are 0 to 255.
  1179. Output image must be 8-bit unsigned 3-channel image. @ref CV_8UC3.
  1180. Width of RGB output image must be the same as width of input image.
  1181. Height of RGB output image must be equal 2/3 from height of input image.
  1182. @note Function textual ID is "org.opencv.imgproc.colorconvert.i4202rgb"
  1183. @param src input image: 8-bit unsigned 1-channel image @ref CV_8UC1.
  1184. @sa RGB2I420
  1185. */
  1186. GAPI_EXPORTS GMat I4202RGB(const GMat& src);
  1187. /** @brief Converts an image from BGR color space to LUV color space.
  1188. The function converts an input image from BGR color space to LUV.
  1189. The conventional ranges for B, G, and R channel values are 0 to 255.
  1190. Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3.
  1191. @note Function textual ID is "org.opencv.imgproc.colorconvert.bgr2luv"
  1192. @param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3.
  1193. @sa RGB2Lab, RGB2LUV
  1194. */
  1195. GAPI_EXPORTS GMat BGR2LUV(const GMat& src);
  1196. /** @brief Converts an image from LUV color space to BGR color space.
  1197. The function converts an input image from LUV color space to BGR.
  1198. The conventional ranges for B, G, and R channel values are 0 to 255.
  1199. Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3.
  1200. @note Function textual ID is "org.opencv.imgproc.colorconvert.luv2bgr"
  1201. @param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3.
  1202. @sa BGR2LUV
  1203. */
  1204. GAPI_EXPORTS GMat LUV2BGR(const GMat& src);
  1205. /** @brief Converts an image from YUV color space to BGR color space.
  1206. The function converts an input image from YUV color space to BGR.
  1207. The conventional ranges for B, G, and R channel values are 0 to 255.
  1208. Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3.
  1209. @note Function textual ID is "org.opencv.imgproc.colorconvert.yuv2bgr"
  1210. @param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3.
  1211. @sa BGR2YUV
  1212. */
  1213. GAPI_EXPORTS GMat YUV2BGR(const GMat& src);
  1214. /** @brief Converts an image from BGR color space to YUV color space.
  1215. The function converts an input image from BGR color space to YUV.
  1216. The conventional ranges for B, G, and R channel values are 0 to 255.
  1217. Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3.
  1218. @note Function textual ID is "org.opencv.imgproc.colorconvert.bgr2yuv"
  1219. @param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3.
  1220. @sa YUV2BGR
  1221. */
  1222. GAPI_EXPORTS GMat BGR2YUV(const GMat& src);
  1223. /** @brief Converts an image from RGB color space to Lab color space.
  1224. The function converts an input image from BGR color space to Lab.
  1225. The conventional ranges for R, G, and B channel values are 0 to 255.
  1226. Output image must be 8-bit unsigned 3-channel image @ref CV_8UC1.
  1227. @note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2lab"
  1228. @param src input image: 8-bit unsigned 3-channel image @ref CV_8UC1.
  1229. @sa RGB2YUV, RGB2LUV
  1230. */
  1231. GAPI_EXPORTS GMat RGB2Lab(const GMat& src);
  1232. /** @brief Converts an image from YUV color space to RGB.
  1233. The function converts an input image from YUV color space to RGB.
  1234. The conventional ranges for Y, U, and V channel values are 0 to 255.
  1235. Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3.
  1236. @note Function textual ID is "org.opencv.imgproc.colorconvert.yuv2rgb"
  1237. @param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3.
  1238. @sa RGB2Lab, RGB2YUV
  1239. */
  1240. GAPI_EXPORTS GMat YUV2RGB(const GMat& src);
  1241. /** @brief Converts an image from NV12 (YUV420p) color space to RGB.
  1242. The function converts an input image from NV12 color space to RGB.
  1243. The conventional ranges for Y, U, and V channel values are 0 to 255.
  1244. Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3.
  1245. @note Function textual ID is "org.opencv.imgproc.colorconvert.nv12torgb"
  1246. @param src_y input image: 8-bit unsigned 1-channel image @ref CV_8UC1.
  1247. @param src_uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2.
  1248. @sa YUV2RGB, NV12toBGR
  1249. */
  1250. GAPI_EXPORTS GMat NV12toRGB(const GMat& src_y, const GMat& src_uv);
  1251. /** @brief Converts an image from NV12 (YUV420p) color space to gray-scaled.
  1252. The function converts an input image from NV12 color space to gray-scaled.
  1253. The conventional ranges for Y, U, and V channel values are 0 to 255.
  1254. Output image must be 8-bit unsigned 1-channel image @ref CV_8UC1.
  1255. @note Function textual ID is "org.opencv.imgproc.colorconvert.nv12togray"
  1256. @param src_y input image: 8-bit unsigned 1-channel image @ref CV_8UC1.
  1257. @param src_uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2.
  1258. @sa YUV2RGB, NV12toBGR
  1259. */
  1260. GAPI_EXPORTS GMat NV12toGray(const GMat& src_y, const GMat& src_uv);
  1261. /** @brief Converts an image from NV12 (YUV420p) color space to BGR.
  1262. The function converts an input image from NV12 color space to RGB.
  1263. The conventional ranges for Y, U, and V channel values are 0 to 255.
  1264. Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3.
  1265. @note Function textual ID is "org.opencv.imgproc.colorconvert.nv12tobgr"
  1266. @param src_y input image: 8-bit unsigned 1-channel image @ref CV_8UC1.
  1267. @param src_uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2.
  1268. @sa YUV2BGR, NV12toRGB
  1269. */
  1270. GAPI_EXPORTS GMat NV12toBGR(const GMat& src_y, const GMat& src_uv);
  1271. /** @brief Converts an image from BayerGR color space to RGB.
  1272. The function converts an input image from BayerGR color space to RGB.
  1273. The conventional ranges for G, R, and B channel values are 0 to 255.
  1274. Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3.
  1275. @note Function textual ID is "org.opencv.imgproc.colorconvert.bayergr2rgb"
  1276. @param src_gr input image: 8-bit unsigned 1-channel image @ref CV_8UC1.
  1277. @sa YUV2BGR, NV12toRGB
  1278. */
  1279. GAPI_EXPORTS GMat BayerGR2RGB(const GMat& src_gr);
  1280. /** @brief Converts an image from RGB color space to HSV.
  1281. The function converts an input image from RGB color space to HSV.
  1282. The conventional ranges for R, G, and B channel values are 0 to 255.
  1283. Output image must be 8-bit unsigned 3-channel image @ref CV_8UC3.
  1284. @note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2hsv"
  1285. @param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3.
  1286. @sa YUV2BGR, NV12toRGB
  1287. */
  1288. GAPI_EXPORTS GMat RGB2HSV(const GMat& src);
  1289. /** @brief Converts an image from RGB color space to YUV422.
  1290. The function converts an input image from RGB color space to YUV422.
  1291. The conventional ranges for R, G, and B channel values are 0 to 255.
  1292. Output image must be 8-bit unsigned 2-channel image @ref CV_8UC2.
  1293. @note Function textual ID is "org.opencv.imgproc.colorconvert.rgb2yuv422"
  1294. @param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3.
  1295. @sa YUV2BGR, NV12toRGB
  1296. */
  1297. GAPI_EXPORTS GMat RGB2YUV422(const GMat& src);
  1298. /** @brief Converts an image from NV12 (YUV420p) color space to RGB.
  1299. The function converts an input image from NV12 color space to RGB.
  1300. The conventional ranges for Y, U, and V channel values are 0 to 255.
  1301. Output image must be 8-bit unsigned planar 3-channel image @ref CV_8UC1.
  1302. Planar image memory layout is three planes laying in the memory contiguously,
  1303. so the image height should be plane_height*plane_number,
  1304. image type is @ref CV_8UC1.
  1305. @note Function textual ID is "org.opencv.imgproc.colorconvert.nv12torgbp"
  1306. @param src_y input image: 8-bit unsigned 1-channel image @ref CV_8UC1.
  1307. @param src_uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2.
  1308. @sa YUV2RGB, NV12toBGRp, NV12toRGB
  1309. */
  1310. GAPI_EXPORTS GMatP NV12toRGBp(const GMat &src_y, const GMat &src_uv);
  1311. /** @brief Converts an image from NV12 (YUV420p) color space to BGR.
  1312. The function converts an input image from NV12 color space to BGR.
  1313. The conventional ranges for Y, U, and V channel values are 0 to 255.
  1314. Output image must be 8-bit unsigned planar 3-channel image @ref CV_8UC1.
  1315. Planar image memory layout is three planes laying in the memory contiguously,
  1316. so the image height should be plane_height*plane_number,
  1317. image type is @ref CV_8UC1.
  1318. @note Function textual ID is "org.opencv.imgproc.colorconvert.nv12torgbp"
  1319. @param src_y input image: 8-bit unsigned 1-channel image @ref CV_8UC1.
  1320. @param src_uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2.
  1321. @sa YUV2RGB, NV12toRGBp, NV12toBGR
  1322. */
  1323. GAPI_EXPORTS GMatP NV12toBGRp(const GMat &src_y, const GMat &src_uv);
  1324. //! @} gapi_colorconvert
  1325. } //namespace gapi
  1326. } //namespace cv
  1327. #endif // OPENCV_GAPI_IMGPROC_HPP