core.hpp 66 KB

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