关于opencv里reduce函数解释

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进行设置!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值