OpenCV  4.0.0-beta
Open Source Computer Vision
Functions
Graph API: Math operations

Functions

GAPI_EXPORTS GMat cv::gapi::add (const GMat &src1, const GMat &src2, int ddepth=-1)
 Calculates the per-element sum of two matrices. More...
 
GAPI_EXPORTS GMat cv::gapi::addC (const GMat &src1, const GScalar &c, int ddepth=-1)
 Calculates the per-element sum of matrix and given scalar. More...
 
GAPI_EXPORTS GMat cv::gapi::addC (const GScalar &c, const GMat &src1, int ddepth=-1)
 
GAPI_EXPORTS std::tuple< GMat, GMatcv::gapi::cartToPolar (const GMat &x, const GMat &y, bool angleInDegrees=false)
 Calculates the magnitude and angle of 2D vectors. More...
 
GAPI_EXPORTS GMat cv::gapi::div (const GMat &src1, const GMat &src2, double scale, int ddepth=-1)
 Performs per-element division of two matrices. More...
 
GAPI_EXPORTS GMat cv::gapi::divC (const GMat &src, const GScalar &divisor, double scale, int ddepth=-1)
 Divides matrix by scalar. More...
 
GAPI_EXPORTS GMat cv::gapi::divRC (const GScalar &divident, const GMat &src, double scale, int ddepth=-1)
 Divides scalar by matrix. More...
 
GAPI_EXPORTS GMat cv::gapi::mask (const GMat &src, const GMat &mask)
 Applies a mask to a matrix. More...
 
GAPI_EXPORTS GScalar cv::gapi::mean (const GMat &src)
 Calculates an average (mean) of matrix elements. More...
 
GAPI_EXPORTS GMat cv::gapi::mul (const GMat &src1, const GMat &src2, double scale, int ddepth=-1)
 Calculates the per-element scaled product of two matrices. More...
 
GAPI_EXPORTS GMat cv::gapi::mulC (const GMat &src, double multiplier, int ddepth=-1)
 Multiplies matrix by scalar. More...
 
GAPI_EXPORTS GMat cv::gapi::mulC (const GMat &src, const GScalar &multiplier, int ddepth=-1)
 
GAPI_EXPORTS GMat cv::gapi::mulC (const GScalar &multiplier, const GMat &src, int ddepth=-1)
 
GAPI_EXPORTS std::tuple< GMat, GMatcv::gapi::polarToCart (const GMat &magnitude, const GMat &angle, bool angleInDegrees=false)
 Calculates x and y coordinates of 2D vectors from their magnitude and angle. More...
 
GAPI_EXPORTS GMat cv::gapi::sub (const GMat &src1, const GMat &src2, int ddepth=-1)
 Calculates the per-element difference between two matrices. More...
 
GAPI_EXPORTS GMat cv::gapi::subC (const GMat &src, const GScalar &c, int ddepth=-1)
 Calculates the per-element difference between matrix and given scalar. More...
 
GAPI_EXPORTS GMat cv::gapi::subRC (const GScalar &c, const GMat &src, int ddepth=-1)
 Calculates the per-element difference between given scalar and the matrix. More...
 

Detailed Description

Function Documentation

§ add()

GAPI_EXPORTS GMat cv::gapi::add ( const GMat src1,
const GMat src2,
int  ddepth = -1 
)

Calculates the per-element sum of two matrices.

The function add calculates sum of two matrices of the same size and the same number of channels:

\[\texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) + \texttt{src2}(I)) \quad \texttt{if mask}(I) \ne0\]

The function can be replaced with matrix expressions:

\[\texttt{dst} = \texttt{src1} + \texttt{src2}\]

The input matrices and the output matrix can all have the same or different depths. For example, you can add a 16-bit unsigned matrix to a 8-bit signed matrix and store the sum as a 32-bit floating-point matrix. Depth of the output matrix is determined by the ddepth parameter. If src1.depth() == src2.depth(), ddepth can be set to the default -1. In this case, the output matrix will have the same depth as the input matrices.

