### Navigation

- index
- next |
- previous |
- OpenCV 2.4.12.3 documentation »
- OpenCV API Reference »
- gpu. GPU-accelerated Computer Vision »

# Matrix Reductions

## gpu::meanStdDev

Computes a mean value and a standard deviation of matrix elements.

C++:`` void `gpu::``meanStdDev`(const GpuMat& mtx, Scalar& mean, Scalar& stddev)

C++:`` void `gpu::``meanStdDev`(const GpuMat& mtx, Scalar& mean, Scalar& stddev, GpuMat& buf)

  Parameters: | mtx – Source matrix. `CV_8UC1` matrices are supported for now. mean – Mean value. stddev – Standard deviation value. buf – Optional buffer to avoid extra memory allocations. It is resized automatically.

See also

`meanStdDev()`

## gpu::norm

Returns the norm of a matrix (or difference of two matrices).

C++:`` double `gpu::``norm`(const GpuMat& src1, int normType=NORM_L2)

C++:`` double `gpu::``norm`(const GpuMat& src1, int normType, GpuMat& buf)

C++:`` double `gpu::``norm`(const GpuMat& src1, int normType, const GpuMat& mask, GpuMat& buf)

C++:`` double `gpu::``norm`(const GpuMat& src1, const GpuMat& src2, int normType=NORM_L2)

  Parameters: | src1 – Source matrix. Any matrices except 64F are supported. src2 – Second source matrix (if any) with the same size and type as `src1`. normType – Norm type. `NORM_L1` , `NORM_L2` , and `NORM_INF` are supported for now. mask – optional operation mask; it must have the same size as `src1` and `CV_8UC1` type. buf – Optional buffer to avoid extra memory allocations. It is resized automatically.

See also

`norm()`

## gpu::sum

Returns the sum of matrix elements.

C++:`` Scalar `gpu::``sum`(const GpuMat& src)

C++:`` Scalar `gpu::``sum`(const GpuMat& src, GpuMat& buf)

C++:`` Scalar `gpu::``sum`(const GpuMat& src, const GpuMat& mask, GpuMat& buf)

  Parameters: | src – Source image of any depth except for `CV_64F` . mask – optional operation mask; it must have the same size as `src1` and `CV_8UC1` type. buf – Optional buffer to avoid extra memory allocations. It is resized automatically.

See also

`sum()`

## gpu::absSum

Returns the sum of absolute values for matrix elements.

C++:`` Scalar `gpu::``absSum`(const GpuMat& src)

C++:`` Scalar `gpu::``absSum`(const GpuMat& src, GpuMat& buf)

C++:`` Scalar `gpu::``absSum`(const GpuMat& src, const GpuMat& mask, GpuMat& buf)

  Parameters: | src – Source image of any depth except for `CV_64F` . mask – optional operation mask; it must have the same size as `src1` and `CV_8UC1` type. buf – Optional buffer to avoid extra memory allocations. It is resized automatically.

## gpu::sqrSum

Returns the squared sum of matrix elements.

C++:`` Scalar `gpu::``sqrSum`(const GpuMat& src)

C++:`` Scalar `gpu::``sqrSum`(const GpuMat& src, GpuMat& buf)

C++:`` Scalar `gpu::``sqrSum`(const GpuMat& src, const GpuMat& mask, GpuMat& buf)

  Parameters: | src – Source image of any depth except for `CV_64F` . mask – optional operation mask; it must have the same size as `src1` and `CV_8UC1` type. buf – Optional buffer to avoid extra memory allocations. It is resized automatically.

## gpu::minMax

Finds global minimum and maximum matrix elements and returns their values.

C++:`` void `gpu::``minMax`(const GpuMat& src, double* minVal, double* maxVal=0, const GpuMat& mask=GpuMat())

