 OpenCV  4.7.0-dev Open Source Computer Vision
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...

GOpaque< int > cv::gapi::countNonZero (const GMat &src)
Counts non-zero array elements. 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 type)
Applies a fixed-level threshold to each matrix element. More...

std::tuple< GMat, GScalarcv::gapi::threshold (const GMat &src, const GScalar &maxval, int type)

## ◆ absDiff()

 GMat cv::gapi::absDiff ( const GMat & src1, const GMat & src2 )
Python:
cv.gapi.absDiff(src1, src2) -> retval

#include <opencv2/gapi/core.hpp>

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
 src1 first input matrix. src2 second input matrix.
abs

## ◆ absDiffC()

 GMat cv::gapi::absDiffC ( const GMat & src, const GScalar & c )
Python:
cv.gapi.absDiffC(src, c) -> retval

#include <opencv2/gapi/core.hpp>

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
 src input matrix. c scalar to be subtracted.
min, max

 GMat cv::gapi::addWeighted ( const GMat & src1, double alpha, const GMat & src2, double beta, double gamma, int ddepth = -1 )
Python:
cv.gapi.addWeighted(src1, alpha, src2, beta, gamma[, ddepth]) -> retval

#include <opencv2/gapi/core.hpp>

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
Parameters
 src1 first input matrix. alpha weight of the first matrix elements. src2 second input matrix of the same size and channel number as src1. beta weight of the second matrix elements. gamma scalar added to each sum. ddepth optional depth of the output matrix.

## ◆ countNonZero()

 GOpaque cv::gapi::countNonZero ( const GMat & src )
Python:
cv.gapi.countNonZero(src) -> retval

#include <opencv2/gapi/core.hpp>

Counts non-zero array elements.

The function returns the number of non-zero elements in src :

$\sum _{I: \; \texttt{src} (I) \ne0 } 1$

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

Note
Function textual ID is "org.opencv.core.matrixop.countNonZero"
Parameters
 src input single-channel matrix.
mean, min, max

## ◆ inRange()

 GMat cv::gapi::inRange ( const GMat & src, const GScalar & threshLow, const GScalar & threshUp )
Python:
cv.gapi.inRange(src, threshLow, threshUp) -> retval

#include <opencv2/gapi/core.hpp>

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
 src input matrix (CV_8UC1). threshLow lower boundary value. threshUp upper boundary value.
threshold

## ◆ integral()

 std::tuple cv::gapi::integral ( const GMat & src, int sdepth = -1, int sqdepth = -1 )
Python:
cv.gapi.integral(src[, sdepth[, sqdepth]]) -> retval

#include <opencv2/gapi/core.hpp>

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
 src input image. sdepth desired depth of the integral and the tilted integral images, CV_32S, CV_32F, or CV_64F. sqdepth desired 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 )
Python:
cv.gapi.max(src1, src2) -> retval

#include <opencv2/gapi/core.hpp>

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
 src1 first input matrix. src2 second input matrix of the same size and depth as src1.
min, compare, cmpEQ, cmpGT, cmpGE

## ◆ min()

 GMat cv::gapi::min ( const GMat & src1, const GMat & src2 )
Python:
cv.gapi.min(src1, src2) -> retval

#include <opencv2/gapi/core.hpp>

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
 src1 first input matrix. src2 second input matrix of the same size and depth as src1.
max, cmpEQ, cmpLT, cmpLE

## ◆ normInf()

 GScalar cv::gapi::normInf ( const GMat & src )
Python:
cv.gapi.normInf(src) -> retval

#include <opencv2/gapi/core.hpp>

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
 src input matrix.
normL1, normL2

## ◆ normL1()

 GScalar cv::gapi::normL1 ( const GMat & src )
Python:
cv.gapi.normL1(src) -> retval

#include <opencv2/gapi/core.hpp>

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
 src input matrix.
normL2, normInf

## ◆ normL2()

 GScalar cv::gapi::normL2 ( const GMat & src )
Python:
cv.gapi.normL2(src) -> retval

#include <opencv2/gapi/core.hpp>

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
 src input matrix.
normL1, normInf

## ◆ sum()

 GScalar cv::gapi::sum ( const GMat & src )
Python:
cv.gapi.sum(src) -> retval

#include <opencv2/gapi/core.hpp>

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
 src input matrix.
countNonZero, mean, min, max

## ◆ threshold() [1/2]

 GMat cv::gapi::threshold ( const GMat & src, const GScalar & thresh, const GScalar & maxval, int type )
Python:
cv.gapi.threshold(src, thresh, maxval, type) -> retval
cv.gapi.threshold(src, maxval, type) -> retval

#include <opencv2/gapi/core.hpp>

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 functions 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 types of thresholding supported by the function. They are determined by type 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
 src input matrix (CV_8UC1, CV_8UC3, or CV_32FC1). thresh threshold value. maxval maximum value to use with the cv::THRESH_BINARY and cv::THRESH_BINARY_INV thresholding types. type thresholding type (see the cv::ThresholdTypes).
min, max, cmpGT, cmpLE, cmpGE, cmpLT

## ◆ threshold() [2/2]

 std::tuple cv::gapi::threshold ( const GMat & src, const GScalar & maxval, int type )
Python:
cv.gapi.threshold(src, thresh, maxval, type) -> retval
cv.gapi.threshold(src, maxval, type) -> retval

#include <opencv2/gapi/core.hpp>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function applicable for all threshold types except cv::THRESH_OTSU and cv::THRESH_TRIANGLE

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