imgproc.hpp 78 KB

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