每列opencv的总和 [英] Sum of each column opencv

查看:90
本文介绍了每列opencv的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Matlab中,如果A是矩阵,sum(A)会将A的列视为向量,并返回每列总和的行向量.

sum(Image);用OpenCV怎么办?

In Matlab, If A is a matrix, sum(A) treats the columns of A as vectors, returning a row vector of the sums of each column.

sum(Image); How could it be done with OpenCV?

推荐答案

对于8位灰度图像,以下方法应该有效(我认为). 扩展到不同的图像类型应该不太困难.

For an 8 bit greyscale image, the following should work (I think). It shouldn't be too hard to expand to different image types.

int imgStep = image->widthStep;
uchar* imageData = (uchar*)image->imageData;
uint result[image->width];
memset(result, 0, sizeof(uchar) * image->width);
for (int col = 0; col < image->width; col++) {
  for (int row = 0; row < image->height; row++) {
    result[col] += imageData[row * imgStep + col];
  }
}

// your desired vector is in result

这篇关于每列opencv的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