Supported matrix data types are CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1.

Note
Function textual ID is "org.opencv.core.math.add"
Parameters
src1first input matrix.
src2second input matrix.
ddepthoptional depth of the output matrix.
See also
sub, addWeighted

§ addC() [1/2]

GAPI_EXPORTS GMat cv::gapi::addC ( const GMat src1,
const GScalar c,
int  ddepth = -1 
)

Calculates the per-element sum of matrix and given scalar.

The function addC adds a given scalar value to each element of given matrix. The function can be replaced with matrix expressions:

\[\texttt{dst} = \texttt{src1} + \texttt{c}\]

Depth of the output matrix is determined by the ddepth parameter. If ddepth is set to default -1, the depth of output matrix will be the same as the depth of input matrix. The matrices can be single or multi channel. Output matrix must have the same size and number of channels as the input matrix.

Supported matrix data types are CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1.

Note
Function textual ID is "org.opencv.core.math.addC"
Parameters
src1first input matrix.
cscalar value to be added.
ddepthoptional depth of the output matrix.
See also
sub, addWeighted

§ addC() [2/2]

GAPI_EXPORTS GMat cv::gapi::addC ( const GScalar c,
const GMat src1,
int  ddepth = -1 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

§ cartToPolar()

GAPI_EXPORTS std::tuple<GMat, GMat> cv::gapi::cartToPolar ( const GMat x,
const GMat y,
bool  angleInDegrees = false 
)

Calculates the magnitude and angle of 2D vectors.

The function cartToPolar calculates either the magnitude, angle, or both for every 2D vector (x(I),y(I)):

\[\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}\]

The angles are calculated with accuracy about 0.3 degrees. For the point (0,0), the angle is set to 0.

First output is a matrix of magnitudes of the same size and depth as input x. Second output is a matrix of angles that has the same size and depth as x; the angles are measured in radians (from 0 to 2*Pi) or in degrees (0 to 360 degrees).

Note
Function textual ID is "org.opencv.core.math.cartToPolar"
Parameters
xmatrix of CV_32FC1 x-coordinates.
yarray of CV_32FC1 y-coordinates.
angleInDegreesa flag, indicating whether the angles are measured in radians (which is by default), or in degrees.
See also
polarToCart

§ div()

GAPI_EXPORTS GMat cv::gapi::div ( const GMat src1,
const GMat src2,
double  scale,
int  ddepth = -1 
)

Performs per-element division of two matrices.

The function divides one matrix by another:

\[\texttt{dst(I) = saturate(src1(I)*scale/src2(I))}\]

When src2(I) is zero, dst(I) will also be zero. Different channels of multi-channel matrices are processed independently. The matrices can be single or multi channel. Output matrix must have the same size and depth as src.

Supported matrix data types are CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1.

Note
Function textual ID is "org.opencv.core.math.div"
Parameters
src1first input matrix.
src2second input matrix of the same size and depth as src1.
scalescalar factor.
ddepthoptional depth of the output matrix; you can only pass -1 when src1.depth() == src2.depth().
See also
mul, add, sub

§ divC()

GAPI_EXPORTS GMat cv::gapi::divC ( const GMat src,
const GScalar divisor,
double  scale,
int  ddepth = -1 
)

Divides matrix by scalar.

The function divC divides each element of matrix src by given scalar value:

\[\texttt{dst(I) = saturate(src(I)*scale/divisor)}\]

When divisor is zero, dst(I) will also be zero. Different channels of multi-channel matrices are processed independently. The matrices can be single or multi channel. Output matrix must have the same size and depth as src.

Supported matrix data types are CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1.

Note
Function textual ID is "org.opencv.core.math.divC"
Parameters
srcinput matrix.
divisornumber to be divided by.
ddepthoptional depth of the output matrix. If -1, the depth of output matrix will be the same as input matrix depth.
scalescale factor.
See also
add, sub, div, addWeighted

