OpenCV  4.0.1
Open Source Computer Vision
Functions
Graph API: Operations on matrices

Functions

GMat cv::gapi::absDiff (const GMat &src1, const GMat &src2)
 Calculates the per-element absolute difference between two matrices. More...
 
GMat cv::gapi::absDiffC (const GMat &src, const GScalar &c)
 Calculates absolute value of matrix elements. More...
 
GMat cv::gapi::addWeighted (const GMat &src1, double alpha, const GMat &src2, double beta, double gamma, int ddepth=-1)
 Calculates the weighted sum of two matrices. More...
 
GMat cv::gapi::inRange (const GMat &src, const GScalar &threshLow, const GScalar &threshUp)
 Applies a range-level threshold to each matrix element. More...
 
std::tuple< GMat, GMatcv::gapi::integral (const GMat &src, int sdepth=-1, int sqdepth=-1)
 Calculates the integral of an image. More...
 
GMat cv::gapi::max (const GMat &src1, const GMat &src2)
 Calculates per-element maximum of two matrices. More...
 
GMat cv::gapi::min (const GMat &src1, const GMat &src2)
 Calculates per-element minimum of two matrices. More...
 
GScalar cv::gapi::normInf (const GMat &src)
 Calculates the absolute infinite norm of a matrix. More...
 
GScalar cv::gapi::normL1 (const GMat &src)
 Calculates the absolute L1 norm of a matrix. More...
 
GScalar cv::gapi::normL2 (const GMat &src)
 Calculates the absolute L2 norm of a matrix. More...
 
GScalar cv::gapi::sum (const GMat &src)
 Calculates sum of all matrix elements. More...
 
GMat cv::gapi::threshold (const GMat &src, const GScalar &thresh, const GScalar &maxval, int depth)
 Applies a fixed-level threshold to each matrix element. More...
 
std::tuple< GMat, GScalarcv::gapi::threshold (const GMat &src, const GScalar &maxval, int depth)
 

Detailed Description

Function Documentation

§ absDiff()

GMat cv::gapi::absDiff ( const GMat src1,
const GMat src2 
)

Calculates the per-element absolute difference between two matrices.

The function absDiff calculates absolute difference between two matrices of the same size and depth:

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

where I is a multi-dimensional index of matrix elements. In case of multi-channel matrices, each channel is processed independently. Output matrix must have the same size and depth 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.matrixop.absdiff"
Parameters
src1first input matrix.
src2second input matrix.
See also
abs

§ absDiffC()

GMat cv::gapi::absDiffC ( const GMat src,
const GScalar c 
)

Calculates absolute value of matrix elements.

The function abs calculates absolute difference between matrix elements and given scalar value:

\[\texttt{dst}(I) = \texttt{saturate} (| \texttt{src1}(I) - \texttt{matC}(I)|)\]

where matC is constructed from given scalar c and has the same sizes and depth as input matrix src.

Output matrix must be of 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.matrixop.absdiffC"
Parameters
srcinput matrix.
cscalar to be subtracted.
See also
min, max

§ addWeighted()

GMat cv::gapi::addWeighted ( const GMat src1,
double  alpha,
const GMat src2,
double  beta,
double  gamma,
int  ddepth = -1 
)

Calculates the weighted sum of two matrices.

The function addWeighted calculates the weighted sum of two matrices as follows:

\[\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I)* \texttt{alpha} + \texttt{src2} (I)* \texttt{beta} + \texttt{gamma} )\]

where I is a multi-dimensional index of array elements. In case of multi-channel matrices, each channel is processed independently.

The function can be replaced with a matrix expression:

\[\texttt{dst}(I) = \texttt{alpha} * \texttt{src1}(I) - \texttt{beta} * \texttt{src2}(I) + \texttt{gamma} \]

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

Note
Function textual ID is "org.opencv.core.matrixop.addweighted"
Parameters
src1first input matrix.
alphaweight of the first matrix elements.
src2second input matrix of the same size and channel number as src1.
betaweight of the second matrix elements.
gammascalar added to each sum.
ddepthoptional depth of the output matrix.
See also
add, sub

§ inRange()

GMat cv::gapi::inRange ( const GMat src,
const GScalar threshLow,
const GScalar threshUp 
)

Applies a range-level threshold to each matrix element.

The function applies range-level thresholding to a single- or multiple-channel matrix. It sets output pixel value to OxFF if the corresponding pixel value of input matrix is in specified range,or 0 otherwise.

Input and output matrices must be CV_8UC1.

Note
Function textual ID is "org.opencv.core.matrixop.inRange"
Parameters
srcinput matrix (CV_8UC1).
threshLowlower boundary value.
threshUpupper boundary value.
See also
threshold

§ integral()

std::tuple<GMat, GMat> cv::gapi::integral ( const GMat src,
int  sdepth = -1,
int  sqdepth = -1 
)

Calculates the integral of an image.

The function calculates one or more integral images for the source image as follows:

\[\texttt{sum} (X,Y) = \sum _{x<X,y<Y} \texttt{image} (x,y)\]

\[\texttt{sqsum} (X,Y) = \sum _{x<X,y<Y} \texttt{image} (x,y)^2\]

The function return integral image as \((W+1)\times (H+1)\) , 32-bit integer or floating-point (32f or 64f) and integral image for squared pixel values; it is \((W+1)\times (H+)\), double-precision floating-point (64f) array.

Note
Function textual ID is "org.opencv.core.matrixop.integral"
Parameters
srcinput image.
sdepthdesired depth of the integral and the tilted integral images, CV_32S, CV_32F, or CV_64F.
sqdepthdesired depth of the integral image of squared pixel values, CV_32F or CV_64F.

