pub fn reduce_def(
mtx: &impl ToInputArray,
vec: &mut impl ToOutputArray,
dim: i32,
reduce_op: i32,
) -> Result<()>Expand description
Reduces a matrix to a vector.
§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:
- REDUCE_SUM The output is the sum of all rows/columns of the matrix.
- REDUCE_AVG The output is the mean vector of all rows/columns of the matrix.
- REDUCE_MAX The output is the maximum (column/row-wise) of all rows/columns of the matrix.
- 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()) .
- stream: Stream for the asynchronous version.
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_SUM 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.
§See also
reduce
§Note
This alternative version of reduce function uses the following default values for its arguments:
- dtype: -1
- stream: Stream::Null()