C++:`` void `gpu::``minMax`(const GpuMat& src, double* minVal, double* maxVal, const GpuMat& mask, GpuMat& buf)

  Parameters: | src – Single-channel source image. minVal – Pointer to the returned minimum value. Use `NULL` if not required. maxVal – Pointer to the returned maximum value. Use `NULL` if not required. mask – Optional mask to select a sub-matrix. buf – Optional buffer to avoid extra memory allocations. It is resized automatically.

The function does not work with `CV_64F` images on GPUs with the compute capability < 1.3.

See also

`minMaxLoc()`

## gpu::minMaxLoc

Finds global minimum and maximum matrix elements and returns their values with locations.

C++:`` void `gpu::``minMaxLoc`(const GpuMat& src, double* minVal, double* maxVal=0, Point* minLoc=0, Point* maxLoc=0, const GpuMat& mask=GpuMat())

C++:`` void `gpu::``minMaxLoc`(const GpuMat& src, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc, const GpuMat& mask, GpuMat& valbuf, GpuMat& locbuf)

  Parameters: | src – Single-channel source image. minVal – Pointer to the returned minimum value. Use `NULL` if not required. maxVal – Pointer to the returned maximum value. Use `NULL` if not required. minLoc – Pointer to the returned minimum location. Use `NULL` if not required. maxLoc – Pointer to the returned maximum location. Use `NULL` if not required. mask – Optional mask to select a sub-matrix. valbuf – Optional values buffer to avoid extra memory allocations. It is resized automatically. locbuf – Optional locations buffer to avoid extra memory allocations. It is resized automatically.

  The function does not work with `CV_64F` images on GPU with the compute capability < 1.3.

See also

`minMaxLoc()`

## gpu::countNonZero

Counts non-zero matrix elements.

C++:`` int `gpu::``countNonZero`(const GpuMat& src)

C++:`` int `gpu::``countNonZero`(const GpuMat& src, GpuMat& buf)

  Parameters: | src – Single-channel source image. buf – Optional buffer to avoid extra memory allocations. It is resized automatically.

The function does not work with `CV_64F` images on GPUs with the compute capability < 1.3.

See also

`countNonZero()`

## gpu::reduce

Reduces a matrix to a vector.

C++:`` void `gpu::``reduce`(const GpuMat& mtx, GpuMat& vec, int dim, int reduceOp, int dtype=-1, Stream& stream=Stream::Null())

  Parameters: | mtx – Source 2D matrix. vec – Destination vector. Its size and type is defined by `dim` and `dtype` parameters. dim – Dimension index along which the matrix is reduced. 0 means that the matrix is reduced to a single row. 1 means that the matrix is reduced to a single column. reduceOp – Reduction operation that could be one of the following: CV_REDUCE_SUM The output is the sum of all rows/columns of the matrix. CV_REDUCE_AVG The output is the mean vector of all rows/columns of the matrix. CV_REDUCE_MAX The output is the maximum (column/row-wise) of all rows/columns of the matrix. CV_REDUCE_MIN The output is the minimum (column/row-wise) of all rows/columns of the matrix. dtype – When it is negative, the destination vector will have the same type as the source matrix. Otherwise, its type will be `CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), mtx.channels())` .

The function `reduce` reduces the matrix to a vector by treating the matrix rows/columns as a set of 1D vectors and performing the specified operation on the vectors until a single row/column is obtained. For example, the function can be used to compute horizontal and vertical projections of a raster image. In case of `CV_REDUCE_SUM` and `CV_REDUCE_AVG` , the output may have a larger element bit-depth to preserve accuracy. And multi-channel arrays are also supported in these two reduction modes.

See also

`reduce()`

## Help and Feedback

You did not find what you were looking for?

- Ask a question on the Q&A forum.
- If you think something is missing or wrong in the documentation, please file a bug report.

### Navigation

- index
- next |
- previous |
- OpenCV 2.4.12.3 documentation »
- OpenCV API Reference »
- gpu. GPU-accelerated Computer Vision »