Opencv Matrix元素的列总和 [英] Column sum of Opencv Matrix elements
本文介绍了Opencv Matrix元素的列总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要分别计算所有列中的元素总和.
I need to compute sum of elements in all columns separately.
现在我正在使用:
应该将矩阵cross_corr相加.
Matrix cross_corr should be summed.
Mat cross_corr_summed;
for (int i=0;i<cross_corr.cols;i++)
{
double column_sum=0;
for (int k=0;k<cross_corr.rows;k++)
{
column_sum +=cross_corr.at<float>(k,i);
}
cross_corr_summed.push_back(column_sum);
}
问题是我的程序需要很长时间才能运行.这是可疑的部分之一. 您能建议任何可能更快的实施方式吗?
The problem is that my program takes quite a long time to run. This is one of parts that is suspicious to cause this. Can you advise any possible faster implementation???
谢谢!
推荐答案
您需要 cv: :reduce :
cv::reduce(cross_corr, cross_corr_summed, 0, CV_REDUCE_SUM, CV_32S);
这篇关于Opencv Matrix元素的列总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文