§ divRC()

GAPI_EXPORTS GMat cv::gapi::divRC ( const GScalar divident,
const GMat src,
double  scale,
int  ddepth = -1 
)

Divides scalar by matrix.

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:

\[\texttt{dst(I) = saturate(divident*scale/src(I))}\]

When src(I) is zero, dst(I) will also be zero. Different channels of multi-channel matrices are processed independently. The matrices can be single or multi channel. Output matrix must have the same size and depth as src.

Supported matrix data types are CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1.

Note
Function textual ID is "org.opencv.core.math.divRC"
Parameters
srcinput matrix.
dividentnumber to be divided.
ddepthoptional depth of the output matrix. If -1, the depth of output matrix will be the same as input matrix depth.
scalescale factor
See also
add, sub, div, addWeighted

§ mask()

GAPI_EXPORTS GMat cv::gapi::mask ( const GMat src,
const GMat mask 
)

Applies a mask to a matrix.

The function mask set value from given matrix if the corresponding pixel value in mask matrix set to true, and set the matrix value to 0 overwise.

Supported src matrix data types are CV_8UC1, CV_16SC1, CV_16UC1. Supported mask data type is CV_8UC1.

Note
Function textual ID is "org.opencv.core.math.mask"
Parameters
srcinput matrix.
maskinput mask matrix.
Examples:
samples/cpp/camshiftdemo.cpp, samples/cpp/create_mask.cpp, samples/cpp/ffilldemo.cpp, samples/cpp/grabcut.cpp, samples/cpp/segment_objects.cpp, samples/cpp/stitching_detailed.cpp, samples/cpp/tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp, and samples/cpp/tutorial_code/photo/seamless_cloning/cloning_demo.cpp.

§ mean()

GAPI_EXPORTS GScalar cv::gapi::mean ( const GMat src)

Calculates an average (mean) of matrix elements.

The function mean calculates the mean value M of matrix elements, independently for each channel, and return it.

Supported matrix data types are CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1.

Note
Function textual ID is "org.opencv.core.math.mean"
Parameters
srcinput matrix.

§ mul()

GAPI_EXPORTS GMat cv::gapi::mul ( const GMat src1,
const GMat src2,
double  scale,
int  ddepth = -1 
)

Calculates the per-element scaled product of two matrices.

The function mul calculates the per-element product of two matrices:

\[\texttt{dst} (I)= \texttt{saturate} ( \texttt{scale} \cdot \texttt{src1} (I) \cdot \texttt{src2} (I))\]

If src1.depth() == src2.depth(), ddepth can be set to the default -1. In this case, the output matrix will have the same depth as the input matrices. The matrices can be single or multi channel. Output matrix must have the same size as input matrices.

Supported matrix data types are CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1.

Note
Function textual ID is "org.opencv.core.math.mul"
Parameters
src1first input matrix.
src2second input matrix of the same size and the same depth as src1.
scaleoptional scale factor.
ddepthoptional depth of the output matrix.
See also
add, sub, div, addWeighted

§ mulC() [1/3]

GAPI_EXPORTS GMat cv::gapi::mulC ( const GMat src,
double  multiplier,
int  ddepth = -1 
)

Multiplies matrix by scalar.

The function mulC multiplies each element of matrix src by given scalar value:

\[\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I) \cdot \texttt{multiplier} )\]

The matrices can be single or multi channel. Output matrix must have the same size as src.

Supported matrix data types are CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1.

Note
Function textual ID is "org.opencv.core.math.mulC"
Parameters
srcinput matrix.
multiplierfactor to be multiplied.
ddepthoptional depth of the output matrix. If -1, the depth of output matrix will be the same as input matrix depth.
See also
add, sub, div, addWeighted

§ mulC() [2/3]

