reduce
import { reduce } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
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;srcinput 2D matrix.
dstOutput destination, filled by the native operation. output vector. Its size and type is defined by dim and dtype parameters.
dimdimension 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.
rtypereduction operation that could be one of #ReduceTypes
dtypewhen 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.