§ max()

GMat cv::gapi::max ( const GMat src1,
const GMat src2 
)

Calculates per-element maximum of two matrices.

The function max calculates the per-element maximum of two matrices of the same size, number of channels and depth:

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

where I is a multi-dimensional index of matrix elements. In case of multi-channel matrices, each channel is processed independently. Output matrix must be of the same size and depth as src1.

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

Note
Function textual ID is "org.opencv.core.matrixop.max"
Parameters
src1first input matrix.
src2second input matrix of the same size and depth as src1.
See also
min, compare, compareEqual, compareGreater, compareGreaterEqual

§ min()

GMat cv::gapi::min ( const GMat src1,
const GMat src2 
)

Calculates per-element minimum of two matrices.

The function min calculates the per-element minimum of two matrices of the same size, number of channels and depth:

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

where I is a multi-dimensional index of matrix elements. In case of multi-channel matrices, each channel is processed independently. Output matrix must be of the same size and depth as src1.

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

Note
Function textual ID is "org.opencv.core.matrixop.min"
Parameters
src1first input matrix.
src2second input matrix of the same size and depth as src1.
See also
max, compareEqual, compareLess, compareLessEqual

§ normInf()

GScalar cv::gapi::normInf ( const GMat src)

Calculates the absolute infinite norm of a matrix.

This version of normInf calculates the absolute infinite norm of src.

As example for one array consider the function \(r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\). The \( L_{\infty} \) norm for the sample value \(r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\) is calculated as follows

\begin{align*} \| r(-1) \|_{L_\infty} &= \max(|-1|,|2|) = 2 \end{align*}

and for \(r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\) the calculation is

\begin{align*} \| r(0.5) \|_{L_\infty} &= \max(|0.5|,|0.5|) = 0.5. \end{align*}

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

Note
Function textual ID is "org.opencv.core.matrixop.norminf"
Parameters
srcinput matrix.
See also
normL1, normL2

§ normL1()

GScalar cv::gapi::normL1 ( const GMat src)

Calculates the absolute L1 norm of a matrix.

This version of normL1 calculates the absolute L1 norm of src.

As example for one array consider the function \(r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\). The \( L_{1} \) norm for the sample value \(r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\) is calculated as follows

\begin{align*} \| r(-1) \|_{L_1} &= |-1| + |2| = 3 \\ \end{align*}

and for \(r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\) the calculation is

\begin{align*} \| r(0.5) \|_{L_1} &= |0.5| + |0.5| = 1 \\ \end{align*}

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

Note
Function textual ID is "org.opencv.core.matrixop.norml1"
Parameters
srcinput matrix.
See also
normL2, normInf

§ normL2()

GScalar cv::gapi::normL2 ( const GMat src)

Calculates the absolute L2 norm of a matrix.

This version of normL2 calculates the absolute L2 norm of src.

As example for one array consider the function \(r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\). The \( L_{2} \) norm for the sample value \(r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\) is calculated as follows

\begin{align*} \| r(-1) \|_{L_2} &= \sqrt{(-1)^{2} + (2)^{2}} = \sqrt{5} \\ \end{align*}

and for \(r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\) the calculation is

\begin{align*} \| r(0.5) \|_{L_2} &= \sqrt{(0.5)^{2} + (0.5)^{2}} = \sqrt{0.5} \\ \end{align*}

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

Note
Function textual ID is "org.opencv.core.matrixop.norml2"
Parameters
srcinput matrix.
See also
normL1, normInf

§ sum()

GScalar cv::gapi::sum ( const GMat src)

Calculates sum of all matrix elements.

The function sum calculates sum of all matrix elements, independently for each channel.

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

Note
Function textual ID is "org.opencv.core.matrixop.sum"
Parameters
srcinput matrix.
See also
min, max

§ threshold() [1/2]

GMat cv::gapi::threshold ( const GMat src,
const GScalar thresh,
const GScalar maxval,
int  depth 
)

Applies a fixed-level threshold to each matrix element.

The function applies fixed-level thresholding to a single- or multiple-channel matrix. The function is typically used to get a bi-level (binary) image out of a grayscale image ( cmp funtions could be also used for this purpose) or for removing a noise, that is, filtering out pixels with too small or too large values. There are several depths of thresholding supported by the function. They are determined by depth parameter.

Also, the special values cv::THRESH_OTSU or cv::THRESH_TRIANGLE may be combined with one of the above values. In these cases, the function determines the optimal threshold value using the Otsu's or Triangle algorithm and uses it instead of the specified thresh . The function returns the computed threshold value in addititon to thresholded matrix. The Otsu's and Triangle methods are implemented only for 8-bit matrices.

Input image should be single channel only in case of cv::THRESH_OTSU or cv::THRESH_TRIANGLE flags. Output matrix must be of the same size and depth as src.

Note
Function textual ID is "org.opencv.core.matrixop.threshold"
Parameters
srcinput matrix (CV_8UC1, CV_8UC3, or CV_32FC1).
threshthreshold value.
maxvalmaximum value to use with the cv::THRESH_BINARY and cv::THRESH_BINARY_INV thresholding depths.
depththresholding depth (see the cv::ThresholdTypes).
See also
min, max, cmpGT, cmpLE, cmpGE, cmpLS

§ threshold() [2/2]

std::tuple<GMat, GScalar> cv::gapi::threshold ( const GMat src,
const GScalar maxval,
int  depth 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function appicable for all threshold depths except CV_THRESH_OTSU and CV_THRESH_TRIANGLE

Note
Function textual ID is "org.opencv.core.matrixop.thresholdOT"