GAPI_EXPORTS GMat cv::gapi::mulC ( const GMat src,
const GScalar multiplier,
int  ddepth = -1 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

§ mulC() [3/3]

GAPI_EXPORTS GMat cv::gapi::mulC ( const GScalar multiplier,
const GMat src,
int  ddepth = -1 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

§ polarToCart()

GAPI_EXPORTS std::tuple<GMat, GMat> cv::gapi::polarToCart ( const GMat magnitude,
const GMat angle,
bool  angleInDegrees = false 
)

Calculates x and y coordinates of 2D vectors from their magnitude and angle.

The function polarToCart calculates the Cartesian coordinates of each 2D vector represented by the corresponding elements of magnitude and angle:

\[\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}\]

The relative accuracy of the estimated coordinates is about 1e-6.

First output is a matrix of x-coordinates of 2D vectors. Second output is a matrix of y-coordinates of 2D vectors. Both output must have the same size and depth as input matrices.

Note
Function textual ID is "org.opencv.core.math.polarToCart"
Parameters
magnitudeinput floating-point CV_32FC1 matrix (1xN) of magnitudes of 2D vectors;
angleinput floating-point CV_32FC1 matrix (1xN) of angles of 2D vectors.
angleInDegreeswhen true, the input angles are measured in degrees, otherwise, they are measured in radians.
See also
cartToPolar, exp, log, pow, sqrt

§ sub()

GAPI_EXPORTS GMat cv::gapi::sub ( const GMat src1,
const GMat src2,
int  ddepth = -1 
)

Calculates the per-element difference between two matrices.

The function sub calculates difference between two matrices, when both matrices have the same size and the same number of channels:

\[\texttt{dst}(I) = \texttt{src1}(I) - \texttt{src2}(I)\]

The function can be replaced with matrix expressions:

\[\texttt{dst} = \texttt{src1} - \texttt{src2}\]

The input matrices and the output matrix can all have the same or different depths. For example, you can subtract two 8-bit unsigned matrices store the result as a 16-bit signed matrix. Depth of the output matrix is determined by the ddepth parameter. If src1.depth() == src2.depth(), ddepth can be set to the default -1. In this case, the output matrix will have the same depth as the input matrices. The matrices can be single or multi channel.

Supported matrix data types are CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1.

Note
Function textual ID is "org.opencv.core.math.sub"
Parameters
src1first input matrix.
src2second input matrix.
ddepthoptional depth of the output matrix.
See also
add, addC

§ subC()

GAPI_EXPORTS GMat cv::gapi::subC ( const GMat src,
const GScalar c,
int  ddepth = -1 
)

Calculates the per-element difference between matrix and given scalar.

The function can be replaced with matrix expressions:

\[\texttt{dst} = \texttt{src} - \texttt{c}\]

Depth of the output matrix is determined by the ddepth parameter. If ddepth is set to default -1, the depth of output matrix will be the same as the depth of input matrix. The matrices can be single or multi channel. Output matrix must have the same size as src.

Supported matrix data types are CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1.

Note
Function textual ID is "org.opencv.core.math.subC"
Parameters
srcfirst input matrix.
cscalar value to subtracted.
ddepthoptional depth of the output matrix.
See also
add, addC, subRC

§ subRC()

GAPI_EXPORTS GMat cv::gapi::subRC ( const GScalar c,
const GMat src,
int  ddepth = -1 
)

Calculates the per-element difference between given scalar and the matrix.

The function can be replaced with matrix expressions:

\[\texttt{dst} = \texttt{val} - \texttt{src}\]

Depth of the output matrix is determined by the ddepth parameter. If ddepth is set to default -1, the depth of output matrix will be the same as the depth of input matrix. The matrices can be single or multi channel. Output matrix must have the same size as src.

Supported matrix data types are CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1.

Note
Function textual ID is "org.opencv.core.math.subRC"
Parameters
cscalar value to subtract from.
srcinput matrix to be subtracted.
ddepthoptional depth of the output matrix.
See also
add, addC, subC