imgproc.hpp 74 KB

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