core.hpp 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911
  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_CORE_HPP
  7. #define OPENCV_GAPI_CORE_HPP
  8. #include <math.h>
  9. #include <utility> // std::tuple
  10. #include <opencv2/imgproc.hpp>
  11. #include <opencv2/gapi/imgproc.hpp>
  12. #include <opencv2/gapi/gmat.hpp>
  13. #include <opencv2/gapi/gscalar.hpp>
  14. #include <opencv2/gapi/gkernel.hpp>
  15. #include <opencv2/gapi/streaming/format.hpp>
  16. /** \defgroup gapi_core G-API Core functionality
  17. @{
  18. @defgroup gapi_math Graph API: Math operations
  19. @defgroup gapi_pixelwise Graph API: Pixelwise operations
  20. @defgroup gapi_matrixop Graph API: Operations on matrices
  21. @defgroup gapi_transform Graph API: Image and channel composition functions
  22. @}
  23. */
  24. namespace cv { namespace gapi {
  25. /**
  26. * @brief This namespace contains G-API Operation Types for OpenCV
  27. * Core module functionality.
  28. */
  29. namespace core {
  30. using GResize = cv::gapi::imgproc::GResize;
  31. using GResizeP = cv::gapi::imgproc::GResizeP;
  32. using GMat2 = std::tuple<GMat,GMat>;
  33. using GMat3 = std::tuple<GMat,GMat,GMat>; // FIXME: how to avoid this?
  34. using GMat4 = std::tuple<GMat,GMat,GMat,GMat>;
  35. using GMatScalar = std::tuple<GMat, GScalar>;
  36. G_TYPED_KERNEL(GAdd, <GMat(GMat, GMat, int)>, "org.opencv.core.math.add") {
  37. static GMatDesc outMeta(GMatDesc a, GMatDesc b, int ddepth) {
  38. if (ddepth == -1)
  39. {
  40. // OpenCV: When the input arrays in add/subtract/multiply/divide
  41. // functions have different depths, the output array depth must be
  42. // explicitly specified!
  43. // See artim_op() @ arithm.cpp
  44. GAPI_Assert(a.chan == b.chan);
  45. GAPI_Assert(a.depth == b.depth);
  46. return a;
  47. }
  48. return a.withDepth(ddepth);
  49. }
  50. };
  51. G_TYPED_KERNEL(GAddC, <GMat(GMat, GScalar, int)>, "org.opencv.core.math.addC") {
  52. static GMatDesc outMeta(GMatDesc a, GScalarDesc, int ddepth) {
  53. GAPI_Assert(a.chan <= 4);
  54. return a.withDepth(ddepth);
  55. }
  56. };
  57. G_TYPED_KERNEL(GSub, <GMat(GMat, GMat, int)>, "org.opencv.core.math.sub") {
  58. static GMatDesc outMeta(GMatDesc a, GMatDesc b, int ddepth) {
  59. if (ddepth == -1)
  60. {
  61. // This macro should select a larger data depth from a and b
  62. // considering the number of channels in the same
  63. // FIXME!!! Clarify if it is valid for sub()
  64. GAPI_Assert(a.chan == b.chan);
  65. ddepth = std::max(a.depth, b.depth);
  66. }
  67. return a.withDepth(ddepth);
  68. }
  69. };
  70. G_TYPED_KERNEL(GSubC, <GMat(GMat, GScalar, int)>, "org.opencv.core.math.subC") {
  71. static GMatDesc outMeta(GMatDesc a, GScalarDesc, int ddepth) {
  72. return a.withDepth(ddepth);
  73. }
  74. };
  75. G_TYPED_KERNEL(GSubRC,<GMat(GScalar, GMat, int)>, "org.opencv.core.math.subRC") {
  76. static GMatDesc outMeta(GScalarDesc, GMatDesc b, int ddepth) {
  77. return b.withDepth(ddepth);
  78. }
  79. };
  80. G_TYPED_KERNEL(GMul, <GMat(GMat, GMat, double, int)>, "org.opencv.core.math.mul") {
  81. static GMatDesc outMeta(GMatDesc a, GMatDesc, double, int ddepth) {
  82. return a.withDepth(ddepth);
  83. }
  84. };
  85. G_TYPED_KERNEL(GMulCOld, <GMat(GMat, double, int)>, "org.opencv.core.math.mulCOld") {
  86. static GMatDesc outMeta(GMatDesc a, double, int ddepth) {
  87. return a.withDepth(ddepth);
  88. }
  89. };
  90. G_TYPED_KERNEL(GMulC, <GMat(GMat, GScalar, int)>, "org.opencv.core.math.mulC") {
  91. static GMatDesc outMeta(GMatDesc a, GScalarDesc, int ddepth) {
  92. return a.withDepth(ddepth);
  93. }
  94. };
  95. G_TYPED_KERNEL(GMulS, <GMat(GMat, GScalar)>, "org.opencv.core.math.muls") {
  96. static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
  97. return a;
  98. }
  99. }; // FIXME: Merge with MulC
  100. G_TYPED_KERNEL(GDiv, <GMat(GMat, GMat, double, int)>, "org.opencv.core.math.div") {
  101. static GMatDesc outMeta(GMatDesc a, GMatDesc b, double, int ddepth) {
  102. if (ddepth == -1)
  103. {
  104. GAPI_Assert(a.depth == b.depth);
  105. return b;
  106. }
  107. return a.withDepth(ddepth);
  108. }
  109. };
  110. G_TYPED_KERNEL(GDivC, <GMat(GMat, GScalar, double, int)>, "org.opencv.core.math.divC") {
  111. static GMatDesc outMeta(GMatDesc a, GScalarDesc, double, int ddepth) {
  112. return a.withDepth(ddepth);
  113. }
  114. };
  115. G_TYPED_KERNEL(GDivRC, <GMat(GScalar, GMat, double, int)>, "org.opencv.core.math.divRC") {
  116. static GMatDesc outMeta(GScalarDesc, GMatDesc b, double, int ddepth) {
  117. return b.withDepth(ddepth);
  118. }
  119. };
  120. G_TYPED_KERNEL(GMean, <GScalar(GMat)>, "org.opencv.core.math.mean") {
  121. static GScalarDesc outMeta(GMatDesc) {
  122. return empty_scalar_desc();
  123. }
  124. };
  125. G_TYPED_KERNEL_M(GPolarToCart, <GMat2(GMat, GMat, bool)>, "org.opencv.core.math.polarToCart") {
  126. static std::tuple<GMatDesc, GMatDesc> outMeta(GMatDesc, GMatDesc a, bool) {
  127. return std::make_tuple(a, a);
  128. }
  129. };
  130. G_TYPED_KERNEL_M(GCartToPolar, <GMat2(GMat, GMat, bool)>, "org.opencv.core.math.cartToPolar") {
  131. static std::tuple<GMatDesc, GMatDesc> outMeta(GMatDesc x, GMatDesc, bool) {
  132. return std::make_tuple(x, x);
  133. }
  134. };
  135. G_TYPED_KERNEL(GPhase, <GMat(GMat, GMat, bool)>, "org.opencv.core.math.phase") {
  136. static GMatDesc outMeta(const GMatDesc &inx, const GMatDesc &, bool) {
  137. return inx;
  138. }
  139. };
  140. G_TYPED_KERNEL(GMask, <GMat(GMat,GMat)>, "org.opencv.core.pixelwise.mask") {
  141. static GMatDesc outMeta(GMatDesc in, GMatDesc) {
  142. return in;
  143. }
  144. };
  145. G_TYPED_KERNEL(GCmpGT, <GMat(GMat, GMat)>, "org.opencv.core.pixelwise.compare.cmpGT") {
  146. static GMatDesc outMeta(GMatDesc a, GMatDesc) {
  147. return a.withDepth(CV_8U);
  148. }
  149. };
  150. G_TYPED_KERNEL(GCmpGE, <GMat(GMat, GMat)>, "org.opencv.core.pixelwise.compare.cmpGE") {
  151. static GMatDesc outMeta(GMatDesc a, GMatDesc) {
  152. return a.withDepth(CV_8U);
  153. }
  154. };
  155. G_TYPED_KERNEL(GCmpLE, <GMat(GMat, GMat)>, "org.opencv.core.pixelwise.compare.cmpLE") {
  156. static GMatDesc outMeta(GMatDesc a, GMatDesc) {
  157. return a.withDepth(CV_8U);
  158. }
  159. };
  160. G_TYPED_KERNEL(GCmpLT, <GMat(GMat, GMat)>, "org.opencv.core.pixelwise.compare.cmpLT") {
  161. static GMatDesc outMeta(GMatDesc a, GMatDesc) {
  162. return a.withDepth(CV_8U);
  163. }
  164. };
  165. G_TYPED_KERNEL(GCmpEQ, <GMat(GMat, GMat)>, "org.opencv.core.pixelwise.compare.cmpEQ") {
  166. static GMatDesc outMeta(GMatDesc a, GMatDesc) {
  167. return a.withDepth(CV_8U);
  168. }
  169. };
  170. G_TYPED_KERNEL(GCmpNE, <GMat(GMat, GMat)>, "org.opencv.core.pixelwise.compare.cmpNE") {
  171. static GMatDesc outMeta(GMatDesc a, GMatDesc) {
  172. return a.withDepth(CV_8U);
  173. }
  174. };
  175. G_TYPED_KERNEL(GCmpGTScalar, <GMat(GMat, GScalar)>, "org.opencv.core.pixelwise.compare.cmpGTScalar") {
  176. static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
  177. return a.withDepth(CV_8U);
  178. }
  179. };
  180. G_TYPED_KERNEL(GCmpGEScalar, <GMat(GMat, GScalar)>, "org.opencv.core.pixelwise.compare.cmpGEScalar") {
  181. static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
  182. return a.withDepth(CV_8U);
  183. }
  184. };
  185. G_TYPED_KERNEL(GCmpLEScalar, <GMat(GMat, GScalar)>, "org.opencv.core.pixelwise.compare.cmpLEScalar") {
  186. static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
  187. return a.withDepth(CV_8U);
  188. }
  189. };
  190. G_TYPED_KERNEL(GCmpLTScalar, <GMat(GMat, GScalar)>, "org.opencv.core.pixelwise.compare.cmpLTScalar") {
  191. static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
  192. return a.withDepth(CV_8U);
  193. }
  194. };
  195. G_TYPED_KERNEL(GCmpEQScalar, <GMat(GMat, GScalar)>, "org.opencv.core.pixelwise.compare.cmpEQScalar") {
  196. static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
  197. return a.withDepth(CV_8U);
  198. }
  199. };
  200. G_TYPED_KERNEL(GCmpNEScalar, <GMat(GMat, GScalar)>, "org.opencv.core.pixelwise.compare.cmpNEScalar") {
  201. static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
  202. return a.withDepth(CV_8U);
  203. }
  204. };
  205. G_TYPED_KERNEL(GAnd, <GMat(GMat, GMat)>, "org.opencv.core.pixelwise.bitwise_and") {
  206. static GMatDesc outMeta(GMatDesc a, GMatDesc) {
  207. return a;
  208. }
  209. };
  210. G_TYPED_KERNEL(GAndS, <GMat(GMat, GScalar)>, "org.opencv.core.pixelwise.bitwise_andS") {
  211. static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
  212. return a;
  213. }
  214. };
  215. G_TYPED_KERNEL(GOr, <GMat(GMat, GMat)>, "org.opencv.core.pixelwise.bitwise_or") {
  216. static GMatDesc outMeta(GMatDesc a, GMatDesc) {
  217. return a;
  218. }
  219. };
  220. G_TYPED_KERNEL(GOrS, <GMat(GMat, GScalar)>, "org.opencv.core.pixelwise.bitwise_orS") {
  221. static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
  222. return a;
  223. }
  224. };
  225. G_TYPED_KERNEL(GXor, <GMat(GMat, GMat)>, "org.opencv.core.pixelwise.bitwise_xor") {
  226. static GMatDesc outMeta(GMatDesc a, GMatDesc) {
  227. return a;
  228. }
  229. };
  230. G_TYPED_KERNEL(GXorS, <GMat(GMat, GScalar)>, "org.opencv.core.pixelwise.bitwise_xorS") {
  231. static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
  232. return a;
  233. }
  234. };
  235. G_TYPED_KERNEL(GNot, <GMat(GMat)>, "org.opencv.core.pixelwise.bitwise_not") {
  236. static GMatDesc outMeta(GMatDesc a) {
  237. return a;
  238. }
  239. };
  240. G_TYPED_KERNEL(GSelect, <GMat(GMat, GMat, GMat)>, "org.opencv.core.pixelwise.select") {
  241. static GMatDesc outMeta(GMatDesc a, GMatDesc, GMatDesc) {
  242. return a;
  243. }
  244. };
  245. G_TYPED_KERNEL(GMin, <GMat(GMat, GMat)>, "org.opencv.core.matrixop.min") {
  246. static GMatDesc outMeta(GMatDesc a, GMatDesc) {
  247. return a;
  248. }
  249. };
  250. G_TYPED_KERNEL(GMax, <GMat(GMat, GMat)>, "org.opencv.core.matrixop.max") {
  251. static GMatDesc outMeta(GMatDesc a, GMatDesc) {
  252. return a;
  253. }
  254. };
  255. G_TYPED_KERNEL(GAbsDiff, <GMat(GMat, GMat)>, "org.opencv.core.matrixop.absdiff") {
  256. static GMatDesc outMeta(GMatDesc a, GMatDesc) {
  257. return a;
  258. }
  259. };
  260. G_TYPED_KERNEL(GAbsDiffC, <GMat(GMat,GScalar)>, "org.opencv.core.matrixop.absdiffC") {
  261. static GMatDesc outMeta(const GMatDesc& a, const GScalarDesc&) {
  262. return a;
  263. }
  264. };
  265. G_TYPED_KERNEL(GSum, <GScalar(GMat)>, "org.opencv.core.matrixop.sum") {
  266. static GScalarDesc outMeta(GMatDesc) {
  267. return empty_scalar_desc();
  268. }
  269. };
  270. G_TYPED_KERNEL(GCountNonZero, <GOpaque<int>(GMat)>, "org.opencv.core.matrixop.countNonZero") {
  271. static GOpaqueDesc outMeta(GMatDesc in) {
  272. GAPI_Assert(in.chan == 1);
  273. return empty_gopaque_desc();
  274. }
  275. };
  276. G_TYPED_KERNEL(GAddW, <GMat(GMat, double, GMat, double, double, int)>, "org.opencv.core.matrixop.addweighted") {
  277. static GMatDesc outMeta(GMatDesc a, double, GMatDesc b, double, double, int ddepth) {
  278. if (ddepth == -1)
  279. {
  280. // OpenCV: When the input arrays in add/subtract/multiply/divide
  281. // functions have different depths, the output array depth must be
  282. // explicitly specified!
  283. // See artim_op() @ arithm.cpp
  284. GAPI_Assert(a.chan == b.chan);
  285. GAPI_Assert(a.depth == b.depth);
  286. return a;
  287. }
  288. return a.withDepth(ddepth);
  289. }
  290. };
  291. G_TYPED_KERNEL(GNormL1, <GScalar(GMat)>, "org.opencv.core.matrixop.norml1") {
  292. static GScalarDesc outMeta(GMatDesc) {
  293. return empty_scalar_desc();
  294. }
  295. };
  296. G_TYPED_KERNEL(GNormL2, <GScalar(GMat)>, "org.opencv.core.matrixop.norml2") {
  297. static GScalarDesc outMeta(GMatDesc) {
  298. return empty_scalar_desc();
  299. }
  300. };
  301. G_TYPED_KERNEL(GNormInf, <GScalar(GMat)>, "org.opencv.core.matrixop.norminf") {
  302. static GScalarDesc outMeta(GMatDesc) {
  303. return empty_scalar_desc();
  304. }
  305. };
  306. G_TYPED_KERNEL_M(GIntegral, <GMat2(GMat, int, int)>, "org.opencv.core.matrixop.integral") {
  307. static std::tuple<GMatDesc, GMatDesc> outMeta(GMatDesc in, int sd, int sqd) {
  308. return std::make_tuple(in.withSizeDelta(1,1).withDepth(sd),
  309. in.withSizeDelta(1,1).withDepth(sqd));
  310. }
  311. };
  312. G_TYPED_KERNEL(GThreshold, <GMat(GMat, GScalar, GScalar, int)>, "org.opencv.core.matrixop.threshold") {
  313. static GMatDesc outMeta(GMatDesc in, GScalarDesc, GScalarDesc, int) {
  314. return in;
  315. }
  316. };
  317. G_TYPED_KERNEL_M(GThresholdOT, <GMatScalar(GMat, GScalar, int)>, "org.opencv.core.matrixop.thresholdOT") {
  318. static std::tuple<GMatDesc,GScalarDesc> outMeta(GMatDesc in, GScalarDesc, int) {
  319. return std::make_tuple(in, empty_scalar_desc());
  320. }
  321. };
  322. G_TYPED_KERNEL(GInRange, <GMat(GMat, GScalar, GScalar)>, "org.opencv.core.matrixop.inrange") {
  323. static GMatDesc outMeta(GMatDesc in, GScalarDesc, GScalarDesc) {
  324. return in.withType(CV_8U, 1);
  325. }
  326. };
  327. G_TYPED_KERNEL_M(GSplit3, <GMat3(GMat)>, "org.opencv.core.transform.split3") {
  328. static std::tuple<GMatDesc, GMatDesc, GMatDesc> outMeta(GMatDesc in) {
  329. const auto out_depth = in.depth;
  330. const auto out_desc = in.withType(out_depth, 1);
  331. return std::make_tuple(out_desc, out_desc, out_desc);
  332. }
  333. };
  334. G_TYPED_KERNEL_M(GSplit4, <GMat4(GMat)>,"org.opencv.core.transform.split4") {
  335. static std::tuple<GMatDesc, GMatDesc, GMatDesc, GMatDesc> outMeta(GMatDesc in) {
  336. const auto out_depth = in.depth;
  337. const auto out_desc = in.withType(out_depth, 1);
  338. return std::make_tuple(out_desc, out_desc, out_desc, out_desc);
  339. }
  340. };
  341. G_TYPED_KERNEL(GMerge3, <GMat(GMat,GMat,GMat)>, "org.opencv.core.transform.merge3") {
  342. static GMatDesc outMeta(GMatDesc in, GMatDesc, GMatDesc) {
  343. // Preserve depth and add channel component
  344. return in.withType(in.depth, 3);
  345. }
  346. };
  347. G_TYPED_KERNEL(GMerge4, <GMat(GMat,GMat,GMat,GMat)>, "org.opencv.core.transform.merge4") {
  348. static GMatDesc outMeta(GMatDesc in, GMatDesc, GMatDesc, GMatDesc) {
  349. // Preserve depth and add channel component
  350. return in.withType(in.depth, 4);
  351. }
  352. };
  353. G_TYPED_KERNEL(GRemap, <GMat(GMat, Mat, Mat, int, int, Scalar)>, "org.opencv.core.transform.remap") {
  354. static GMatDesc outMeta(GMatDesc in, Mat m1, Mat, int, int, Scalar) {
  355. return in.withSize(m1.size());
  356. }
  357. };
  358. G_TYPED_KERNEL(GFlip, <GMat(GMat, int)>, "org.opencv.core.transform.flip") {
  359. static GMatDesc outMeta(GMatDesc in, int) {
  360. return in;
  361. }
  362. };
  363. // TODO: eliminate the need in this kernel (streaming)
  364. G_TYPED_KERNEL(GCrop, <GMat(GMat, Rect)>, "org.opencv.core.transform.crop") {
  365. static GMatDesc outMeta(GMatDesc in, Rect rc) {
  366. return in.withSize(Size(rc.width, rc.height));
  367. }
  368. };
  369. G_TYPED_KERNEL(GConcatHor, <GMat(GMat, GMat)>, "org.opencv.imgproc.transform.concatHor") {
  370. static GMatDesc outMeta(GMatDesc l, GMatDesc r) {
  371. return l.withSizeDelta(+r.size.width, 0);
  372. }
  373. };
  374. G_TYPED_KERNEL(GConcatVert, <GMat(GMat, GMat)>, "org.opencv.imgproc.transform.concatVert") {
  375. static GMatDesc outMeta(GMatDesc t, GMatDesc b) {
  376. return t.withSizeDelta(0, +b.size.height);
  377. }
  378. };
  379. G_TYPED_KERNEL(GLUT, <GMat(GMat, Mat)>, "org.opencv.core.transform.LUT") {
  380. static GMatDesc outMeta(GMatDesc in, Mat) {
  381. return in;
  382. }
  383. };
  384. G_TYPED_KERNEL(GConvertTo, <GMat(GMat, int, double, double)>, "org.opencv.core.transform.convertTo") {
  385. static GMatDesc outMeta(GMatDesc in, int rdepth, double, double) {
  386. return rdepth < 0 ? in : in.withDepth(rdepth);
  387. }
  388. };
  389. G_TYPED_KERNEL(GSqrt, <GMat(GMat)>, "org.opencv.core.math.sqrt") {
  390. static GMatDesc outMeta(GMatDesc in) {
  391. return in;
  392. }
  393. };
  394. G_TYPED_KERNEL(GNormalize, <GMat(GMat, double, double, int, int)>, "org.opencv.core.normalize") {
  395. static GMatDesc outMeta(GMatDesc in, double, double, int, int ddepth) {
  396. // unlike opencv doesn't have a mask as a parameter
  397. return (ddepth < 0 ? in : in.withDepth(ddepth));
  398. }
  399. };
  400. G_TYPED_KERNEL(GWarpPerspective, <GMat(GMat, const Mat&, Size, int, int, const cv::Scalar&)>, "org.opencv.core.warpPerspective") {
  401. static GMatDesc outMeta(GMatDesc in, const Mat&, Size dsize, int, int borderMode, const cv::Scalar&) {
  402. GAPI_Assert((borderMode == cv::BORDER_CONSTANT || borderMode == cv::BORDER_REPLICATE) &&
  403. "cv::gapi::warpPerspective supports only cv::BORDER_CONSTANT and cv::BORDER_REPLICATE border modes");
  404. return in.withType(in.depth, in.chan).withSize(dsize);
  405. }
  406. };
  407. G_TYPED_KERNEL(GWarpAffine, <GMat(GMat, const Mat&, Size, int, int, const cv::Scalar&)>, "org.opencv.core.warpAffine") {
  408. static GMatDesc outMeta(GMatDesc in, const Mat&, Size dsize, int, int border_mode, const cv::Scalar&) {
  409. GAPI_Assert(border_mode != cv::BORDER_TRANSPARENT &&
  410. "cv::BORDER_TRANSPARENT mode is not supported in cv::gapi::warpAffine");
  411. return in.withType(in.depth, in.chan).withSize(dsize);
  412. }
  413. };
  414. G_TYPED_KERNEL(
  415. GKMeansND,
  416. <std::tuple<GOpaque<double>,GMat,GMat>(GMat,int,GMat,TermCriteria,int,KmeansFlags)>,
  417. "org.opencv.core.kmeansND") {
  418. static std::tuple<GOpaqueDesc,GMatDesc,GMatDesc>
  419. outMeta(const GMatDesc& in, int K, const GMatDesc& bestLabels, const TermCriteria&, int,
  420. KmeansFlags flags) {
  421. GAPI_Assert(in.depth == CV_32F);
  422. std::vector<int> amount_n_dim = detail::checkVector(in);
  423. int amount = amount_n_dim[0], dim = amount_n_dim[1];
  424. if (amount == -1) // Mat with height != 1, width != 1, channels != 1 given
  425. { // which means that kmeans will consider the following:
  426. amount = in.size.height;
  427. dim = in.size.width * in.chan;
  428. }
  429. // kmeans sets these labels' sizes when no bestLabels given:
  430. GMatDesc out_labels(CV_32S, 1, Size{1, amount});
  431. // kmeans always sets these centers' sizes:
  432. GMatDesc centers (CV_32F, 1, Size{dim, K});
  433. if (flags & KMEANS_USE_INITIAL_LABELS)
  434. {
  435. GAPI_Assert(bestLabels.depth == CV_32S);
  436. int labels_amount = detail::checkVector(bestLabels, 1u);
  437. GAPI_Assert(labels_amount == amount);
  438. out_labels = bestLabels; // kmeans preserves bestLabels' sizes if given
  439. }
  440. return std::make_tuple(empty_gopaque_desc(), out_labels, centers);
  441. }
  442. };
  443. G_TYPED_KERNEL(
  444. GKMeansNDNoInit,
  445. <std::tuple<GOpaque<double>,GMat,GMat>(GMat,int,TermCriteria,int,KmeansFlags)>,
  446. "org.opencv.core.kmeansNDNoInit") {
  447. static std::tuple<GOpaqueDesc,GMatDesc,GMatDesc>
  448. outMeta(const GMatDesc& in, int K, const TermCriteria&, int, KmeansFlags flags) {
  449. GAPI_Assert( !(flags & KMEANS_USE_INITIAL_LABELS) );
  450. GAPI_Assert(in.depth == CV_32F);
  451. std::vector<int> amount_n_dim = detail::checkVector(in);
  452. int amount = amount_n_dim[0], dim = amount_n_dim[1];
  453. if (amount == -1) // Mat with height != 1, width != 1, channels != 1 given
  454. { // which means that kmeans will consider the following:
  455. amount = in.size.height;
  456. dim = in.size.width * in.chan;
  457. }
  458. GMatDesc out_labels(CV_32S, 1, Size{1, amount});
  459. GMatDesc centers (CV_32F, 1, Size{dim, K});
  460. return std::make_tuple(empty_gopaque_desc(), out_labels, centers);
  461. }
  462. };
  463. G_TYPED_KERNEL(GKMeans2D, <std::tuple<GOpaque<double>,GArray<int>,GArray<Point2f>>
  464. (GArray<Point2f>,int,GArray<int>,TermCriteria,int,KmeansFlags)>,
  465. "org.opencv.core.kmeans2D") {
  466. static std::tuple<GOpaqueDesc,GArrayDesc,GArrayDesc>
  467. outMeta(const GArrayDesc&,int,const GArrayDesc&,const TermCriteria&,int,KmeansFlags) {
  468. return std::make_tuple(empty_gopaque_desc(), empty_array_desc(), empty_array_desc());
  469. }
  470. };
  471. G_TYPED_KERNEL(GKMeans3D, <std::tuple<GOpaque<double>,GArray<int>,GArray<Point3f>>
  472. (GArray<Point3f>,int,GArray<int>,TermCriteria,int,KmeansFlags)>,
  473. "org.opencv.core.kmeans3D") {
  474. static std::tuple<GOpaqueDesc,GArrayDesc,GArrayDesc>
  475. outMeta(const GArrayDesc&,int,const GArrayDesc&,const TermCriteria&,int,KmeansFlags) {
  476. return std::make_tuple(empty_gopaque_desc(), empty_array_desc(), empty_array_desc());
  477. }
  478. };
  479. G_TYPED_KERNEL(GTranspose, <GMat(GMat)>, "org.opencv.core.transpose") {
  480. static GMatDesc outMeta(GMatDesc in) {
  481. return in.withSize({in.size.height, in.size.width});
  482. }
  483. };
  484. } // namespace core
  485. namespace streaming {
  486. // Operations for Streaming (declared in this header for convenience)
  487. G_TYPED_KERNEL(GSize, <GOpaque<Size>(GMat)>, "org.opencv.streaming.size") {
  488. static GOpaqueDesc outMeta(const GMatDesc&) {
  489. return empty_gopaque_desc();
  490. }
  491. };
  492. G_TYPED_KERNEL(GSizeR, <GOpaque<Size>(GOpaque<Rect>)>, "org.opencv.streaming.sizeR") {
  493. static GOpaqueDesc outMeta(const GOpaqueDesc&) {
  494. return empty_gopaque_desc();
  495. }
  496. };
  497. G_TYPED_KERNEL(GSizeMF, <GOpaque<Size>(GFrame)>, "org.opencv.streaming.sizeMF") {
  498. static GOpaqueDesc outMeta(const GFrameDesc&) {
  499. return empty_gopaque_desc();
  500. }
  501. };
  502. } // namespace streaming
  503. //! @addtogroup gapi_math
  504. //! @{
  505. /** @brief Calculates the per-element sum of two matrices.
  506. The function add calculates sum of two matrices of the same size and the same number of channels:
  507. \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) + \texttt{src2}(I)) \quad \texttt{if mask}(I) \ne0\f]
  508. The function can be replaced with matrix expressions:
  509. \f[\texttt{dst} = \texttt{src1} + \texttt{src2}\f]
  510. The input matrices and the output matrix can all have the same or different depths. For example, you
  511. can add a 16-bit unsigned matrix to a 8-bit signed matrix and store the sum as a 32-bit
  512. floating-point matrix. Depth of the output matrix is determined by the ddepth parameter.
  513. If src1.depth() == src2.depth(), ddepth can be set to the default -1. In this case, the output matrix will have
  514. the same depth as the input matrices.
  515. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  516. @note Function textual ID is "org.opencv.core.math.add"
  517. @param src1 first input matrix.
  518. @param src2 second input matrix.
  519. @param ddepth optional depth of the output matrix.
  520. @sa sub, addWeighted
  521. */
  522. GAPI_EXPORTS_W GMat add(const GMat& src1, const GMat& src2, int ddepth = -1);
  523. /** @brief Calculates the per-element sum of matrix and given scalar.
  524. The function addC adds a given scalar value to each element of given matrix.
  525. The function can be replaced with matrix expressions:
  526. \f[\texttt{dst} = \texttt{src1} + \texttt{c}\f]
  527. Depth of the output matrix is determined by the ddepth parameter.
  528. If ddepth is set to default -1, the depth of output matrix will be the same as the depth of input matrix.
  529. The matrices can be single or multi channel. Output matrix must have the same size and number of channels as the input matrix.
  530. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  531. @note Function textual ID is "org.opencv.core.math.addC"
  532. @param src1 first input matrix.
  533. @param c scalar value to be added.
  534. @param ddepth optional depth of the output matrix.
  535. @sa sub, addWeighted
  536. */
  537. GAPI_EXPORTS_W GMat addC(const GMat& src1, const GScalar& c, int ddepth = -1);
  538. //! @overload
  539. GAPI_EXPORTS_W GMat addC(const GScalar& c, const GMat& src1, int ddepth = -1);
  540. /** @brief Calculates the per-element difference between two matrices.
  541. The function sub calculates difference between two matrices, when both matrices have the same size and the same number of
  542. channels:
  543. \f[\texttt{dst}(I) = \texttt{src1}(I) - \texttt{src2}(I)\f]
  544. The function can be replaced with matrix expressions:
  545. \f[\texttt{dst} = \texttt{src1} - \texttt{src2}\f]
  546. The input matrices and the output matrix can all have the same or different depths. For example, you
  547. can subtract two 8-bit unsigned matrices store the result as a 16-bit signed matrix.
  548. Depth of the output matrix is determined by the ddepth parameter.
  549. If src1.depth() == src2.depth(), ddepth can be set to the default -1. In this case, the output matrix will have
  550. the same depth as the input matrices. The matrices can be single or multi channel.
  551. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  552. @note Function textual ID is "org.opencv.core.math.sub"
  553. @param src1 first input matrix.
  554. @param src2 second input matrix.
  555. @param ddepth optional depth of the output matrix.
  556. @sa add, addC
  557. */
  558. GAPI_EXPORTS_W GMat sub(const GMat& src1, const GMat& src2, int ddepth = -1);
  559. /** @brief Calculates the per-element difference between matrix and given scalar.
  560. The function can be replaced with matrix expressions:
  561. \f[\texttt{dst} = \texttt{src} - \texttt{c}\f]
  562. Depth of the output matrix is determined by the ddepth parameter.
  563. If ddepth is set to default -1, the depth of output matrix will be the same as the depth of input matrix.
  564. The matrices can be single or multi channel. Output matrix must have the same size as src.
  565. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  566. @note Function textual ID is "org.opencv.core.math.subC"
  567. @param src first input matrix.
  568. @param c scalar value to subtracted.
  569. @param ddepth optional depth of the output matrix.
  570. @sa add, addC, subRC
  571. */
  572. GAPI_EXPORTS_W GMat subC(const GMat& src, const GScalar& c, int ddepth = -1);
  573. /** @brief Calculates the per-element difference between given scalar and the matrix.
  574. The function can be replaced with matrix expressions:
  575. \f[\texttt{dst} = \texttt{c} - \texttt{src}\f]
  576. Depth of the output matrix is determined by the ddepth parameter.
  577. If ddepth is set to default -1, the depth of output matrix will be the same as the depth of input matrix.
  578. The matrices can be single or multi channel. Output matrix must have the same size as src.
  579. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  580. @note Function textual ID is "org.opencv.core.math.subRC"
  581. @param c scalar value to subtract from.
  582. @param src input matrix to be subtracted.
  583. @param ddepth optional depth of the output matrix.
  584. @sa add, addC, subC
  585. */
  586. GAPI_EXPORTS_W GMat subRC(const GScalar& c, const GMat& src, int ddepth = -1);
  587. /** @brief Calculates the per-element scaled product of two matrices.
  588. The function mul calculates the per-element product of two matrices:
  589. \f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{scale} \cdot \texttt{src1} (I) \cdot \texttt{src2} (I))\f]
  590. If src1.depth() == src2.depth(), ddepth can be set to the default -1. In this case, the output matrix will have
  591. the same depth as the input matrices. The matrices can be single or multi channel.
  592. Output matrix must have the same size as input matrices.
  593. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  594. @note Function textual ID is "org.opencv.core.math.mul"
  595. @param src1 first input matrix.
  596. @param src2 second input matrix of the same size and the same depth as src1.
  597. @param scale optional scale factor.
  598. @param ddepth optional depth of the output matrix.
  599. @sa add, sub, div, addWeighted
  600. */
  601. GAPI_EXPORTS_W GMat mul(const GMat& src1, const GMat& src2, double scale = 1.0, int ddepth = -1);
  602. /** @brief Multiplies matrix by scalar.
  603. The function mulC multiplies each element of matrix src by given scalar value:
  604. \f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I) \cdot \texttt{multiplier} )\f]
  605. The matrices can be single or multi channel. Output matrix must have the same size as src.
  606. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  607. @note Function textual ID is "org.opencv.core.math.mulC"
  608. @param src input matrix.
  609. @param multiplier factor to be multiplied.
  610. @param ddepth optional depth of the output matrix. If -1, the depth of output matrix will be the same as input matrix depth.
  611. @sa add, sub, div, addWeighted
  612. */
  613. GAPI_EXPORTS_W GMat mulC(const GMat& src, double multiplier, int ddepth = -1);
  614. //! @overload
  615. GAPI_EXPORTS_W GMat mulC(const GMat& src, const GScalar& multiplier, int ddepth = -1); // FIXME: merge with mulc
  616. //! @overload
  617. GAPI_EXPORTS_W GMat mulC(const GScalar& multiplier, const GMat& src, int ddepth = -1); // FIXME: merge with mulc
  618. /** @brief Performs per-element division of two matrices.
  619. The function divides one matrix by another:
  620. \f[\texttt{dst(I) = saturate(src1(I)*scale/src2(I))}\f]
  621. For integer types when src2(I) is zero, dst(I) will also be zero.
  622. Floating point case returns Inf/NaN (according to IEEE).
  623. Different channels of
  624. multi-channel matrices are processed independently.
  625. The matrices can be single or multi channel. Output matrix must have the same size and depth as src.
  626. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  627. @note Function textual ID is "org.opencv.core.math.div"
  628. @param src1 first input matrix.
  629. @param src2 second input matrix of the same size and depth as src1.
  630. @param scale scalar factor.
  631. @param ddepth optional depth of the output matrix; you can only pass -1 when src1.depth() == src2.depth().
  632. @sa mul, add, sub
  633. */
  634. GAPI_EXPORTS_W GMat div(const GMat& src1, const GMat& src2, double scale, int ddepth = -1);
  635. /** @brief Divides matrix by scalar.
  636. The function divC divides each element of matrix src by given scalar value:
  637. \f[\texttt{dst(I) = saturate(src(I)*scale/divisor)}\f]
  638. When divisor is zero, dst(I) will also be zero. Different channels of
  639. multi-channel matrices are processed independently.
  640. The matrices can be single or multi channel. Output matrix must have the same size and depth as src.
  641. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  642. @note Function textual ID is "org.opencv.core.math.divC"
  643. @param src input matrix.
  644. @param divisor number to be divided by.
  645. @param ddepth optional depth of the output matrix. If -1, the depth of output matrix will be the same as input matrix depth.
  646. @param scale scale factor.
  647. @sa add, sub, div, addWeighted
  648. */
  649. GAPI_EXPORTS_W GMat divC(const GMat& src, const GScalar& divisor, double scale, int ddepth = -1);
  650. /** @brief Divides scalar by matrix.
  651. The function divRC divides given scalar by each element of matrix src and keep the division result in new matrix of the same size and type as src:
  652. \f[\texttt{dst(I) = saturate(divident*scale/src(I))}\f]
  653. When src(I) is zero, dst(I) will also be zero. Different channels of
  654. multi-channel matrices are processed independently.
  655. The matrices can be single or multi channel. Output matrix must have the same size and depth as src.
  656. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  657. @note Function textual ID is "org.opencv.core.math.divRC"
  658. @param src input matrix.
  659. @param divident number to be divided.
  660. @param ddepth optional depth of the output matrix. If -1, the depth of output matrix will be the same as input matrix depth.
  661. @param scale scale factor
  662. @sa add, sub, div, addWeighted
  663. */
  664. GAPI_EXPORTS_W GMat divRC(const GScalar& divident, const GMat& src, double scale, int ddepth = -1);
  665. /** @brief Applies a mask to a matrix.
  666. The function mask set value from given matrix if the corresponding pixel value in mask matrix set to true,
  667. and set the matrix value to 0 otherwise.
  668. Supported src matrix data types are @ref CV_8UC1, @ref CV_16SC1, @ref CV_16UC1. Supported mask data type is @ref CV_8UC1.
  669. @note Function textual ID is "org.opencv.core.math.mask"
  670. @param src input matrix.
  671. @param mask input mask matrix.
  672. */
  673. GAPI_EXPORTS_W GMat mask(const GMat& src, const GMat& mask);
  674. /** @brief Calculates an average (mean) of matrix elements.
  675. The function mean calculates the mean value M of matrix elements,
  676. independently for each channel, and return it.
  677. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  678. @note Function textual ID is "org.opencv.core.math.mean"
  679. @param src input matrix.
  680. @sa countNonZero, min, max
  681. */
  682. GAPI_EXPORTS_W GScalar mean(const GMat& src);
  683. /** @brief Calculates x and y coordinates of 2D vectors from their magnitude and angle.
  684. The function polarToCart calculates the Cartesian coordinates of each 2D
  685. vector represented by the corresponding elements of magnitude and angle:
  686. \f[\begin{array}{l} \texttt{x} (I) = \texttt{magnitude} (I) \cos ( \texttt{angle} (I)) \\ \texttt{y} (I) = \texttt{magnitude} (I) \sin ( \texttt{angle} (I)) \\ \end{array}\f]
  687. The relative accuracy of the estimated coordinates is about 1e-6.
  688. First output is a matrix of x-coordinates of 2D vectors.
  689. Second output is a matrix of y-coordinates of 2D vectors.
  690. Both output must have the same size and depth as input matrices.
  691. @note Function textual ID is "org.opencv.core.math.polarToCart"
  692. @param magnitude input floating-point @ref CV_32FC1 matrix (1xN) of magnitudes of 2D vectors;
  693. @param angle input floating-point @ref CV_32FC1 matrix (1xN) of angles of 2D vectors.
  694. @param angleInDegrees when true, the input angles are measured in
  695. degrees, otherwise, they are measured in radians.
  696. @sa cartToPolar, exp, log, pow, sqrt
  697. */
  698. GAPI_EXPORTS_W std::tuple<GMat, GMat> polarToCart(const GMat& magnitude, const GMat& angle,
  699. bool angleInDegrees = false);
  700. /** @brief Calculates the magnitude and angle of 2D vectors.
  701. The function cartToPolar calculates either the magnitude, angle, or both
  702. for every 2D vector (x(I),y(I)):
  703. \f[\begin{array}{l} \texttt{magnitude} (I)= \sqrt{\texttt{x}(I)^2+\texttt{y}(I)^2} , \\ \texttt{angle} (I)= \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))[ \cdot180 / \pi ] \end{array}\f]
  704. The angles are calculated with accuracy about 0.3 degrees. For the point
  705. (0,0), the angle is set to 0.
  706. First output is a matrix of magnitudes of the same size and depth as input x.
  707. Second output is a matrix of angles that has the same size and depth as
  708. x; the angles are measured in radians (from 0 to 2\*Pi) or in degrees (0 to 360 degrees).
  709. @note Function textual ID is "org.opencv.core.math.cartToPolar"
  710. @param x matrix of @ref CV_32FC1 x-coordinates.
  711. @param y array of @ref CV_32FC1 y-coordinates.
  712. @param angleInDegrees a flag, indicating whether the angles are measured
  713. in radians (which is by default), or in degrees.
  714. @sa polarToCart
  715. */
  716. GAPI_EXPORTS_W std::tuple<GMat, GMat> cartToPolar(const GMat& x, const GMat& y,
  717. bool angleInDegrees = false);
  718. /** @brief Calculates the rotation angle of 2D vectors.
  719. The function cv::phase calculates the rotation angle of each 2D vector that
  720. is formed from the corresponding elements of x and y :
  721. \f[\texttt{angle} (I) = \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))\f]
  722. The angle estimation accuracy is about 0.3 degrees. When x(I)=y(I)=0 ,
  723. the corresponding angle(I) is set to 0.
  724. @param x input floating-point array of x-coordinates of 2D vectors.
  725. @param y input array of y-coordinates of 2D vectors; it must have the
  726. same size and the same type as x.
  727. @param angleInDegrees when true, the function calculates the angle in
  728. degrees, otherwise, they are measured in radians.
  729. @return array of vector angles; it has the same size and same type as x.
  730. */
  731. GAPI_EXPORTS_W GMat phase(const GMat& x, const GMat &y, bool angleInDegrees = false);
  732. /** @brief Calculates a square root of array elements.
  733. The function cv::gapi::sqrt calculates a square root of each input array element.
  734. In case of multi-channel arrays, each channel is processed
  735. independently. The accuracy is approximately the same as of the built-in
  736. std::sqrt .
  737. @param src input floating-point array.
  738. @return output array of the same size and type as src.
  739. */
  740. GAPI_EXPORTS_W GMat sqrt(const GMat &src);
  741. //! @} gapi_math
  742. //!
  743. //! @addtogroup gapi_pixelwise
  744. //! @{
  745. /** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are greater compare to elements in second.
  746. The function compares elements of two matrices src1 and src2 of the same size:
  747. \f[\texttt{dst} (I) = \texttt{src1} (I) > \texttt{src2} (I)\f]
  748. When the comparison result is true, the corresponding element of output
  749. array is set to 255. The comparison operations can be replaced with the
  750. equivalent matrix expressions:
  751. \f[\texttt{dst} = \texttt{src1} > \texttt{src2}\f]
  752. Output matrix of depth @ref CV_8U must have the same size and the same number of channels as
  753. the input matrices/matrix.
  754. Supported input matrix data types are @ref CV_8UC1, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  755. @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpGT"
  756. @param src1 first input matrix.
  757. @param src2 second input matrix/scalar of the same depth as first input matrix.
  758. @sa min, max, threshold, cmpLE, cmpGE, cmpLT
  759. */
  760. GAPI_EXPORTS_W GMat cmpGT(const GMat& src1, const GMat& src2);
  761. /** @overload
  762. @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpGTScalar"
  763. */
  764. GAPI_EXPORTS_W GMat cmpGT(const GMat& src1, const GScalar& src2);
  765. /** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are less than elements in second.
  766. The function compares elements of two matrices src1 and src2 of the same size:
  767. \f[\texttt{dst} (I) = \texttt{src1} (I) < \texttt{src2} (I)\f]
  768. When the comparison result is true, the corresponding element of output
  769. array is set to 255. The comparison operations can be replaced with the
  770. equivalent matrix expressions:
  771. \f[\texttt{dst} = \texttt{src1} < \texttt{src2}\f]
  772. Output matrix of depth @ref CV_8U must have the same size and the same number of channels as
  773. the input matrices/matrix.
  774. Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  775. @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLT"
  776. @param src1 first input matrix.
  777. @param src2 second input matrix/scalar of the same depth as first input matrix.
  778. @sa min, max, threshold, cmpLE, cmpGE, cmpGT
  779. */
  780. GAPI_EXPORTS_W GMat cmpLT(const GMat& src1, const GMat& src2);
  781. /** @overload
  782. @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLTScalar"
  783. */
  784. GAPI_EXPORTS_W GMat cmpLT(const GMat& src1, const GScalar& src2);
  785. /** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are greater or equal compare to elements in second.
  786. The function compares elements of two matrices src1 and src2 of the same size:
  787. \f[\texttt{dst} (I) = \texttt{src1} (I) >= \texttt{src2} (I)\f]
  788. When the comparison result is true, the corresponding element of output
  789. array is set to 255. The comparison operations can be replaced with the
  790. equivalent matrix expressions:
  791. \f[\texttt{dst} = \texttt{src1} >= \texttt{src2}\f]
  792. Output matrix of depth @ref CV_8U must have the same size and the same number of channels as
  793. the input matrices.
  794. Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  795. @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpGE"
  796. @param src1 first input matrix.
  797. @param src2 second input matrix/scalar of the same depth as first input matrix.
  798. @sa min, max, threshold, cmpLE, cmpGT, cmpLT
  799. */
  800. GAPI_EXPORTS_W GMat cmpGE(const GMat& src1, const GMat& src2);
  801. /** @overload
  802. @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLGEcalar"
  803. */
  804. GAPI_EXPORTS_W GMat cmpGE(const GMat& src1, const GScalar& src2);
  805. /** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are less or equal compare to elements in second.
  806. The function compares elements of two matrices src1 and src2 of the same size:
  807. \f[\texttt{dst} (I) = \texttt{src1} (I) <= \texttt{src2} (I)\f]
  808. When the comparison result is true, the corresponding element of output
  809. array is set to 255. The comparison operations can be replaced with the
  810. equivalent matrix expressions:
  811. \f[\texttt{dst} = \texttt{src1} <= \texttt{src2}\f]
  812. Output matrix of depth @ref CV_8U must have the same size and the same number of channels as
  813. the input matrices.
  814. Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  815. @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLE"
  816. @param src1 first input matrix.
  817. @param src2 second input matrix/scalar of the same depth as first input matrix.
  818. @sa min, max, threshold, cmpGT, cmpGE, cmpLT
  819. */
  820. GAPI_EXPORTS_W GMat cmpLE(const GMat& src1, const GMat& src2);
  821. /** @overload
  822. @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLEScalar"
  823. */
  824. GAPI_EXPORTS_W GMat cmpLE(const GMat& src1, const GScalar& src2);
  825. /** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are equal to elements in second.
  826. The function compares elements of two matrices src1 and src2 of the same size:
  827. \f[\texttt{dst} (I) = \texttt{src1} (I) == \texttt{src2} (I)\f]
  828. When the comparison result is true, the corresponding element of output
  829. array is set to 255. The comparison operations can be replaced with the
  830. equivalent matrix expressions:
  831. \f[\texttt{dst} = \texttt{src1} == \texttt{src2}\f]
  832. Output matrix of depth @ref CV_8U must have the same size and the same number of channels as
  833. the input matrices.
  834. Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  835. @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpEQ"
  836. @param src1 first input matrix.
  837. @param src2 second input matrix/scalar of the same depth as first input matrix.
  838. @sa min, max, threshold, cmpNE
  839. */
  840. GAPI_EXPORTS_W GMat cmpEQ(const GMat& src1, const GMat& src2);
  841. /** @overload
  842. @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpEQScalar"
  843. */
  844. GAPI_EXPORTS_W GMat cmpEQ(const GMat& src1, const GScalar& src2);
  845. /** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are not equal to elements in second.
  846. The function compares elements of two matrices src1 and src2 of the same size:
  847. \f[\texttt{dst} (I) = \texttt{src1} (I) != \texttt{src2} (I)\f]
  848. When the comparison result is true, the corresponding element of output
  849. array is set to 255. The comparison operations can be replaced with the
  850. equivalent matrix expressions:
  851. \f[\texttt{dst} = \texttt{src1} != \texttt{src2}\f]
  852. Output matrix of depth @ref CV_8U must have the same size and the same number of channels as
  853. the input matrices.
  854. Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  855. @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpNE"
  856. @param src1 first input matrix.
  857. @param src2 second input matrix/scalar of the same depth as first input matrix.
  858. @sa min, max, threshold, cmpEQ
  859. */
  860. GAPI_EXPORTS_W GMat cmpNE(const GMat& src1, const GMat& src2);
  861. /** @overload
  862. @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpNEScalar"
  863. */
  864. GAPI_EXPORTS_W GMat cmpNE(const GMat& src1, const GScalar& src2);
  865. /** @brief computes bitwise conjunction of the two matrixes (src1 & src2)
  866. Calculates the per-element bit-wise logical conjunction of two matrices of the same size.
  867. In case of floating-point matrices, their machine-specific bit
  868. representations (usually IEEE754-compliant) are used for the operation.
  869. In case of multi-channel matrices, each channel is processed
  870. independently. Output matrix must have the same size and depth as the input
  871. matrices.
  872. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  873. @note Function textual ID is "org.opencv.core.pixelwise.bitwise_and"
  874. @param src1 first input matrix.
  875. @param src2 second input matrix.
  876. */
  877. GAPI_EXPORTS_W GMat bitwise_and(const GMat& src1, const GMat& src2);
  878. /** @overload
  879. @note Function textual ID is "org.opencv.core.pixelwise.bitwise_andS"
  880. @param src1 first input matrix.
  881. @param src2 scalar, which will be per-lemenetly conjuncted with elements of src1.
  882. */
  883. GAPI_EXPORTS_W GMat bitwise_and(const GMat& src1, const GScalar& src2);
  884. /** @brief computes bitwise disjunction of the two matrixes (src1 | src2)
  885. Calculates the per-element bit-wise logical disjunction of two matrices of the same size.
  886. In case of floating-point matrices, their machine-specific bit
  887. representations (usually IEEE754-compliant) are used for the operation.
  888. In case of multi-channel matrices, each channel is processed
  889. independently. Output matrix must have the same size and depth as the input
  890. matrices.
  891. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  892. @note Function textual ID is "org.opencv.core.pixelwise.bitwise_or"
  893. @param src1 first input matrix.
  894. @param src2 second input matrix.
  895. */
  896. GAPI_EXPORTS_W GMat bitwise_or(const GMat& src1, const GMat& src2);
  897. /** @overload
  898. @note Function textual ID is "org.opencv.core.pixelwise.bitwise_orS"
  899. @param src1 first input matrix.
  900. @param src2 scalar, which will be per-lemenetly disjuncted with elements of src1.
  901. */
  902. GAPI_EXPORTS_W GMat bitwise_or(const GMat& src1, const GScalar& src2);
  903. /** @brief computes bitwise logical "exclusive or" of the two matrixes (src1 ^ src2)
  904. Calculates the per-element bit-wise logical "exclusive or" of two matrices of the same size.
  905. In case of floating-point matrices, their machine-specific bit
  906. representations (usually IEEE754-compliant) are used for the operation.
  907. In case of multi-channel matrices, each channel is processed
  908. independently. Output matrix must have the same size and depth as the input
  909. matrices.
  910. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  911. @note Function textual ID is "org.opencv.core.pixelwise.bitwise_xor"
  912. @param src1 first input matrix.
  913. @param src2 second input matrix.
  914. */
  915. GAPI_EXPORTS_W GMat bitwise_xor(const GMat& src1, const GMat& src2);
  916. /** @overload
  917. @note Function textual ID is "org.opencv.core.pixelwise.bitwise_xorS"
  918. @param src1 first input matrix.
  919. @param src2 scalar, for which per-lemenet "logical or" operation on elements of src1 will be performed.
  920. */
  921. GAPI_EXPORTS_W GMat bitwise_xor(const GMat& src1, const GScalar& src2);
  922. /** @brief Inverts every bit of an array.
  923. The function bitwise_not calculates per-element bit-wise inversion of the input
  924. matrix:
  925. \f[\texttt{dst} (I) = \neg \texttt{src} (I)\f]
  926. In case of floating-point matrices, their machine-specific bit
  927. representations (usually IEEE754-compliant) are used for the operation.
  928. In case of multi-channel matrices, each channel is processed
  929. independently. Output matrix must have the same size and depth as the input
  930. matrix.
  931. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  932. @note Function textual ID is "org.opencv.core.pixelwise.bitwise_not"
  933. @param src input matrix.
  934. */
  935. GAPI_EXPORTS_W GMat bitwise_not(const GMat& src);
  936. /** @brief Select values from either first or second of input matrices by given mask.
  937. The function set to the output matrix either the value from the first input matrix if corresponding value of mask matrix is 255,
  938. or value from the second input matrix (if value of mask matrix set to 0).
  939. Input mask matrix must be of @ref CV_8UC1 type, two other inout matrices and output matrix should be of the same type. The size should
  940. be the same for all input and output matrices.
  941. Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  942. @note Function textual ID is "org.opencv.core.pixelwise.select"
  943. @param src1 first input matrix.
  944. @param src2 second input matrix.
  945. @param mask mask input matrix.
  946. */
  947. GAPI_EXPORTS_W GMat select(const GMat& src1, const GMat& src2, const GMat& mask);
  948. //! @} gapi_pixelwise
  949. //! @addtogroup gapi_matrixop
  950. //! @{
  951. /** @brief Calculates per-element minimum of two matrices.
  952. The function min calculates the per-element minimum of two matrices of the same size, number of channels and depth:
  953. \f[\texttt{dst} (I)= \min ( \texttt{src1} (I), \texttt{src2} (I))\f]
  954. where I is a multi-dimensional index of matrix elements. In case of
  955. multi-channel matrices, each channel is processed independently.
  956. Output matrix must be of the same size and depth as src1.
  957. Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  958. @note Function textual ID is "org.opencv.core.matrixop.min"
  959. @param src1 first input matrix.
  960. @param src2 second input matrix of the same size and depth as src1.
  961. @sa max, cmpEQ, cmpLT, cmpLE
  962. */
  963. GAPI_EXPORTS_W GMat min(const GMat& src1, const GMat& src2);
  964. /** @brief Calculates per-element maximum of two matrices.
  965. The function max calculates the per-element maximum of two matrices of the same size, number of channels and depth:
  966. \f[\texttt{dst} (I)= \max ( \texttt{src1} (I), \texttt{src2} (I))\f]
  967. where I is a multi-dimensional index of matrix elements. In case of
  968. multi-channel matrices, each channel is processed independently.
  969. Output matrix must be of the same size and depth as src1.
  970. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  971. @note Function textual ID is "org.opencv.core.matrixop.max"
  972. @param src1 first input matrix.
  973. @param src2 second input matrix of the same size and depth as src1.
  974. @sa min, compare, cmpEQ, cmpGT, cmpGE
  975. */
  976. GAPI_EXPORTS_W GMat max(const GMat& src1, const GMat& src2);
  977. /** @brief Calculates the per-element absolute difference between two matrices.
  978. The function absDiff calculates absolute difference between two matrices of the same size and depth:
  979. \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1}(I) - \texttt{src2}(I)|)\f]
  980. where I is a multi-dimensional index of matrix elements. In case of
  981. multi-channel matrices, each channel is processed independently.
  982. Output matrix must have the same size and depth as input matrices.
  983. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  984. @note Function textual ID is "org.opencv.core.matrixop.absdiff"
  985. @param src1 first input matrix.
  986. @param src2 second input matrix.
  987. @sa abs
  988. */
  989. GAPI_EXPORTS_W GMat absDiff(const GMat& src1, const GMat& src2);
  990. /** @brief Calculates absolute value of matrix elements.
  991. The function abs calculates absolute difference between matrix elements and given scalar value:
  992. \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1}(I) - \texttt{matC}(I)|)\f]
  993. where matC is constructed from given scalar c and has the same sizes and depth as input matrix src.
  994. Output matrix must be of the same size and depth as src.
  995. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  996. @note Function textual ID is "org.opencv.core.matrixop.absdiffC"
  997. @param src input matrix.
  998. @param c scalar to be subtracted.
  999. @sa min, max
  1000. */
  1001. GAPI_EXPORTS_W GMat absDiffC(const GMat& src, const GScalar& c);
  1002. /** @brief Calculates sum of all matrix elements.
  1003. The function sum calculates sum of all matrix elements, independently for each channel.
  1004. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  1005. @note Function textual ID is "org.opencv.core.matrixop.sum"
  1006. @param src input matrix.
  1007. @sa countNonZero, mean, min, max
  1008. */
  1009. GAPI_EXPORTS_W GScalar sum(const GMat& src);
  1010. /** @brief Counts non-zero array elements.
  1011. The function returns the number of non-zero elements in src :
  1012. \f[\sum _{I: \; \texttt{src} (I) \ne0 } 1\f]
  1013. Supported matrix data types are @ref CV_8UC1, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  1014. @note Function textual ID is "org.opencv.core.matrixop.countNonZero"
  1015. @param src input single-channel matrix.
  1016. @sa mean, min, max
  1017. */
  1018. GAPI_EXPORTS_W GOpaque<int> countNonZero(const GMat& src);
  1019. /** @brief Calculates the weighted sum of two matrices.
  1020. The function addWeighted calculates the weighted sum of two matrices as follows:
  1021. \f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I)* \texttt{alpha} + \texttt{src2} (I)* \texttt{beta} + \texttt{gamma} )\f]
  1022. where I is a multi-dimensional index of array elements. In case of multi-channel matrices, each
  1023. channel is processed independently.
  1024. The function can be replaced with a matrix expression:
  1025. \f[\texttt{dst}(I) = \texttt{alpha} * \texttt{src1}(I) - \texttt{beta} * \texttt{src2}(I) + \texttt{gamma} \f]
  1026. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  1027. @note Function textual ID is "org.opencv.core.matrixop.addweighted"
  1028. @param src1 first input matrix.
  1029. @param alpha weight of the first matrix elements.
  1030. @param src2 second input matrix of the same size and channel number as src1.
  1031. @param beta weight of the second matrix elements.
  1032. @param gamma scalar added to each sum.
  1033. @param ddepth optional depth of the output matrix.
  1034. @sa add, sub
  1035. */
  1036. GAPI_EXPORTS_W GMat addWeighted(const GMat& src1, double alpha, const GMat& src2, double beta, double gamma, int ddepth = -1);
  1037. /** @brief Calculates the absolute L1 norm of a matrix.
  1038. This version of normL1 calculates the absolute L1 norm of src.
  1039. As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$.
  1040. The \f$ L_{1} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$
  1041. is calculated as follows
  1042. \f{align*}
  1043. \| r(-1) \|_{L_1} &= |-1| + |2| = 3 \\
  1044. \f}
  1045. and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is
  1046. \f{align*}
  1047. \| r(0.5) \|_{L_1} &= |0.5| + |0.5| = 1 \\
  1048. \f}
  1049. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  1050. @note Function textual ID is "org.opencv.core.matrixop.norml1"
  1051. @param src input matrix.
  1052. @sa normL2, normInf
  1053. */
  1054. GAPI_EXPORTS_W GScalar normL1(const GMat& src);
  1055. /** @brief Calculates the absolute L2 norm of a matrix.
  1056. This version of normL2 calculates the absolute L2 norm of src.
  1057. As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$.
  1058. The \f$ L_{2} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$
  1059. is calculated as follows
  1060. \f{align*}
  1061. \| r(-1) \|_{L_2} &= \sqrt{(-1)^{2} + (2)^{2}} = \sqrt{5} \\
  1062. \f}
  1063. and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is
  1064. \f{align*}
  1065. \| r(0.5) \|_{L_2} &= \sqrt{(0.5)^{2} + (0.5)^{2}} = \sqrt{0.5} \\
  1066. \f}
  1067. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  1068. @note Function textual ID is "org.opencv.core.matrixop.norml2"
  1069. @param src input matrix.
  1070. @sa normL1, normInf
  1071. */
  1072. GAPI_EXPORTS_W GScalar normL2(const GMat& src);
  1073. /** @brief Calculates the absolute infinite norm of a matrix.
  1074. This version of normInf calculates the absolute infinite norm of src.
  1075. As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$.
  1076. The \f$ L_{\infty} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$
  1077. is calculated as follows
  1078. \f{align*}
  1079. \| r(-1) \|_{L_\infty} &= \max(|-1|,|2|) = 2
  1080. \f}
  1081. and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is
  1082. \f{align*}
  1083. \| r(0.5) \|_{L_\infty} &= \max(|0.5|,|0.5|) = 0.5.
  1084. \f}
  1085. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  1086. @note Function textual ID is "org.opencv.core.matrixop.norminf"
  1087. @param src input matrix.
  1088. @sa normL1, normL2
  1089. */
  1090. GAPI_EXPORTS_W GScalar normInf(const GMat& src);
  1091. /** @brief Calculates the integral of an image.
  1092. The function calculates one or more integral images for the source image as follows:
  1093. \f[\texttt{sum} (X,Y) = \sum _{x<X,y<Y} \texttt{image} (x,y)\f]
  1094. \f[\texttt{sqsum} (X,Y) = \sum _{x<X,y<Y} \texttt{image} (x,y)^2\f]
  1095. The function return integral image as \f$(W+1)\times (H+1)\f$ , 32-bit integer or floating-point (32f or 64f) and
  1096. integral image for squared pixel values; it is \f$(W+1)\times (H+)\f$, double-precision floating-point (64f) array.
  1097. @note Function textual ID is "org.opencv.core.matrixop.integral"
  1098. @param src input image.
  1099. @param sdepth desired depth of the integral and the tilted integral images, CV_32S, CV_32F, or
  1100. CV_64F.
  1101. @param sqdepth desired depth of the integral image of squared pixel values, CV_32F or CV_64F.
  1102. */
  1103. GAPI_EXPORTS_W std::tuple<GMat, GMat> integral(const GMat& src, int sdepth = -1, int sqdepth = -1);
  1104. /** @brief Applies a fixed-level threshold to each matrix element.
  1105. The function applies fixed-level thresholding to a single- or multiple-channel matrix.
  1106. The function is typically used to get a bi-level (binary) image out of a grayscale image ( cmp functions could be also used for
  1107. this purpose) or for removing a noise, that is, filtering out pixels with too small or too large
  1108. values. There are several types of thresholding supported by the function. They are determined by
  1109. type parameter.
  1110. Also, the special values cv::THRESH_OTSU or cv::THRESH_TRIANGLE may be combined with one of the
  1111. above values. In these cases, the function determines the optimal threshold value using the Otsu's
  1112. or Triangle algorithm and uses it instead of the specified thresh . The function returns the
  1113. computed threshold value in addititon to thresholded matrix.
  1114. The Otsu's and Triangle methods are implemented only for 8-bit matrices.
  1115. Input image should be single channel only in case of cv::THRESH_OTSU or cv::THRESH_TRIANGLE flags.
  1116. Output matrix must be of the same size and depth as src.
  1117. @note Function textual ID is "org.opencv.core.matrixop.threshold"
  1118. @param src input matrix (@ref CV_8UC1, @ref CV_8UC3, or @ref CV_32FC1).
  1119. @param thresh threshold value.
  1120. @param maxval maximum value to use with the cv::THRESH_BINARY and cv::THRESH_BINARY_INV thresholding
  1121. types.
  1122. @param type thresholding type (see the cv::ThresholdTypes).
  1123. @sa min, max, cmpGT, cmpLE, cmpGE, cmpLT
  1124. */
  1125. GAPI_EXPORTS_W GMat threshold(const GMat& src, const GScalar& thresh, const GScalar& maxval, int type);
  1126. /** @overload
  1127. This function applicable for all threshold types except cv::THRESH_OTSU and cv::THRESH_TRIANGLE
  1128. @note Function textual ID is "org.opencv.core.matrixop.thresholdOT"
  1129. */
  1130. GAPI_EXPORTS_W std::tuple<GMat, GScalar> threshold(const GMat& src, const GScalar& maxval, int type);
  1131. /** @brief Applies a range-level threshold to each matrix element.
  1132. The function applies range-level thresholding to a single- or multiple-channel matrix.
  1133. It sets output pixel value to OxFF if the corresponding pixel value of input matrix is in specified range,or 0 otherwise.
  1134. Input and output matrices must be CV_8UC1.
  1135. @note Function textual ID is "org.opencv.core.matrixop.inRange"
  1136. @param src input matrix (CV_8UC1).
  1137. @param threshLow lower boundary value.
  1138. @param threshUp upper boundary value.
  1139. @sa threshold
  1140. */
  1141. GAPI_EXPORTS_W GMat inRange(const GMat& src, const GScalar& threshLow, const GScalar& threshUp);
  1142. //! @} gapi_matrixop
  1143. //! @addtogroup gapi_transform
  1144. //! @{
  1145. /** @brief Creates one 4-channel matrix out of 4 single-channel ones.
  1146. The function merges several matrices to make a single multi-channel matrix. That is, each
  1147. element of the output matrix will be a concatenation of the elements of the input matrices, where
  1148. elements of i-th input matrix are treated as mv[i].channels()-element vectors.
  1149. Output matrix must be of @ref CV_8UC4 type.
  1150. The function split4 does the reverse operation.
  1151. @note
  1152. - Function textual ID is "org.opencv.core.transform.merge4"
  1153. @param src1 first input @ref CV_8UC1 matrix to be merged.
  1154. @param src2 second input @ref CV_8UC1 matrix to be merged.
  1155. @param src3 third input @ref CV_8UC1 matrix to be merged.
  1156. @param src4 fourth input @ref CV_8UC1 matrix to be merged.
  1157. @sa merge3, split4, split3
  1158. */
  1159. GAPI_EXPORTS_W GMat merge4(const GMat& src1, const GMat& src2, const GMat& src3, const GMat& src4);
  1160. /** @brief Creates one 3-channel matrix out of 3 single-channel ones.
  1161. The function merges several matrices to make a single multi-channel matrix. That is, each
  1162. element of the output matrix will be a concatenation of the elements of the input matrices, where
  1163. elements of i-th input matrix are treated as mv[i].channels()-element vectors.
  1164. Output matrix must be of @ref CV_8UC3 type.
  1165. The function split3 does the reverse operation.
  1166. @note
  1167. - Function textual ID is "org.opencv.core.transform.merge3"
  1168. @param src1 first input @ref CV_8UC1 matrix to be merged.
  1169. @param src2 second input @ref CV_8UC1 matrix to be merged.
  1170. @param src3 third input @ref CV_8UC1 matrix to be merged.
  1171. @sa merge4, split4, split3
  1172. */
  1173. GAPI_EXPORTS_W GMat merge3(const GMat& src1, const GMat& src2, const GMat& src3);
  1174. /** @brief Divides a 4-channel matrix into 4 single-channel matrices.
  1175. The function splits a 4-channel matrix into 4 single-channel matrices:
  1176. \f[\texttt{mv} [c](I) = \texttt{src} (I)_c\f]
  1177. All output matrices must be of @ref CV_8UC1 type.
  1178. The function merge4 does the reverse operation.
  1179. @note
  1180. - Function textual ID is "org.opencv.core.transform.split4"
  1181. @param src input @ref CV_8UC4 matrix.
  1182. @sa split3, merge3, merge4
  1183. */
  1184. GAPI_EXPORTS_W std::tuple<GMat, GMat, GMat,GMat> split4(const GMat& src);
  1185. /** @brief Divides a 3-channel matrix into 3 single-channel matrices.
  1186. The function splits a 3-channel matrix into 3 single-channel matrices:
  1187. \f[\texttt{mv} [c](I) = \texttt{src} (I)_c\f]
  1188. All output matrices must be of @ref CV_8UC1 type.
  1189. The function merge3 does the reverse operation.
  1190. @note
  1191. - Function textual ID is "org.opencv.core.transform.split3"
  1192. @param src input @ref CV_8UC3 matrix.
  1193. @sa split4, merge3, merge4
  1194. */
  1195. GAPI_EXPORTS_W std::tuple<GMat, GMat, GMat> split3(const GMat& src);
  1196. /** @brief Applies a generic geometrical transformation to an image.
  1197. The function remap transforms the source image using the specified map:
  1198. \f[\texttt{dst} (x,y) = \texttt{src} (map_x(x,y),map_y(x,y))\f]
  1199. where values of pixels with non-integer coordinates are computed using one of available
  1200. interpolation methods. \f$map_x\f$ and \f$map_y\f$ can be encoded as separate floating-point maps
  1201. in \f$map_1\f$ and \f$map_2\f$ respectively, or interleaved floating-point maps of \f$(x,y)\f$ in
  1202. \f$map_1\f$, or fixed-point maps created by using convertMaps. The reason you might want to
  1203. convert from floating to fixed-point representations of a map is that they can yield much faster
  1204. (\~2x) remapping operations. In the converted case, \f$map_1\f$ contains pairs (cvFloor(x),
  1205. cvFloor(y)) and \f$map_2\f$ contains indices in a table of interpolation coefficients.
  1206. Output image must be of the same size and depth as input one.
  1207. @note
  1208. - Function textual ID is "org.opencv.core.transform.remap"
  1209. - Due to current implementation limitations the size of an input and output images should be less than 32767x32767.
  1210. @param src Source image.
  1211. @param map1 The first map of either (x,y) points or just x values having the type CV_16SC2,
  1212. CV_32FC1, or CV_32FC2.
  1213. @param map2 The second map of y values having the type CV_16UC1, CV_32FC1, or none (empty map
  1214. if map1 is (x,y) points), respectively.
  1215. @param interpolation Interpolation method (see cv::InterpolationFlags). The methods #INTER_AREA
  1216. and #INTER_LINEAR_EXACT are not supported by this function.
  1217. @param borderMode Pixel extrapolation method (see cv::BorderTypes). When
  1218. borderMode=BORDER_TRANSPARENT, it means that the pixels in the destination image that
  1219. corresponds to the "outliers" in the source image are not modified by the function.
  1220. @param borderValue Value used in case of a constant border. By default, it is 0.
  1221. */
  1222. GAPI_EXPORTS_W GMat remap(const GMat& src, const Mat& map1, const Mat& map2,
  1223. int interpolation, int borderMode = BORDER_CONSTANT,
  1224. const Scalar& borderValue = Scalar());
  1225. /** @brief Flips a 2D matrix around vertical, horizontal, or both axes.
  1226. The function flips the matrix in one of three different ways (row
  1227. and column indices are 0-based):
  1228. \f[\texttt{dst} _{ij} =
  1229. \left\{
  1230. \begin{array}{l l}
  1231. \texttt{src} _{\texttt{src.rows}-i-1,j} & if\; \texttt{flipCode} = 0 \\
  1232. \texttt{src} _{i, \texttt{src.cols} -j-1} & if\; \texttt{flipCode} > 0 \\
  1233. \texttt{src} _{ \texttt{src.rows} -i-1, \texttt{src.cols} -j-1} & if\; \texttt{flipCode} < 0 \\
  1234. \end{array}
  1235. \right.\f]
  1236. The example scenarios of using the function are the following:
  1237. * Vertical flipping of the image (flipCode == 0) to switch between
  1238. top-left and bottom-left image origin. This is a typical operation
  1239. in video processing on Microsoft Windows\* OS.
  1240. * Horizontal flipping of the image with the subsequent horizontal
  1241. shift and absolute difference calculation to check for a
  1242. vertical-axis symmetry (flipCode \> 0).
  1243. * Simultaneous horizontal and vertical flipping of the image with
  1244. the subsequent shift and absolute difference calculation to check
  1245. for a central symmetry (flipCode \< 0).
  1246. * Reversing the order of point arrays (flipCode \> 0 or
  1247. flipCode == 0).
  1248. Output image must be of the same depth as input one, size should be correct for given flipCode.
  1249. @note Function textual ID is "org.opencv.core.transform.flip"
  1250. @param src input matrix.
  1251. @param flipCode a flag to specify how to flip the array; 0 means
  1252. flipping around the x-axis and positive value (for example, 1) means
  1253. flipping around y-axis. Negative value (for example, -1) means flipping
  1254. around both axes.
  1255. @sa remap
  1256. */
  1257. GAPI_EXPORTS_W GMat flip(const GMat& src, int flipCode);
  1258. /** @brief Crops a 2D matrix.
  1259. The function crops the matrix by given cv::Rect.
  1260. Output matrix must be of the same depth as input one, size is specified by given rect size.
  1261. @note Function textual ID is "org.opencv.core.transform.crop"
  1262. @param src input matrix.
  1263. @param rect a rect to crop a matrix to
  1264. @sa resize
  1265. */
  1266. GAPI_EXPORTS_W GMat crop(const GMat& src, const Rect& rect);
  1267. /** @brief Applies horizontal concatenation to given matrices.
  1268. The function horizontally concatenates two GMat matrices (with the same number of rows).
  1269. @code{.cpp}
  1270. GMat A = { 1, 4,
  1271. 2, 5,
  1272. 3, 6 };
  1273. GMat B = { 7, 10,
  1274. 8, 11,
  1275. 9, 12 };
  1276. GMat C = gapi::concatHor(A, B);
  1277. //C:
  1278. //[1, 4, 7, 10;
  1279. // 2, 5, 8, 11;
  1280. // 3, 6, 9, 12]
  1281. @endcode
  1282. Output matrix must the same number of rows and depth as the src1 and src2, and the sum of cols of the src1 and src2.
  1283. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  1284. @note Function textual ID is "org.opencv.imgproc.transform.concatHor"
  1285. @param src1 first input matrix to be considered for horizontal concatenation.
  1286. @param src2 second input matrix to be considered for horizontal concatenation.
  1287. @sa concatVert
  1288. */
  1289. GAPI_EXPORTS_W GMat concatHor(const GMat& src1, const GMat& src2);
  1290. /** @overload
  1291. The function horizontally concatenates given number of GMat matrices (with the same number of columns).
  1292. Output matrix must the same number of columns and depth as the input matrices, and the sum of rows of input matrices.
  1293. @param v vector of input matrices to be concatenated horizontally.
  1294. */
  1295. GAPI_EXPORTS_W GMat concatHor(const std::vector<GMat> &v);
  1296. /** @brief Applies vertical concatenation to given matrices.
  1297. The function vertically concatenates two GMat matrices (with the same number of cols).
  1298. @code{.cpp}
  1299. GMat A = { 1, 7,
  1300. 2, 8,
  1301. 3, 9 };
  1302. GMat B = { 4, 10,
  1303. 5, 11,
  1304. 6, 12 };
  1305. GMat C = gapi::concatVert(A, B);
  1306. //C:
  1307. //[1, 7;
  1308. // 2, 8;
  1309. // 3, 9;
  1310. // 4, 10;
  1311. // 5, 11;
  1312. // 6, 12]
  1313. @endcode
  1314. Output matrix must the same number of cols and depth as the src1 and src2, and the sum of rows of the src1 and src2.
  1315. Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
  1316. @note Function textual ID is "org.opencv.imgproc.transform.concatVert"
  1317. @param src1 first input matrix to be considered for vertical concatenation.
  1318. @param src2 second input matrix to be considered for vertical concatenation.
  1319. @sa concatHor
  1320. */
  1321. GAPI_EXPORTS_W GMat concatVert(const GMat& src1, const GMat& src2);
  1322. /** @overload
  1323. The function vertically concatenates given number of GMat matrices (with the same number of columns).
  1324. Output matrix must the same number of columns and depth as the input matrices, and the sum of rows of input matrices.
  1325. @param v vector of input matrices to be concatenated vertically.
  1326. */
  1327. GAPI_EXPORTS_W GMat concatVert(const std::vector<GMat> &v);
  1328. /** @brief Performs a look-up table transform of a matrix.
  1329. The function LUT fills the output matrix with values from the look-up table. Indices of the entries
  1330. are taken from the input matrix. That is, the function processes each element of src as follows:
  1331. \f[\texttt{dst} (I) \leftarrow \texttt{lut(src(I))}\f]
  1332. Supported matrix data types are @ref CV_8UC1.
  1333. Output is a matrix of the same size and number of channels as src, and the same depth as lut.
  1334. @note Function textual ID is "org.opencv.core.transform.LUT"
  1335. @param src input matrix of 8-bit elements.
  1336. @param lut look-up table of 256 elements; in case of multi-channel input array, the table should
  1337. either have a single channel (in this case the same table is used for all channels) or the same
  1338. number of channels as in the input matrix.
  1339. */
  1340. GAPI_EXPORTS_W GMat LUT(const GMat& src, const Mat& lut);
  1341. /** @brief Converts a matrix to another data depth with optional scaling.
  1342. The method converts source pixel values to the target data depth. saturate_cast\<\> is applied at
  1343. the end to avoid possible overflows:
  1344. \f[m(x,y) = saturate \_ cast<rType>( \alpha (*this)(x,y) + \beta )\f]
  1345. Output matrix must be of the same size as input one.
  1346. @note Function textual ID is "org.opencv.core.transform.convertTo"
  1347. @param src input matrix to be converted from.
  1348. @param rdepth desired output matrix depth or, rather, the depth since the number of channels are the
  1349. same as the input has; if rdepth is negative, the output matrix will have the same depth as the input.
  1350. @param alpha optional scale factor.
  1351. @param beta optional delta added to the scaled values.
  1352. */
  1353. GAPI_EXPORTS_W GMat convertTo(const GMat& src, int rdepth, double alpha=1, double beta=0);
  1354. /** @brief Normalizes the norm or value range of an array.
  1355. The function normalizes scale and shift the input array elements so that
  1356. \f[\| \texttt{dst} \| _{L_p}= \texttt{alpha}\f]
  1357. (where p=Inf, 1 or 2) when normType=NORM_INF, NORM_L1, or NORM_L2, respectively; or so that
  1358. \f[\min _I \texttt{dst} (I)= \texttt{alpha} , \, \, \max _I \texttt{dst} (I)= \texttt{beta}\f]
  1359. when normType=NORM_MINMAX (for dense arrays only).
  1360. @note Function textual ID is "org.opencv.core.normalize"
  1361. @param src input array.
  1362. @param alpha norm value to normalize to or the lower range boundary in case of the range
  1363. normalization.
  1364. @param beta upper range boundary in case of the range normalization; it is not used for the norm
  1365. normalization.
  1366. @param norm_type normalization type (see cv::NormTypes).
  1367. @param ddepth when negative, the output array has the same type as src; otherwise, it has the same
  1368. number of channels as src and the depth =ddepth.
  1369. @sa norm, Mat::convertTo
  1370. */
  1371. GAPI_EXPORTS_W GMat normalize(const GMat& src, double alpha, double beta,
  1372. int norm_type, int ddepth = -1);
  1373. /** @brief Applies a perspective transformation to an image.
  1374. The function warpPerspective transforms the source image using the specified matrix:
  1375. \f[\texttt{dst} (x,y) = \texttt{src} \left ( \frac{M_{11} x + M_{12} y + M_{13}}{M_{31} x + M_{32} y + M_{33}} ,
  1376. \frac{M_{21} x + M_{22} y + M_{23}}{M_{31} x + M_{32} y + M_{33}} \right )\f]
  1377. when the flag #WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted with invert
  1378. and then put in the formula above instead of M. The function cannot operate in-place.
  1379. @param src input image.
  1380. @param M \f$3\times 3\f$ transformation matrix.
  1381. @param dsize size of the output image.
  1382. @param flags combination of interpolation methods (#INTER_LINEAR or #INTER_NEAREST) and the
  1383. optional flag #WARP_INVERSE_MAP, that sets M as the inverse transformation (
  1384. \f$\texttt{dst}\rightarrow\texttt{src}\f$ ).
  1385. @param borderMode pixel extrapolation method (#BORDER_CONSTANT or #BORDER_REPLICATE).
  1386. @param borderValue value used in case of a constant border; by default, it equals 0.
  1387. @sa warpAffine, resize, remap, getRectSubPix, perspectiveTransform
  1388. */
  1389. GAPI_EXPORTS_W GMat warpPerspective(const GMat& src, const Mat& M, const Size& dsize, int flags = cv::INTER_LINEAR,
  1390. int borderMode = cv::BORDER_CONSTANT, const Scalar& borderValue = Scalar());
  1391. /** @brief Applies an affine transformation to an image.
  1392. The function warpAffine transforms the source image using the specified matrix:
  1393. \f[\texttt{dst} (x,y) = \texttt{src} ( \texttt{M} _{11} x + \texttt{M} _{12} y + \texttt{M} _{13}, \texttt{M} _{21} x + \texttt{M} _{22} y + \texttt{M} _{23})\f]
  1394. when the flag #WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted
  1395. with #invertAffineTransform and then put in the formula above instead of M. The function cannot
  1396. operate in-place.
  1397. @param src input image.
  1398. @param M \f$2\times 3\f$ transformation matrix.
  1399. @param dsize size of the output image.
  1400. @param flags combination of interpolation methods (see #InterpolationFlags) and the optional
  1401. flag #WARP_INVERSE_MAP that means that M is the inverse transformation (
  1402. \f$\texttt{dst}\rightarrow\texttt{src}\f$ ).
  1403. @param borderMode pixel extrapolation method (see #BorderTypes);
  1404. borderMode=#BORDER_TRANSPARENT isn't supported
  1405. @param borderValue value used in case of a constant border; by default, it is 0.
  1406. @sa warpPerspective, resize, remap, getRectSubPix, transform
  1407. */
  1408. GAPI_EXPORTS_W GMat warpAffine(const GMat& src, const Mat& M, const Size& dsize, int flags = cv::INTER_LINEAR,
  1409. int borderMode = cv::BORDER_CONSTANT, const Scalar& borderValue = Scalar());
  1410. //! @} gapi_transform
  1411. /** @brief Finds centers of clusters and groups input samples around the clusters.
  1412. The function kmeans implements a k-means algorithm that finds the centers of K clusters
  1413. and groups the input samples around the clusters. As an output, \f$\texttt{bestLabels}_i\f$
  1414. contains a 0-based cluster index for the \f$i^{th}\f$ sample.
  1415. @note
  1416. - Function textual ID is "org.opencv.core.kmeansND"
  1417. - In case of an N-dimentional points' set given, input GMat can have the following traits:
  1418. 2 dimensions, a single row or column if there are N channels,
  1419. or N columns if there is a single channel. Mat should have @ref CV_32F depth.
  1420. - Although, if GMat with height != 1, width != 1, channels != 1 given as data, n-dimensional
  1421. samples are considered given in amount of A, where A = height, n = width * channels.
  1422. - In case of GMat given as data:
  1423. - the output labels are returned as 1-channel GMat with sizes
  1424. width = 1, height = A, where A is samples amount, or width = bestLabels.width,
  1425. height = bestLabels.height if bestLabels given;
  1426. - the cluster centers are returned as 1-channel GMat with sizes
  1427. width = n, height = K, where n is samples' dimentionality and K is clusters' amount.
  1428. - As one of possible usages, if you want to control the initial labels for each attempt
  1429. by yourself, you can utilize just the core of the function. To do that, set the number
  1430. of attempts to 1, initialize labels each time using a custom algorithm, pass them with the
  1431. ( flags = #KMEANS_USE_INITIAL_LABELS ) flag, and then choose the best (most-compact) clustering.
  1432. @param data Data for clustering. An array of N-Dimensional points with float coordinates is needed.
  1433. Function can take GArray<Point2f>, GArray<Point3f> for 2D and 3D cases or GMat for any
  1434. dimentionality and channels.
  1435. @param K Number of clusters to split the set by.
  1436. @param bestLabels Optional input integer array that can store the supposed initial cluster indices
  1437. for every sample. Used when ( flags = #KMEANS_USE_INITIAL_LABELS ) flag is set.
  1438. @param criteria The algorithm termination criteria, that is, the maximum number of iterations
  1439. and/or the desired accuracy. The accuracy is specified as criteria.epsilon. As soon as each of
  1440. the cluster centers moves by less than criteria.epsilon on some iteration, the algorithm stops.
  1441. @param attempts Flag to specify the number of times the algorithm is executed using different
  1442. initial labellings. The algorithm returns the labels that yield the best compactness (see the first
  1443. function return value).
  1444. @param flags Flag that can take values of cv::KmeansFlags .
  1445. @return
  1446. - Compactness measure that is computed as
  1447. \f[\sum _i \| \texttt{samples} _i - \texttt{centers} _{ \texttt{labels} _i} \| ^2\f]
  1448. after every attempt. The best (minimum) value is chosen and the corresponding labels and the
  1449. compactness value are returned by the function.
  1450. - Integer array that stores the cluster indices for every sample.
  1451. - Array of the cluster centers.
  1452. */
  1453. GAPI_EXPORTS_W std::tuple<GOpaque<double>,GMat,GMat>
  1454. kmeans(const GMat& data, const int K, const GMat& bestLabels,
  1455. const TermCriteria& criteria, const int attempts, const KmeansFlags flags);
  1456. /** @overload
  1457. @note
  1458. - Function textual ID is "org.opencv.core.kmeansNDNoInit"
  1459. - #KMEANS_USE_INITIAL_LABELS flag must not be set while using this overload.
  1460. */
  1461. GAPI_EXPORTS_W std::tuple<GOpaque<double>,GMat,GMat>
  1462. kmeans(const GMat& data, const int K, const TermCriteria& criteria, const int attempts,
  1463. const KmeansFlags flags);
  1464. /** @overload
  1465. @note Function textual ID is "org.opencv.core.kmeans2D"
  1466. */
  1467. GAPI_EXPORTS_W std::tuple<GOpaque<double>,GArray<int>,GArray<Point2f>>
  1468. kmeans(const GArray<Point2f>& data, const int K, const GArray<int>& bestLabels,
  1469. const TermCriteria& criteria, const int attempts, const KmeansFlags flags);
  1470. /** @overload
  1471. @note Function textual ID is "org.opencv.core.kmeans3D"
  1472. */
  1473. GAPI_EXPORTS_W std::tuple<GOpaque<double>,GArray<int>,GArray<Point3f>>
  1474. kmeans(const GArray<Point3f>& data, const int K, const GArray<int>& bestLabels,
  1475. const TermCriteria& criteria, const int attempts, const KmeansFlags flags);
  1476. /** @brief Transposes a matrix.
  1477. The function transposes the matrix:
  1478. \f[\texttt{dst} (i,j) = \texttt{src} (j,i)\f]
  1479. @note
  1480. - Function textual ID is "org.opencv.core.transpose"
  1481. - No complex conjugation is done in case of a complex matrix. It should be done separately if needed.
  1482. @param src input array.
  1483. */
  1484. GAPI_EXPORTS_W GMat transpose(const GMat& src);
  1485. namespace streaming {
  1486. /** @brief Gets dimensions from Mat.
  1487. @note Function textual ID is "org.opencv.streaming.size"
  1488. @param src Input tensor
  1489. @return Size (tensor dimensions).
  1490. */
  1491. GAPI_EXPORTS_W GOpaque<Size> size(const GMat& src);
  1492. /** @overload
  1493. Gets dimensions from rectangle.
  1494. @note Function textual ID is "org.opencv.streaming.sizeR"
  1495. @param r Input rectangle.
  1496. @return Size (rectangle dimensions).
  1497. */
  1498. GAPI_EXPORTS_W GOpaque<Size> size(const GOpaque<Rect>& r);
  1499. /** @brief Gets dimensions from MediaFrame.
  1500. @note Function textual ID is "org.opencv.streaming.sizeMF"
  1501. @param src Input frame
  1502. @return Size (frame dimensions).
  1503. */
  1504. GAPI_EXPORTS_W GOpaque<Size> size(const GFrame& src);
  1505. } //namespace streaming
  1506. } //namespace gapi
  1507. } //namespace cv
  1508. #endif //OPENCV_GAPI_CORE_HPP