Skip to content

reduce

Core and matricesfunctionOpenCV 5.0.0
import { reduce } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

ARGUMENTSsrc, dst, dim, rtype
FUNCTIONreduce
RETURN TYPEvoid
Call structure. A void return can still write to destination arguments. The parameter descriptions define inputs, outputs and ownership.

Reduces a matrix to a vector.

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 #REDUCE_MAX and #REDUCE_MIN, the output image should have the same type as the source one. In case of #REDUCE_SUM, #REDUCE_SUM2 and #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.

The following code demonstrates its usage for a single channel matrix.

And the following code demonstrates its usage for a two-channel matrix.

See: repeat, reduceArgMin, reduceArgMax

reduce(src: Mat, dst: Mat, dim: number, rtype: number, dtype: number): void;
2 available overloads
reduce(src: Mat, dst: Mat, dim: number, rtype: number): void;
reduce(src: Mat, dst: Mat, dim: number, rtype: number, dtype: number): void;
src

input 2D matrix.

dst

Output destination, filled by the native operation. output 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.

rtype

reduction operation that could be one of #ReduceTypes

dtype

when negative, the output vector will have the same type as the input matrix, otherwise, its type will be CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), src.channels()).

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.