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.
5 // Copyright (C) 2018-2019 Intel Corporation
8 #ifndef OPENCV_GAPI_CORE_HPP
9 #define OPENCV_GAPI_CORE_HPP
11 #include <utility> // std::tuple
13 #include <opencv2/imgproc.hpp>
15 #include "opencv2/gapi/gmat.hpp"
16 #include "opencv2/gapi/gscalar.hpp"
17 #include "opencv2/gapi/gkernel.hpp"
19 /** \defgroup gapi_core G-API core (basic) functionality
21 @defgroup gapi_math Graph API: Math operations
22 @defgroup gapi_pixelwise Graph API: Pixelwise operations
23 @defgroup gapi_matrixop Graph API: Operations on matrices
24 @defgroup gapi_transform Graph API: Geometric, depth and LUT-like image transformations
27 namespace cv { namespace gapi {
29 using GMat2 = std::tuple<GMat,GMat>;
30 using GMat3 = std::tuple<GMat,GMat,GMat>; // FIXME: how to avoid this?
31 using GMat4 = std::tuple<GMat,GMat,GMat,GMat>;
32 using GMatScalar = std::tuple<GMat, GScalar>;
34 G_TYPED_KERNEL(GAdd, <GMat(GMat, GMat, int)>, "org.opencv.core.math.add") {
35 static GMatDesc outMeta(GMatDesc a, GMatDesc b, int ddepth) {
38 // OpenCV: When the input arrays in add/subtract/multiply/divide
39 // functions have different depths, the output array depth must be
40 // explicitly specified!
41 // See artim_op() @ arithm.cpp
42 GAPI_Assert(a.chan == b.chan);
43 GAPI_Assert(a.depth == b.depth);
46 return a.withDepth(ddepth);
50 G_TYPED_KERNEL(GAddC, <GMat(GMat, GScalar, int)>, "org.opencv.core.math.addC") {
51 static GMatDesc outMeta(GMatDesc a, GScalarDesc, int ddepth) {
52 return a.withDepth(ddepth);
56 G_TYPED_KERNEL(GSub, <GMat(GMat, GMat, int)>, "org.opencv.core.math.sub") {
57 static GMatDesc outMeta(GMatDesc a, GMatDesc b, int ddepth) {
60 // This macro should select a larger data depth from a and b
61 // considering the number of channels in the same
62 // FIXME!!! Clarify if it is valid for sub()
63 GAPI_Assert(a.chan == b.chan);
64 ddepth = std::max(a.depth, b.depth);
66 return a.withDepth(ddepth);
70 G_TYPED_KERNEL(GSubC, <GMat(GMat, GScalar, int)>, "org.opencv.core.math.subC") {
71 static GMatDesc outMeta(GMatDesc a, GScalarDesc, int ddepth) {
72 return a.withDepth(ddepth);
76 G_TYPED_KERNEL(GSubRC,<GMat(GScalar, GMat, int)>, "org.opencv.core.math.subRC") {
77 static GMatDesc outMeta(GScalarDesc, GMatDesc b, int ddepth) {
78 return b.withDepth(ddepth);
82 G_TYPED_KERNEL(GMul, <GMat(GMat, GMat, double, int)>, "org.opencv.core.math.mul") {
83 static GMatDesc outMeta(GMatDesc a, GMatDesc, double, int ddepth) {
84 return a.withDepth(ddepth);
88 G_TYPED_KERNEL(GMulCOld, <GMat(GMat, double, int)>, "org.opencv.core.math.mulCOld") {
89 static GMatDesc outMeta(GMatDesc a, double, int ddepth) {
90 return a.withDepth(ddepth);
94 G_TYPED_KERNEL(GMulC, <GMat(GMat, GScalar, int)>, "org.opencv.core.math.mulC"){
95 static GMatDesc outMeta(GMatDesc a, GScalarDesc, int ddepth) {
96 return a.withDepth(ddepth);
100 G_TYPED_KERNEL(GMulS, <GMat(GMat, GScalar)>, "org.opencv.core.math.muls") {
101 static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
104 }; // FIXME: Merge with MulC
106 G_TYPED_KERNEL(GDiv, <GMat(GMat, GMat, double, int)>, "org.opencv.core.math.div") {
107 static GMatDesc outMeta(GMatDesc a, GMatDesc b, double, int ddepth) {
110 GAPI_Assert(a.depth == b.depth);
113 return a.withDepth(ddepth);
117 G_TYPED_KERNEL(GDivC, <GMat(GMat, GScalar, double, int)>, "org.opencv.core.math.divC") {
118 static GMatDesc outMeta(GMatDesc a, GScalarDesc, double, int ddepth) {
119 return a.withDepth(ddepth);
123 G_TYPED_KERNEL(GDivRC, <GMat(GScalar, GMat, double, int)>, "org.opencv.core.math.divRC") {
124 static GMatDesc outMeta(GScalarDesc, GMatDesc b, double, int ddepth) {
125 return b.withDepth(ddepth);
129 G_TYPED_KERNEL(GMean, <GScalar(GMat)>, "org.opencv.core.math.mean") {
130 static GScalarDesc outMeta(GMatDesc) {
131 return empty_scalar_desc();
135 G_TYPED_KERNEL_M(GPolarToCart, <GMat2(GMat, GMat, bool)>, "org.opencv.core.math.polarToCart") {
136 static std::tuple<GMatDesc, GMatDesc> outMeta(GMatDesc, GMatDesc a, bool) {
137 return std::make_tuple(a, a);
141 G_TYPED_KERNEL_M(GCartToPolar, <GMat2(GMat, GMat, bool)>, "org.opencv.core.math.cartToPolar") {
142 static std::tuple<GMatDesc, GMatDesc> outMeta(GMatDesc x, GMatDesc, bool) {
143 return std::make_tuple(x, x);
147 G_TYPED_KERNEL(GPhase, <GMat(GMat, GMat, bool)>, "org.opencv.core.math.phase") {
148 static GMatDesc outMeta(const GMatDesc &inx, const GMatDesc &, bool) {
153 G_TYPED_KERNEL(GMask, <GMat(GMat,GMat)>, "org.opencv.core.pixelwise.mask") {
154 static GMatDesc outMeta(GMatDesc in, GMatDesc) {
159 G_TYPED_KERNEL(GCmpGT, <GMat(GMat, GMat)>, "org.opencv.core.pixelwise.compare.cmpGT") {
160 static GMatDesc outMeta(GMatDesc a, GMatDesc) {
161 return a.withDepth(CV_8U);
165 G_TYPED_KERNEL(GCmpGE, <GMat(GMat, GMat)>, "org.opencv.core.pixelwise.compare.cmpGE") {
166 static GMatDesc outMeta(GMatDesc a, GMatDesc) {
167 return a.withDepth(CV_8U);
171 G_TYPED_KERNEL(GCmpLE, <GMat(GMat, GMat)>, "org.opencv.core.pixelwise.compare.cmpLE") {
172 static GMatDesc outMeta(GMatDesc a, GMatDesc) {
173 return a.withDepth(CV_8U);
177 G_TYPED_KERNEL(GCmpLT, <GMat(GMat, GMat)>, "org.opencv.core.pixelwise.compare.cmpLT") {
178 static GMatDesc outMeta(GMatDesc a, GMatDesc) {
179 return a.withDepth(CV_8U);
183 G_TYPED_KERNEL(GCmpEQ, <GMat(GMat, GMat)>, "org.opencv.core.pixelwise.compare.cmpEQ") {
184 static GMatDesc outMeta(GMatDesc a, GMatDesc) {
185 return a.withDepth(CV_8U);
189 G_TYPED_KERNEL(GCmpNE, <GMat(GMat, GMat)>, "org.opencv.core.pixelwise.compare.cmpNE") {
190 static GMatDesc outMeta(GMatDesc a, GMatDesc) {
191 return a.withDepth(CV_8U);
195 G_TYPED_KERNEL(GCmpGTScalar, <GMat(GMat, GScalar)>, "org.opencv.core.pixelwise.compare.cmpGTScalar"){
196 static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
197 return a.withDepth(CV_8U);
201 G_TYPED_KERNEL(GCmpGEScalar, <GMat(GMat, GScalar)>, "org.opencv.core.pixelwise.compare.cmpGEScalar"){
202 static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
203 return a.withDepth(CV_8U);
207 G_TYPED_KERNEL(GCmpLEScalar, <GMat(GMat, GScalar)>, "org.opencv.core.pixelwise.compare.cmpLEScalar"){
208 static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
209 return a.withDepth(CV_8U);
213 G_TYPED_KERNEL(GCmpLTScalar, <GMat(GMat, GScalar)>, "org.opencv.core.pixelwise.compare.cmpLTScalar"){
214 static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
215 return a.withDepth(CV_8U);
219 G_TYPED_KERNEL(GCmpEQScalar, <GMat(GMat, GScalar)>, "org.opencv.core.pixelwise.compare.cmpEQScalar"){
220 static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
221 return a.withDepth(CV_8U);
225 G_TYPED_KERNEL(GCmpNEScalar, <GMat(GMat, GScalar)>, "org.opencv.core.pixelwise.compare.cmpNEScalar"){
226 static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
227 return a.withDepth(CV_8U);
231 G_TYPED_KERNEL(GAnd, <GMat(GMat, GMat)>, "org.opencv.core.pixelwise.bitwise_and") {
232 static GMatDesc outMeta(GMatDesc a, GMatDesc) {
237 G_TYPED_KERNEL(GAndS, <GMat(GMat, GScalar)>, "org.opencv.core.pixelwise.bitwise_andS") {
238 static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
243 G_TYPED_KERNEL(GOr, <GMat(GMat, GMat)>, "org.opencv.core.pixelwise.bitwise_or") {
244 static GMatDesc outMeta(GMatDesc a, GMatDesc) {
249 G_TYPED_KERNEL(GOrS, <GMat(GMat, GScalar)>, "org.opencv.core.pixelwise.bitwise_orS") {
250 static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
255 G_TYPED_KERNEL(GXor, <GMat(GMat, GMat)>, "org.opencv.core.pixelwise.bitwise_xor") {
256 static GMatDesc outMeta(GMatDesc a, GMatDesc) {
261 G_TYPED_KERNEL(GXorS, <GMat(GMat, GScalar)>, "org.opencv.core.pixelwise.bitwise_xorS") {
262 static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
267 G_TYPED_KERNEL(GNot, <GMat(GMat)>, "org.opencv.core.pixelwise.bitwise_not") {
268 static GMatDesc outMeta(GMatDesc a) {
273 G_TYPED_KERNEL(GSelect, <GMat(GMat, GMat, GMat)>, "org.opencv.core.pixelwise.select") {
274 static GMatDesc outMeta(GMatDesc a, GMatDesc, GMatDesc) {
279 G_TYPED_KERNEL(GMin, <GMat(GMat, GMat)>, "org.opencv.core.matrixop.min") {
280 static GMatDesc outMeta(GMatDesc a, GMatDesc) {
285 G_TYPED_KERNEL(GMax, <GMat(GMat, GMat)>, "org.opencv.core.matrixop.max") {
286 static GMatDesc outMeta(GMatDesc a, GMatDesc) {
291 G_TYPED_KERNEL(GAbsDiff, <GMat(GMat, GMat)>, "org.opencv.core.matrixop.absdiff") {
292 static GMatDesc outMeta(GMatDesc a, GMatDesc) {
297 G_TYPED_KERNEL(GAbsDiffC, <GMat(GMat, GScalar)>, "org.opencv.core.matrixop.absdiffC") {
298 static GMatDesc outMeta(GMatDesc a, GScalarDesc) {
303 G_TYPED_KERNEL(GSum, <GScalar(GMat)>, "org.opencv.core.matrixop.sum") {
304 static GScalarDesc outMeta(GMatDesc) {
305 return empty_scalar_desc();
309 G_TYPED_KERNEL(GAddW, <GMat(GMat, double, GMat, double, double, int)>, "org.opencv.core.matrixop.addweighted") {
310 static GMatDesc outMeta(GMatDesc a, double, GMatDesc b, double, double, int ddepth) {
313 // OpenCV: When the input arrays in add/subtract/multiply/divide
314 // functions have different depths, the output array depth must be
315 // explicitly specified!
316 // See artim_op() @ arithm.cpp
317 GAPI_Assert(a.chan == b.chan);
318 GAPI_Assert(a.depth == b.depth);
321 return a.withDepth(ddepth);
325 G_TYPED_KERNEL(GNormL1, <GScalar(GMat)>, "org.opencv.core.matrixop.norml1") {
326 static GScalarDesc outMeta(GMatDesc) {
327 return empty_scalar_desc();
331 G_TYPED_KERNEL(GNormL2, <GScalar(GMat)>, "org.opencv.core.matrixop.norml2") {
332 static GScalarDesc outMeta(GMatDesc) {
333 return empty_scalar_desc();
337 G_TYPED_KERNEL(GNormInf, <GScalar(GMat)>, "org.opencv.core.matrixop.norminf") {
338 static GScalarDesc outMeta(GMatDesc) {
339 return empty_scalar_desc();
343 G_TYPED_KERNEL_M(GIntegral, <GMat2(GMat, int, int)>, "org.opencv.core.matrixop.integral") {
344 static std::tuple<GMatDesc, GMatDesc> outMeta(GMatDesc in, int sd, int sqd) {
345 return std::make_tuple(in.withSizeDelta(1,1).withDepth(sd),
346 in.withSizeDelta(1,1).withDepth(sqd));
350 G_TYPED_KERNEL(GThreshold, <GMat(GMat, GScalar, GScalar, int)>, "org.opencv.core.matrixop.threshold") {
351 static GMatDesc outMeta(GMatDesc in, GScalarDesc, GScalarDesc, int) {
357 G_TYPED_KERNEL_M(GThresholdOT, <GMatScalar(GMat, GScalar, int)>, "org.opencv.core.matrixop.thresholdOT") {
358 static std::tuple<GMatDesc,GScalarDesc> outMeta(GMatDesc in, GScalarDesc, int) {
359 return std::make_tuple(in, empty_scalar_desc());
363 G_TYPED_KERNEL(GInRange, <GMat(GMat, GScalar, GScalar)>, "org.opencv.core.matrixop.inrange") {
364 static GMatDesc outMeta(GMatDesc in, GScalarDesc, GScalarDesc) {
365 return in.withType(CV_8U, 1);
369 G_TYPED_KERNEL_M(GSplit3, <GMat3(GMat)>, "org.opencv.core.transform.split3") {
370 static std::tuple<GMatDesc, GMatDesc, GMatDesc> outMeta(GMatDesc in) {
371 const auto out_depth = in.depth;
372 const auto out_desc = in.withType(out_depth, 1);
373 return std::make_tuple(out_desc, out_desc, out_desc);
377 G_TYPED_KERNEL_M(GSplit4, <GMat4(GMat)>,"org.opencv.core.transform.split4") {
378 static std::tuple<GMatDesc, GMatDesc, GMatDesc, GMatDesc> outMeta(GMatDesc in) {
379 const auto out_depth = in.depth;
380 const auto out_desc = in.withType(out_depth, 1);
381 return std::make_tuple(out_desc, out_desc, out_desc, out_desc);
385 G_TYPED_KERNEL(GResize, <GMat(GMat,Size,double,double,int)>, "org.opencv.core.transform.resize") {
386 static GMatDesc outMeta(GMatDesc in, Size sz, double fx, double fy, int) {
387 if (sz.width != 0 && sz.height != 0)
389 return in.withSize(sz);
393 GAPI_Assert(fx != 0. && fy != 0.);
395 (Size(static_cast<int>(std::round(in.size.width * fx)),
396 static_cast<int>(std::round(in.size.height * fy))));
401 G_TYPED_KERNEL(GMerge3, <GMat(GMat,GMat,GMat)>, "org.opencv.core.transform.merge3") {
402 static GMatDesc outMeta(GMatDesc in, GMatDesc, GMatDesc) {
403 // Preserve depth and add channel component
404 return in.withType(in.depth, 3);
408 G_TYPED_KERNEL(GMerge4, <GMat(GMat,GMat,GMat,GMat)>, "org.opencv.core.transform.merge4") {
409 static GMatDesc outMeta(GMatDesc in, GMatDesc, GMatDesc, GMatDesc) {
410 // Preserve depth and add channel component
411 return in.withType(in.depth, 4);
415 G_TYPED_KERNEL(GRemap, <GMat(GMat, Mat, Mat, int, int, Scalar)>, "org.opencv.core.transform.remap") {
416 static GMatDesc outMeta(GMatDesc in, Mat m1, Mat, int, int, Scalar) {
417 return in.withSize(m1.size());
421 G_TYPED_KERNEL(GFlip, <GMat(GMat, int)>, "org.opencv.core.transform.flip") {
422 static GMatDesc outMeta(GMatDesc in, int) {
427 G_TYPED_KERNEL(GCrop, <GMat(GMat, Rect)>, "org.opencv.core.transform.crop") {
428 static GMatDesc outMeta(GMatDesc in, Rect rc) {
429 return in.withSize(Size(rc.width, rc.height));
433 G_TYPED_KERNEL(GConcatHor, <GMat(GMat, GMat)>, "org.opencv.imgproc.transform.concatHor") {
434 static GMatDesc outMeta(GMatDesc l, GMatDesc r) {
435 return l.withSizeDelta(+r.size.width, 0);
439 G_TYPED_KERNEL(GConcatVert, <GMat(GMat, GMat)>, "org.opencv.imgproc.transform.concatVert") {
440 static GMatDesc outMeta(GMatDesc t, GMatDesc b) {
441 return t.withSizeDelta(0, +b.size.height);
445 G_TYPED_KERNEL(GLUT, <GMat(GMat, Mat)>, "org.opencv.core.transform.LUT") {
446 static GMatDesc outMeta(GMatDesc in, Mat) {
451 G_TYPED_KERNEL(GConvertTo, <GMat(GMat, int, double, double)>, "org.opencv.core.transform.convertTo") {
452 static GMatDesc outMeta(GMatDesc in, int rdepth, double, double) {
453 return rdepth < 0 ? in : in.withDepth(rdepth);
457 G_TYPED_KERNEL(GSqrt, <GMat(GMat)>, "org.opencv.core.math.sqrt") {
458 static GMatDesc outMeta(GMatDesc in) {
464 //! @addtogroup gapi_math
467 /** @brief Calculates the per-element sum of two matrices.
469 The function add calculates sum of two matrices of the same size and the same number of channels:
470 \f[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) + \texttt{src2}(I)) \quad \texttt{if mask}(I) \ne0\f]
472 The function can be replaced with matrix expressions:
473 \f[\texttt{dst} = \texttt{src1} + \texttt{src2}\f]
475 The input matrices and the output matrix can all have the same or different depths. For example, you
476 can add a 16-bit unsigned matrix to a 8-bit signed matrix and store the sum as a 32-bit
477 floating-point matrix. Depth of the output matrix is determined by the ddepth parameter.
478 If src1.depth() == src2.depth(), ddepth can be set to the default -1. In this case, the output matrix will have
479 the same depth as the input matrices.
481 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
483 @note Function textual ID is "org.opencv.core.math.add"
484 @param src1 first input matrix.
485 @param src2 second input matrix.
486 @param ddepth optional depth of the output matrix.
489 GAPI_EXPORTS GMat add(const GMat& src1, const GMat& src2, int ddepth = -1);
491 /** @brief Calculates the per-element sum of matrix and given scalar.
493 The function addC adds a given scalar value to each element of given matrix.
494 The function can be replaced with matrix expressions:
496 \f[\texttt{dst} = \texttt{src1} + \texttt{c}\f]
498 Depth of the output matrix is determined by the ddepth parameter.
499 If ddepth is set to default -1, the depth of output matrix will be the same as the depth of input matrix.
500 The matrices can be single or multi channel. Output matrix must have the same size and number of channels as the input matrix.
502 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
504 @note Function textual ID is "org.opencv.core.math.addC"
505 @param src1 first input matrix.
506 @param c scalar value to be added.
507 @param ddepth optional depth of the output matrix.
510 GAPI_EXPORTS GMat addC(const GMat& src1, const GScalar& c, int ddepth = -1);
512 GAPI_EXPORTS GMat addC(const GScalar& c, const GMat& src1, int ddepth = -1);
514 /** @brief Calculates the per-element difference between two matrices.
516 The function sub calculates difference between two matrices, when both matrices have the same size and the same number of
518 \f[\texttt{dst}(I) = \texttt{src1}(I) - \texttt{src2}(I)\f]
520 The function can be replaced with matrix expressions:
521 \f[\texttt{dst} = \texttt{src1} - \texttt{src2}\f]
523 The input matrices and the output matrix can all have the same or different depths. For example, you
524 can subtract two 8-bit unsigned matrices store the result as a 16-bit signed matrix.
525 Depth of the output matrix is determined by the ddepth parameter.
526 If src1.depth() == src2.depth(), ddepth can be set to the default -1. In this case, the output matrix will have
527 the same depth as the input matrices. The matrices can be single or multi channel.
529 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
531 @note Function textual ID is "org.opencv.core.math.sub"
532 @param src1 first input matrix.
533 @param src2 second input matrix.
534 @param ddepth optional depth of the output matrix.
537 GAPI_EXPORTS GMat sub(const GMat& src1, const GMat& src2, int ddepth = -1);
539 /** @brief Calculates the per-element difference between matrix and given scalar.
541 The function can be replaced with matrix expressions:
542 \f[\texttt{dst} = \texttt{src} - \texttt{c}\f]
544 Depth of the output matrix is determined by the ddepth parameter.
545 If ddepth is set to default -1, the depth of output matrix will be the same as the depth of input matrix.
546 The matrices can be single or multi channel. Output matrix must have the same size as src.
548 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
550 @note Function textual ID is "org.opencv.core.math.subC"
551 @param src first input matrix.
552 @param c scalar value to subtracted.
553 @param ddepth optional depth of the output matrix.
556 GAPI_EXPORTS GMat subC(const GMat& src, const GScalar& c, int ddepth = -1);
558 /** @brief Calculates the per-element difference between given scalar and the matrix.
560 The function can be replaced with matrix expressions:
561 \f[\texttt{dst} = \texttt{val} - \texttt{src}\f]
563 Depth of the output matrix is determined by the ddepth parameter.
564 If ddepth is set to default -1, the depth of output matrix will be the same as the depth of input matrix.
565 The matrices can be single or multi channel. Output matrix must have the same size as src.
567 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
569 @note Function textual ID is "org.opencv.core.math.subRC"
570 @param c scalar value to subtract from.
571 @param src input matrix to be subtracted.
572 @param ddepth optional depth of the output matrix.
575 GAPI_EXPORTS GMat subRC(const GScalar& c, const GMat& src, int ddepth = -1);
577 /** @brief Calculates the per-element scaled product of two matrices.
579 The function mul calculates the per-element product of two matrices:
581 \f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{scale} \cdot \texttt{src1} (I) \cdot \texttt{src2} (I))\f]
583 If src1.depth() == src2.depth(), ddepth can be set to the default -1. In this case, the output matrix will have
584 the same depth as the input matrices. The matrices can be single or multi channel.
585 Output matrix must have the same size as input matrices.
587 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
589 @note Function textual ID is "org.opencv.core.math.mul"
590 @param src1 first input matrix.
591 @param src2 second input matrix of the same size and the same depth as src1.
592 @param scale optional scale factor.
593 @param ddepth optional depth of the output matrix.
594 @sa add, sub, div, addWeighted
596 GAPI_EXPORTS GMat mul(const GMat& src1, const GMat& src2, double scale = 1.0, int ddepth = -1);
598 /** @brief Multiplies matrix by scalar.
600 The function mulC multiplies each element of matrix src by given scalar value:
602 \f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I) \cdot \texttt{multiplier} )\f]
604 The matrices can be single or multi channel. Output matrix must have the same size as src.
606 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
608 @note Function textual ID is "org.opencv.core.math.mulC"
609 @param src input matrix.
610 @param multiplier factor to be multiplied.
611 @param ddepth optional depth of the output matrix. If -1, the depth of output matrix will be the same as input matrix depth.
612 @sa add, sub, div, addWeighted
614 GAPI_EXPORTS GMat mulC(const GMat& src, double multiplier, int ddepth = -1);
616 GAPI_EXPORTS GMat mulC(const GMat& src, const GScalar& multiplier, int ddepth = -1); // FIXME: merge with mulc
618 GAPI_EXPORTS GMat mulC(const GScalar& multiplier, const GMat& src, int ddepth = -1); // FIXME: merge with mulc
620 /** @brief Performs per-element division of two matrices.
622 The function divides one matrix by another:
623 \f[\texttt{dst(I) = saturate(src1(I)*scale/src2(I))}\f]
625 When src2(I) is zero, dst(I) will also be zero. Different channels of
626 multi-channel matrices are processed independently.
627 The matrices can be single or multi channel. Output matrix must have the same size and depth as src.
629 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
631 @note Function textual ID is "org.opencv.core.math.div"
632 @param src1 first input matrix.
633 @param src2 second input matrix of the same size and depth as src1.
634 @param scale scalar factor.
635 @param ddepth optional depth of the output matrix; you can only pass -1 when src1.depth() == src2.depth().
638 GAPI_EXPORTS GMat div(const GMat& src1, const GMat& src2, double scale, int ddepth = -1);
640 /** @brief Divides matrix by scalar.
642 The function divC divides each element of matrix src by given scalar value:
644 \f[\texttt{dst(I) = saturate(src(I)*scale/divisor)}\f]
646 When divisor is zero, dst(I) will also be zero. Different channels of
647 multi-channel matrices are processed independently.
648 The matrices can be single or multi channel. Output matrix must have the same size and depth as src.
650 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
652 @note Function textual ID is "org.opencv.core.math.divC"
653 @param src input matrix.
654 @param divisor number to be divided by.
655 @param ddepth optional depth of the output matrix. If -1, the depth of output matrix will be the same as input matrix depth.
656 @param scale scale factor.
657 @sa add, sub, div, addWeighted
659 GAPI_EXPORTS GMat divC(const GMat& src, const GScalar& divisor, double scale, int ddepth = -1);
661 /** @brief Divides scalar by matrix.
663 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:
665 \f[\texttt{dst(I) = saturate(divident*scale/src(I))}\f]
667 When src(I) is zero, dst(I) will also be zero. Different channels of
668 multi-channel matrices are processed independently.
669 The matrices can be single or multi channel. Output matrix must have the same size and depth as src.
671 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
673 @note Function textual ID is "org.opencv.core.math.divRC"
674 @param src input matrix.
675 @param divident number to be divided.
676 @param ddepth optional depth of the output matrix. If -1, the depth of output matrix will be the same as input matrix depth.
677 @param scale scale factor
678 @sa add, sub, div, addWeighted
680 GAPI_EXPORTS GMat divRC(const GScalar& divident, const GMat& src, double scale, int ddepth = -1);
682 /** @brief Applies a mask to a matrix.
684 The function mask set value from given matrix if the corresponding pixel value in mask matrix set to true,
685 and set the matrix value to 0 overwise.
687 Supported src matrix data types are @ref CV_8UC1, @ref CV_16SC1, @ref CV_16UC1. Supported mask data type is @ref CV_8UC1.
689 @note Function textual ID is "org.opencv.core.math.mask"
690 @param src input matrix.
691 @param mask input mask matrix.
693 GAPI_EXPORTS GMat mask(const GMat& src, const GMat& mask);
695 /** @brief Calculates an average (mean) of matrix elements.
697 The function mean calculates the mean value M of matrix elements,
698 independently for each channel, and return it.
700 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
702 @note Function textual ID is "org.opencv.core.math.mean"
703 @param src input matrix.
705 GAPI_EXPORTS GScalar mean(const GMat& src);
707 /** @brief Calculates x and y coordinates of 2D vectors from their magnitude and angle.
709 The function polarToCart calculates the Cartesian coordinates of each 2D
710 vector represented by the corresponding elements of magnitude and angle:
711 \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]
713 The relative accuracy of the estimated coordinates is about 1e-6.
715 First output is a matrix of x-coordinates of 2D vectors.
716 Second output is a matrix of y-coordinates of 2D vectors.
717 Both output must have the same size and depth as input matrices.
719 @note Function textual ID is "org.opencv.core.math.polarToCart"
721 @param magnitude input floating-point @ref CV_32FC1 matrix (1xN) of magnitudes of 2D vectors;
722 @param angle input floating-point @ref CV_32FC1 matrix (1xN) of angles of 2D vectors.
723 @param angleInDegrees when true, the input angles are measured in
724 degrees, otherwise, they are measured in radians.
725 @sa cartToPolar, exp, log, pow, sqrt
727 GAPI_EXPORTS std::tuple<GMat, GMat> polarToCart(const GMat& magnitude, const GMat& angle,
728 bool angleInDegrees = false);
730 /** @brief Calculates the magnitude and angle of 2D vectors.
732 The function cartToPolar calculates either the magnitude, angle, or both
733 for every 2D vector (x(I),y(I)):
734 \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]
736 The angles are calculated with accuracy about 0.3 degrees. For the point
737 (0,0), the angle is set to 0.
739 First output is a matrix of magnitudes of the same size and depth as input x.
740 Second output is a matrix of angles that has the same size and depth as
741 x; the angles are measured in radians (from 0 to 2\*Pi) or in degrees (0 to 360 degrees).
743 @note Function textual ID is "org.opencv.core.math.cartToPolar"
745 @param x matrix of @ref CV_32FC1 x-coordinates.
746 @param y array of @ref CV_32FC1 y-coordinates.
747 @param angleInDegrees a flag, indicating whether the angles are measured
748 in radians (which is by default), or in degrees.
751 GAPI_EXPORTS std::tuple<GMat, GMat> cartToPolar(const GMat& x, const GMat& y,
752 bool angleInDegrees = false);
754 /** @brief Calculates the rotation angle of 2D vectors.
756 The function cv::phase calculates the rotation angle of each 2D vector that
757 is formed from the corresponding elements of x and y :
758 \f[\texttt{angle} (I) = \texttt{atan2} ( \texttt{y} (I), \texttt{x} (I))\f]
760 The angle estimation accuracy is about 0.3 degrees. When x(I)=y(I)=0 ,
761 the corresponding angle(I) is set to 0.
762 @param x input floating-point array of x-coordinates of 2D vectors.
763 @param y input array of y-coordinates of 2D vectors; it must have the
764 same size and the same type as x.
765 @param angleInDegrees when true, the function calculates the angle in
766 degrees, otherwise, they are measured in radians.
767 @return array of vector angles; it has the same size and same type as x.
769 GAPI_EXPORTS GMat phase(const GMat& x, const GMat &y, bool angleInDegrees = false);
771 /** @brief Calculates a square root of array elements.
773 The function cv::gapi::sqrt calculates a square root of each input array element.
774 In case of multi-channel arrays, each channel is processed
775 independently. The accuracy is approximately the same as of the built-in
777 @param src input floating-point array.
778 @return output array of the same size and type as src.
780 GAPI_EXPORTS GMat sqrt(const GMat &src);
784 //! @addtogroup gapi_pixelwise
787 /** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are greater compare to elements in second.
789 The function compares elements of two matrices src1 and src2 of the same size:
790 \f[\texttt{dst} (I) = \texttt{src1} (I) > \texttt{src2} (I)\f]
792 When the comparison result is true, the corresponding element of output
793 array is set to 255. The comparison operations can be replaced with the
794 equivalent matrix expressions:
795 \f[\texttt{dst} = \texttt{src1} > \texttt{src2}\f]
797 Output matrix of depth @ref CV_8U must have the same size and the same number of channels as
798 the input matrices/matrix.
800 Supported input matrix data types are @ref CV_8UC1, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
802 @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpGT"
803 @param src1 first input matrix.
804 @param src2 second input matrix/scalar of the same depth as first input matrix.
805 @sa min, max, threshold, cmpLE, cmpGE, cmpLS
807 GAPI_EXPORTS GMat cmpGT(const GMat& src1, const GMat& src2);
809 @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpGTScalar"
811 GAPI_EXPORTS GMat cmpGT(const GMat& src1, const GScalar& src2);
813 /** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are less than elements in second.
815 The function compares elements of two matrices src1 and src2 of the same size:
816 \f[\texttt{dst} (I) = \texttt{src1} (I) < \texttt{src2} (I)\f]
818 When the comparison result is true, the corresponding element of output
819 array is set to 255. The comparison operations can be replaced with the
820 equivalent matrix expressions:
821 \f[\texttt{dst} = \texttt{src1} < \texttt{src2}\f]
823 Output matrix of depth @ref CV_8U must have the same size and the same number of channels as
824 the input matrices/matrix.
826 Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
828 @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLT"
829 @param src1 first input matrix.
830 @param src2 second input matrix/scalar of the same depth as first input matrix.
831 @sa min, max, threshold, cmpLE, cmpGE, cmpGT
833 GAPI_EXPORTS GMat cmpLT(const GMat& src1, const GMat& src2);
835 @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLTScalar"
837 GAPI_EXPORTS GMat cmpLT(const GMat& src1, const GScalar& src2);
839 /** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are greater or equal compare to elements in second.
841 The function compares elements of two matrices src1 and src2 of the same size:
842 \f[\texttt{dst} (I) = \texttt{src1} (I) >= \texttt{src2} (I)\f]
844 When the comparison result is true, the corresponding element of output
845 array is set to 255. The comparison operations can be replaced with the
846 equivalent matrix expressions:
847 \f[\texttt{dst} = \texttt{src1} >= \texttt{src2}\f]
849 Output matrix of depth @ref CV_8U must have the same size and the same number of channels as
852 Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
854 @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpGE"
855 @param src1 first input matrix.
856 @param src2 second input matrix/scalar of the same depth as first input matrix.
857 @sa min, max, threshold, cmpLE, cmpGT, cmpLS
859 GAPI_EXPORTS GMat cmpGE(const GMat& src1, const GMat& src2);
861 @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLGEcalar"
863 GAPI_EXPORTS GMat cmpGE(const GMat& src1, const GScalar& src2);
865 /** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are less or equal compare to elements in second.
867 The function compares elements of two matrices src1 and src2 of the same size:
868 \f[\texttt{dst} (I) = \texttt{src1} (I) <= \texttt{src2} (I)\f]
870 When the comparison result is true, the corresponding element of output
871 array is set to 255. The comparison operations can be replaced with the
872 equivalent matrix expressions:
873 \f[\texttt{dst} = \texttt{src1} <= \texttt{src2}\f]
875 Output matrix of depth @ref CV_8U must have the same size and the same number of channels as
878 Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
880 @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLE"
881 @param src1 first input matrix.
882 @param src2 second input matrix/scalar of the same depth as first input matrix.
883 @sa min, max, threshold, cmpGT, cmpGE, cmpLS
885 GAPI_EXPORTS GMat cmpLE(const GMat& src1, const GMat& src2);
887 @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLEScalar"
889 GAPI_EXPORTS GMat cmpLE(const GMat& src1, const GScalar& src2);
891 /** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are equal to elements in second.
893 The function compares elements of two matrices src1 and src2 of the same size:
894 \f[\texttt{dst} (I) = \texttt{src1} (I) == \texttt{src2} (I)\f]
896 When the comparison result is true, the corresponding element of output
897 array is set to 255. The comparison operations can be replaced with the
898 equivalent matrix expressions:
899 \f[\texttt{dst} = \texttt{src1} == \texttt{src2}\f]
901 Output matrix of depth @ref CV_8U must have the same size and the same number of channels as
904 Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
906 @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpEQ"
907 @param src1 first input matrix.
908 @param src2 second input matrix/scalar of the same depth as first input matrix.
909 @sa min, max, threshold, cmpNE
911 GAPI_EXPORTS GMat cmpEQ(const GMat& src1, const GMat& src2);
913 @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpEQScalar"
915 GAPI_EXPORTS GMat cmpEQ(const GMat& src1, const GScalar& src2);
917 /** @brief Performs the per-element comparison of two matrices checking if elements from first matrix are not equal to elements in second.
919 The function compares elements of two matrices src1 and src2 of the same size:
920 \f[\texttt{dst} (I) = \texttt{src1} (I) != \texttt{src2} (I)\f]
922 When the comparison result is true, the corresponding element of output
923 array is set to 255. The comparison operations can be replaced with the
924 equivalent matrix expressions:
925 \f[\texttt{dst} = \texttt{src1} != \texttt{src2}\f]
927 Output matrix of depth @ref CV_8U must have the same size and the same number of channels as
930 Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
932 @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpNE"
933 @param src1 first input matrix.
934 @param src2 second input matrix/scalar of the same depth as first input matrix.
935 @sa min, max, threshold, cmpEQ
937 GAPI_EXPORTS GMat cmpNE(const GMat& src1, const GMat& src2);
939 @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpNEScalar"
941 GAPI_EXPORTS GMat cmpNE(const GMat& src1, const GScalar& src2);
943 /** @brief computes bitwise conjunction of the two matrixes (src1 & src2)
944 Calculates the per-element bit-wise logical conjunction of two matrices of the same size.
946 In case of floating-point matrices, their machine-specific bit
947 representations (usually IEEE754-compliant) are used for the operation.
948 In case of multi-channel matrices, each channel is processed
949 independently. Output matrix must have the same size and depth as the input
952 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
954 @note Function textual ID is "org.opencv.core.pixelwise.bitwise_and"
956 @param src1 first input matrix.
957 @param src2 second input matrix.
959 GAPI_EXPORTS GMat bitwise_and(const GMat& src1, const GMat& src2);
961 @note Function textual ID is "org.opencv.core.pixelwise.compare.bitwise_andS"
962 @param src1 first input matrix.
963 @param src2 scalar, which will be per-lemenetly conjuncted with elements of src1.
965 GAPI_EXPORTS GMat bitwise_and(const GMat& src1, const GScalar& src2);
967 /** @brief computes bitwise disjunction of the two matrixes (src1 | src2)
968 Calculates the per-element bit-wise logical disjunction of two matrices of the same size.
970 In case of floating-point matrices, their machine-specific bit
971 representations (usually IEEE754-compliant) are used for the operation.
972 In case of multi-channel matrices, each channel is processed
973 independently. Output matrix must have the same size and depth as the input
976 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
978 @note Function textual ID is "org.opencv.core.pixelwise.bitwise_or"
980 @param src1 first input matrix.
981 @param src2 second input matrix.
983 GAPI_EXPORTS GMat bitwise_or(const GMat& src1, const GMat& src2);
985 @note Function textual ID is "org.opencv.core.pixelwise.compare.bitwise_orS"
986 @param src1 first input matrix.
987 @param src2 scalar, which will be per-lemenetly disjuncted with elements of src1.
989 GAPI_EXPORTS GMat bitwise_or(const GMat& src1, const GScalar& src2);
992 /** @brief computes bitwise logical "exclusive or" of the two matrixes (src1 ^ src2)
993 Calculates the per-element bit-wise logical "exclusive or" of two matrices of the same size.
995 In case of floating-point matrices, their machine-specific bit
996 representations (usually IEEE754-compliant) are used for the operation.
997 In case of multi-channel matrices, each channel is processed
998 independently. Output matrix must have the same size and depth as the input
1001 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
1003 @note Function textual ID is "org.opencv.core.pixelwise.bitwise_xor"
1005 @param src1 first input matrix.
1006 @param src2 second input matrix.
1008 GAPI_EXPORTS GMat bitwise_xor(const GMat& src1, const GMat& src2);
1010 @note Function textual ID is "org.opencv.core.pixelwise.compare.bitwise_xorS"
1011 @param src1 first input matrix.
1012 @param src2 scalar, for which per-lemenet "logical or" operation on elements of src1 will be performed.
1014 GAPI_EXPORTS GMat bitwise_xor(const GMat& src1, const GScalar& src2);
1017 /** @brief Inverts every bit of an array.
1018 The function bitwise_not calculates per-element bit-wise inversion of the input
1020 \f[\texttt{dst} (I) = \neg \texttt{src} (I)\f]
1022 In case of floating-point matrices, their machine-specific bit
1023 representations (usually IEEE754-compliant) are used for the operation.
1024 In case of multi-channel matrices, each channel is processed
1025 independently. Output matrix must have the same size and depth as the input
1028 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
1030 @note Function textual ID is "org.opencv.core.pixelwise.bitwise_not"
1032 @param src input matrix.
1034 GAPI_EXPORTS GMat bitwise_not(const GMat& src);
1036 /** @brief Select values from either first or second of input matrices by given mask.
1037 The function set to the output matrix either the value from the first input matrix if corresponding value of mask matrix is 255,
1038 or value from the second input matrix (if value of mask matrix set to 0).
1040 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
1041 be the same for all input and output matrices.
1042 Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
1044 @note Function textual ID is "org.opencv.core.pixelwise.select"
1046 @param src1 first input matrix.
1047 @param src2 second input matrix.
1048 @param mask mask input matrix.
1050 GAPI_EXPORTS GMat select(const GMat& src1, const GMat& src2, const GMat& mask);
1052 //! @} gapi_pixelwise
1055 //! @addtogroup gapi_matrixop
1057 /** @brief Calculates per-element minimum of two matrices.
1059 The function min calculates the per-element minimum of two matrices of the same size, number of channels and depth:
1060 \f[\texttt{dst} (I)= \min ( \texttt{src1} (I), \texttt{src2} (I))\f]
1061 where I is a multi-dimensional index of matrix elements. In case of
1062 multi-channel matrices, each channel is processed independently.
1063 Output matrix must be of the same size and depth as src1.
1065 Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
1067 @note Function textual ID is "org.opencv.core.matrixop.min"
1068 @param src1 first input matrix.
1069 @param src2 second input matrix of the same size and depth as src1.
1070 @sa max, compareEqual, compareLess, compareLessEqual
1072 GAPI_EXPORTS GMat min(const GMat& src1, const GMat& src2);
1074 /** @brief Calculates per-element maximum of two matrices.
1076 The function max calculates the per-element maximum of two matrices of the same size, number of channels and depth:
1077 \f[\texttt{dst} (I)= \max ( \texttt{src1} (I), \texttt{src2} (I))\f]
1078 where I is a multi-dimensional index of matrix elements. In case of
1079 multi-channel matrices, each channel is processed independently.
1080 Output matrix must be of the same size and depth as src1.
1082 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
1084 @note Function textual ID is "org.opencv.core.matrixop.max"
1085 @param src1 first input matrix.
1086 @param src2 second input matrix of the same size and depth as src1.
1087 @sa min, compare, compareEqual, compareGreater, compareGreaterEqual
1089 GAPI_EXPORTS GMat max(const GMat& src1, const GMat& src2);
1091 /** @brief Calculates the per-element absolute difference between two matrices.
1093 The function absDiff calculates absolute difference between two matrices of the same size and depth:
1094 \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1}(I) - \texttt{src2}(I)|)\f]
1095 where I is a multi-dimensional index of matrix elements. In case of
1096 multi-channel matrices, each channel is processed independently.
1097 Output matrix must have the same size and depth as input matrices.
1099 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
1101 @note Function textual ID is "org.opencv.core.matrixop.absdiff"
1102 @param src1 first input matrix.
1103 @param src2 second input matrix.
1106 GAPI_EXPORTS GMat absDiff(const GMat& src1, const GMat& src2);
1108 /** @brief Calculates absolute value of matrix elements.
1110 The function abs calculates absolute difference between matrix elements and given scalar value:
1111 \f[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1}(I) - \texttt{matC}(I)|)\f]
1112 where matC is constructed from given scalar c and has the same sizes and depth as input matrix src.
1114 Output matrix must be of the same size and depth as src.
1116 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
1118 @note Function textual ID is "org.opencv.core.matrixop.absdiffC"
1119 @param src input matrix.
1120 @param c scalar to be subtracted.
1123 GAPI_EXPORTS GMat absDiffC(const GMat& src, const GScalar& c);
1125 /** @brief Calculates sum of all matrix elements.
1127 The function sum calculates sum of all matrix elements, independently for each channel.
1129 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
1131 @note Function textual ID is "org.opencv.core.matrixop.sum"
1132 @param src input matrix.
1135 GAPI_EXPORTS GScalar sum(const GMat& src);
1137 /** @brief Calculates the weighted sum of two matrices.
1139 The function addWeighted calculates the weighted sum of two matrices as follows:
1140 \f[\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I)* \texttt{alpha} + \texttt{src2} (I)* \texttt{beta} + \texttt{gamma} )\f]
1141 where I is a multi-dimensional index of array elements. In case of multi-channel matrices, each
1142 channel is processed independently.
1144 The function can be replaced with a matrix expression:
1145 \f[\texttt{dst}(I) = \texttt{alpha} * \texttt{src1}(I) - \texttt{beta} * \texttt{src2}(I) + \texttt{gamma} \f]
1147 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
1149 @note Function textual ID is "org.opencv.core.matrixop.addweighted"
1150 @param src1 first input matrix.
1151 @param alpha weight of the first matrix elements.
1152 @param src2 second input matrix of the same size and channel number as src1.
1153 @param beta weight of the second matrix elements.
1154 @param gamma scalar added to each sum.
1155 @param ddepth optional depth of the output matrix.
1158 GAPI_EXPORTS GMat addWeighted(const GMat& src1, double alpha, const GMat& src2, double beta, double gamma, int ddepth = -1);
1160 /** @brief Calculates the absolute L1 norm of a matrix.
1162 This version of normL1 calculates the absolute L1 norm of src.
1164 As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$.
1165 The \f$ L_{1} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$
1166 is calculated as follows
1168 \| r(-1) \|_{L_1} &= |-1| + |2| = 3 \\
1170 and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is
1172 \| r(0.5) \|_{L_1} &= |0.5| + |0.5| = 1 \\
1175 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
1177 @note Function textual ID is "org.opencv.core.matrixop.norml1"
1178 @param src input matrix.
1181 GAPI_EXPORTS GScalar normL1(const GMat& src);
1183 /** @brief Calculates the absolute L2 norm of a matrix.
1185 This version of normL2 calculates the absolute L2 norm of src.
1187 As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$.
1188 The \f$ L_{2} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$
1189 is calculated as follows
1191 \| r(-1) \|_{L_2} &= \sqrt{(-1)^{2} + (2)^{2}} = \sqrt{5} \\
1193 and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is
1195 \| r(0.5) \|_{L_2} &= \sqrt{(0.5)^{2} + (0.5)^{2}} = \sqrt{0.5} \\
1198 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
1199 @note Function textual ID is "org.opencv.core.matrixop.norml2"
1200 @param src input matrix.
1203 GAPI_EXPORTS GScalar normL2(const GMat& src);
1205 /** @brief Calculates the absolute infinite norm of a matrix.
1207 This version of normInf calculates the absolute infinite norm of src.
1209 As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$.
1210 The \f$ L_{\infty} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$
1211 is calculated as follows
1213 \| r(-1) \|_{L_\infty} &= \max(|-1|,|2|) = 2
1215 and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is
1217 \| r(0.5) \|_{L_\infty} &= \max(|0.5|,|0.5|) = 0.5.
1220 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
1222 @note Function textual ID is "org.opencv.core.matrixop.norminf"
1223 @param src input matrix.
1226 GAPI_EXPORTS GScalar normInf(const GMat& src);
1228 /** @brief Calculates the integral of an image.
1230 The function calculates one or more integral images for the source image as follows:
1232 \f[\texttt{sum} (X,Y) = \sum _{x<X,y<Y} \texttt{image} (x,y)\f]
1234 \f[\texttt{sqsum} (X,Y) = \sum _{x<X,y<Y} \texttt{image} (x,y)^2\f]
1236 The function return integral image as \f$(W+1)\times (H+1)\f$ , 32-bit integer or floating-point (32f or 64f) and
1237 integral image for squared pixel values; it is \f$(W+1)\times (H+)\f$, double-precision floating-point (64f) array.
1239 @note Function textual ID is "org.opencv.core.matrixop.integral"
1241 @param src input image.
1242 @param sdepth desired depth of the integral and the tilted integral images, CV_32S, CV_32F, or
1244 @param sqdepth desired depth of the integral image of squared pixel values, CV_32F or CV_64F.
1246 GAPI_EXPORTS std::tuple<GMat, GMat> integral(const GMat& src, int sdepth = -1, int sqdepth = -1);
1248 /** @brief Applies a fixed-level threshold to each matrix element.
1250 The function applies fixed-level thresholding to a single- or multiple-channel matrix.
1251 The function is typically used to get a bi-level (binary) image out of a grayscale image ( cmp funtions could be also used for
1252 this purpose) or for removing a noise, that is, filtering out pixels with too small or too large
1253 values. There are several depths of thresholding supported by the function. They are determined by
1256 Also, the special values cv::THRESH_OTSU or cv::THRESH_TRIANGLE may be combined with one of the
1257 above values. In these cases, the function determines the optimal threshold value using the Otsu's
1258 or Triangle algorithm and uses it instead of the specified thresh . The function returns the
1259 computed threshold value in addititon to thresholded matrix.
1260 The Otsu's and Triangle methods are implemented only for 8-bit matrices.
1262 Input image should be single channel only in case of cv::THRESH_OTSU or cv::THRESH_TRIANGLE flags.
1263 Output matrix must be of the same size and depth as src.
1265 @note Function textual ID is "org.opencv.core.matrixop.threshold"
1267 @param src input matrix (@ref CV_8UC1, @ref CV_8UC3, or @ref CV_32FC1).
1268 @param thresh threshold value.
1269 @param maxval maximum value to use with the cv::THRESH_BINARY and cv::THRESH_BINARY_INV thresholding
1271 @param depth thresholding depth (see the cv::ThresholdTypes).
1273 @sa min, max, cmpGT, cmpLE, cmpGE, cmpLS
1275 GAPI_EXPORTS GMat threshold(const GMat& src, const GScalar& thresh, const GScalar& maxval, int depth);
1277 This function appicable for all threshold depths except CV_THRESH_OTSU and CV_THRESH_TRIANGLE
1278 @note Function textual ID is "org.opencv.core.matrixop.thresholdOT"
1280 GAPI_EXPORTS std::tuple<GMat, GScalar> threshold(const GMat& src, const GScalar& maxval, int depth);
1282 /** @brief Applies a range-level threshold to each matrix element.
1284 The function applies range-level thresholding to a single- or multiple-channel matrix.
1285 It sets output pixel value to OxFF if the corresponding pixel value of input matrix is in specified range,or 0 otherwise.
1287 Input and output matrices must be CV_8UC1.
1289 @note Function textual ID is "org.opencv.core.matrixop.inRange"
1291 @param src input matrix (CV_8UC1).
1292 @param threshLow lower boundary value.
1293 @param threshUp upper boundary value.
1297 GAPI_EXPORTS GMat inRange(const GMat& src, const GScalar& threshLow, const GScalar& threshUp);
1299 //! @} gapi_matrixop
1301 //! @addtogroup gapi_transform
1303 /** @brief Resizes an image.
1305 The function resizes the image src down to or up to the specified size.
1307 Output image size will have the size dsize (when dsize is non-zero) or the size computed from
1308 src.size(), fx, and fy; the depth of output is the same as of src.
1310 If you want to resize src so that it fits the pre-created dst,
1311 you may call the function as follows:
1313 // explicitly specify dsize=dst.size(); fx and fy will be computed from that.
1314 resize(src, dst, dst.size(), 0, 0, interpolation);
1316 If you want to decimate the image by factor of 2 in each direction, you can call the function this
1319 // specify fx and fy and let the function compute the destination image size.
1320 resize(src, dst, Size(), 0.5, 0.5, interpolation);
1322 To shrink an image, it will generally look best with cv::INTER_AREA interpolation, whereas to
1323 enlarge an image, it will generally look best with cv::INTER_CUBIC (slow) or cv::INTER_LINEAR
1324 (faster but still looks OK).
1326 @note Function textual ID is "org.opencv.core.transform.resize"
1328 @param src input image.
1329 @param dsize output image size; if it equals zero, it is computed as:
1330 \f[\texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}\f]
1331 Either dsize or both fx and fy must be non-zero.
1332 @param fx scale factor along the horizontal axis; when it equals 0, it is computed as
1333 \f[\texttt{(double)dsize.width/src.cols}\f]
1334 @param fy scale factor along the vertical axis; when it equals 0, it is computed as
1335 \f[\texttt{(double)dsize.height/src.rows}\f]
1336 @param interpolation interpolation method, see cv::InterpolationFlags
1338 @sa warpAffine, warpPerspective, remap
1340 GAPI_EXPORTS GMat resize(const GMat& src, const Size& dsize, double fx = 0, double fy = 0, int interpolation = INTER_LINEAR);
1342 /** @brief Creates one 3-channel (4-channel) matrix out of 3(4) single-channel ones.
1344 The function merges several matrices to make a single multi-channel matrix. That is, each
1345 element of the output matrix will be a concatenation of the elements of the input matrices, where
1346 elements of i-th input matrix are treated as mv[i].channels()-element vectors.
1347 Input matrix must be of @ref CV_8UC3 (@ref CV_8UC4) type.
1349 The function split3/split4 does the reverse operation.
1351 @note Function textual ID for merge3 is "org.opencv.core.transform.merge3"
1352 @note Function textual ID for merge4 is "org.opencv.core.transform.merge4"
1354 @param src1 first input matrix to be merged
1355 @param src2 second input matrix to be merged
1356 @param src3 third input matrix to be merged
1357 @param src4 fourth input matrix to be merged
1360 GAPI_EXPORTS GMat merge4(const GMat& src1, const GMat& src2, const GMat& src3, const GMat& src4);
1361 GAPI_EXPORTS GMat merge3(const GMat& src1, const GMat& src2, const GMat& src3);
1363 /** @brief Divides a 3-channel (4-channel) matrix into 3(4) single-channel matrices.
1365 The function splits a 3-channel (4-channel) matrix into 3(4) single-channel matrices:
1366 \f[\texttt{mv} [c](I) = \texttt{src} (I)_c\f]
1368 All output matrices must be in @ref CV_8UC1.
1370 @note Function textual for split3 ID is "org.opencv.core.transform.split3"
1371 @note Function textual for split4 ID is "org.opencv.core.transform.split4"
1373 @param src input @ref CV_8UC4 (@ref CV_8UC3) matrix.
1376 GAPI_EXPORTS std::tuple<GMat, GMat, GMat,GMat> split4(const GMat& src);
1377 GAPI_EXPORTS std::tuple<GMat, GMat, GMat> split3(const GMat& src);
1379 /** @brief Applies a generic geometrical transformation to an image.
1381 The function remap transforms the source image using the specified map:
1383 \f[\texttt{dst} (x,y) = \texttt{src} (map_x(x,y),map_y(x,y))\f]
1385 where values of pixels with non-integer coordinates are computed using one of available
1386 interpolation methods. \f$map_x\f$ and \f$map_y\f$ can be encoded as separate floating-point maps
1387 in \f$map_1\f$ and \f$map_2\f$ respectively, or interleaved floating-point maps of \f$(x,y)\f$ in
1388 \f$map_1\f$, or fixed-point maps created by using convertMaps. The reason you might want to
1389 convert from floating to fixed-point representations of a map is that they can yield much faster
1390 (\~2x) remapping operations. In the converted case, \f$map_1\f$ contains pairs (cvFloor(x),
1391 cvFloor(y)) and \f$map_2\f$ contains indices in a table of interpolation coefficients.
1392 Output image must be of the same size and depth as input one.
1394 @note Function textual ID is "org.opencv.core.transform.remap"
1396 @param src Source image.
1397 @param map1 The first map of either (x,y) points or just x values having the type CV_16SC2,
1398 CV_32FC1, or CV_32FC2.
1399 @param map2 The second map of y values having the type CV_16UC1, CV_32FC1, or none (empty map
1400 if map1 is (x,y) points), respectively.
1401 @param interpolation Interpolation method (see cv::InterpolationFlags). The method INTER_AREA is
1402 not supported by this function.
1403 @param borderMode Pixel extrapolation method (see cv::BorderTypes). When
1404 borderMode=BORDER_TRANSPARENT, it means that the pixels in the destination image that
1405 corresponds to the "outliers" in the source image are not modified by the function.
1406 @param borderValue Value used in case of a constant border. By default, it is 0.
1408 Due to current implementation limitations the size of an input and output images should be less than 32767x32767.
1410 GAPI_EXPORTS GMat remap(const GMat& src, const Mat& map1, const Mat& map2,
1411 int interpolation, int borderMode = BORDER_CONSTANT,
1412 const Scalar& borderValue = Scalar());
1414 /** @brief Flips a 2D matrix around vertical, horizontal, or both axes.
1416 The function flips the matrix in one of three different ways (row
1417 and column indices are 0-based):
1418 \f[\texttt{dst} _{ij} =
1421 \texttt{src} _{\texttt{src.rows}-i-1,j} & if\; \texttt{flipCode} = 0 \\
1422 \texttt{src} _{i, \texttt{src.cols} -j-1} & if\; \texttt{flipCode} > 0 \\
1423 \texttt{src} _{ \texttt{src.rows} -i-1, \texttt{src.cols} -j-1} & if\; \texttt{flipCode} < 0 \\
1426 The example scenarios of using the function are the following:
1427 * Vertical flipping of the image (flipCode == 0) to switch between
1428 top-left and bottom-left image origin. This is a typical operation
1429 in video processing on Microsoft Windows\* OS.
1430 * Horizontal flipping of the image with the subsequent horizontal
1431 shift and absolute difference calculation to check for a
1432 vertical-axis symmetry (flipCode \> 0).
1433 * Simultaneous horizontal and vertical flipping of the image with
1434 the subsequent shift and absolute difference calculation to check
1435 for a central symmetry (flipCode \< 0).
1436 * Reversing the order of point arrays (flipCode \> 0 or
1438 Output image must be of the same depth as input one, size should be correct for given flipCode.
1440 @note Function textual ID is "org.opencv.core.transform.flip"
1442 @param src input matrix.
1443 @param flipCode a flag to specify how to flip the array; 0 means
1444 flipping around the x-axis and positive value (for example, 1) means
1445 flipping around y-axis. Negative value (for example, -1) means flipping
1449 GAPI_EXPORTS GMat flip(const GMat& src, int flipCode);
1451 /** @brief Crops a 2D matrix.
1453 The function crops the matrix by given cv::Rect.
1455 Output matrix must be of the same depth as input one, size is specified by given rect size.
1457 @note Function textual ID is "org.opencv.core.transform.crop"
1459 @param src input matrix.
1460 @param rect a rect to crop a matrix to
1463 GAPI_EXPORTS GMat crop(const GMat& src, const Rect& rect);
1465 /** @brief Applies horizontal concatenation to given matrices.
1467 The function horizontally concatenates two GMat matrices (with the same number of rows).
1476 GMat C = gapi::concatHor(A, B);
1482 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.
1483 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
1485 @note Function textual ID is "org.opencv.imgproc.transform.concatHor"
1487 @param src1 first input matrix to be considered for horizontal concatenation.
1488 @param src2 second input matrix to be considered for horizontal concatenation.
1491 GAPI_EXPORTS GMat concatHor(const GMat& src1, const GMat& src2);
1494 The function horizontally concatenates given number of GMat matrices (with the same number of columns).
1495 Output matrix must the same number of columns and depth as the input matrices, and the sum of rows of input matrices.
1497 @param v vector of input matrices to be concatenated horizontally.
1499 GAPI_EXPORTS GMat concatHor(const std::vector<GMat> &v);
1501 /** @brief Applies vertical concatenation to given matrices.
1503 The function vertically concatenates two GMat matrices (with the same number of cols).
1512 GMat C = gapi::concatVert(A, B);
1522 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.
1523 Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1.
1525 @note Function textual ID is "org.opencv.imgproc.transform.concatVert"
1527 @param src1 first input matrix to be considered for vertical concatenation.
1528 @param src2 second input matrix to be considered for vertical concatenation.
1531 GAPI_EXPORTS GMat concatVert(const GMat& src1, const GMat& src2);
1534 The function vertically concatenates given number of GMat matrices (with the same number of columns).
1535 Output matrix must the same number of columns and depth as the input matrices, and the sum of rows of input matrices.
1537 @param v vector of input matrices to be concatenated vertically.
1539 GAPI_EXPORTS GMat concatVert(const std::vector<GMat> &v);
1542 /** @brief Performs a look-up table transform of a matrix.
1544 The function LUT fills the output matrix with values from the look-up table. Indices of the entries
1545 are taken from the input matrix. That is, the function processes each element of src as follows:
1546 \f[\texttt{dst} (I) \leftarrow \texttt{lut(src(I))}\f]
1548 Supported matrix data types are @ref CV_8UC1.
1549 Output is a matrix of the same size and number of channels as src, and the same depth as lut.
1551 @note Function textual ID is "org.opencv.core.transform.LUT"
1553 @param src input matrix of 8-bit elements.
1554 @param lut look-up table of 256 elements; in case of multi-channel input array, the table should
1555 either have a single channel (in this case the same table is used for all channels) or the same
1556 number of channels as in the input matrix.
1558 GAPI_EXPORTS GMat LUT(const GMat& src, const Mat& lut);
1560 /** @brief Performs a 3D look-up table transform of a multi-channel matrix.
1562 The function LUT3D fills the output matrix with values from the look-up table. Indices of the entries
1563 are taken from the input matrix. Interpolation is applied for mapping 0-255 range values to 0-16 range of 3DLUT table.
1564 The function processes each element of src as follows:
1566 dst[i][j][k] = lut3D[~src_r][~src_g][~src_b];
1568 where ~ means approximation.
1569 Output is a matrix of of @ref CV_8UC3.
1571 @note Function textual ID is "org.opencv.core.transform.LUT3D"
1573 @param src input matrix of @ref CV_8UC3.
1574 @param lut3D look-up table 17x17x17 3-channel elements.
1575 @param interpolation The depth of interpoolation to be used.
1577 GAPI_EXPORTS GMat LUT3D(const GMat& src, const GMat& lut3D, int interpolation = INTER_NEAREST);
1579 /** @brief Converts a matrix to another data depth with optional scaling.
1581 The method converts source pixel values to the target data depth. saturate_cast\<\> is applied at
1582 the end to avoid possible overflows:
1584 \f[m(x,y) = saturate \_ cast<rType>( \alpha (*this)(x,y) + \beta )\f]
1585 Output matrix must be of the same size as input one.
1587 @note Function textual ID is "org.opencv.core.transform.convertTo"
1588 @param src input matrix to be converted from.
1589 @param rdepth desired output matrix depth or, rather, the depth since the number of channels are the
1590 same as the input has; if rdepth is negative, the output matrix will have the same depth as the input.
1591 @param alpha optional scale factor.
1592 @param beta optional delta added to the scaled values.
1594 GAPI_EXPORTS GMat convertTo(const GMat& src, int rdepth, double alpha=1, double beta=0);
1595 //! @} gapi_transform
1600 #endif //OPENCV_GAPI_CORE_HPP