void cv::reduce ( InputArray src,
OutputArray dst,
int dim,
int rtype,
int dtype = -1
)
(1)输入为一个矩阵;
(2)输出为一个Mat形式的列向量或者行向量(由dim参数而定,dim=1则矩阵向右投影得到列向量,若dim=0则矩阵向下投影,得到行向量)。
(3)rtype为投影的方式:
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.
Mat lie(img.rows, 1, CV_32SC1);
Mat hang(1, img.cols, CV_32SC1);
reduce(img, lie, 1, CV_REDUCE_SUM,CV_32SC1);
reduce(img, hang, 0, CV_REDUCE_SUM,CV_32SC1);
注意reduce的输入与输出关系:cv::reduce for SUM and 8U input can return only 32S, 32F or 64F types.
就是说输入如果是8U那么输出一定是32S, 32F or 64F其中一个。如果不在dtype设置,那么就默认输出的数据类型与输入类型一致。所以如果要输出32S类型的数据,就要在dtype进行设置!