[英]Image processing : Mean of line sample
I would like to know the mean
of each columns on my image source. 我想知道图像源中每列的
mean
。 The goal is when the first columns which have a average of 0 (all my pixels are black) a boolean is switch for leave a while
. 目标是当平均为0(我的所有像素均为黑色)的布尔值的第一列切换为
while
。
I do not know if I use a vector
, a Mat
function , Line
or another way. 我不知道是否使用
vector
, Mat
函数, Line
或其他方式。
You can compute the mean (and sum , min , max ) of each column (or row ) in a matrix using reduce 您可以使用reduce来计算矩阵中每一列 (或行 )的平均值 (和sum , min , max )
This is a small example that shows how to compute the mean of each column and each row. 这是一个小示例,显示了如何计算每一列和每一行的平均值。
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
// Create a random 1 channel matrix
Mat1b img(10,20);
randu(img, Scalar(0), Scalar(10));
// Compute the mean of each column
Mat1f colMean;
reduce(img, colMean, 0, CV_REDUCE_AVG, CV_32F);
// colMean is a 1x20 matrix (row matrix)
// Compute the mean of each row
Mat1f rowMean;
reduce(img, rowMean, 1, CV_REDUCE_AVG, CV_32F);
// rowMean is a 10x1 matrix (column matrix)
return 0;
}
Note that to check if values in a column (row) are all zero, you can also use CV_REDUCE_SUM
or CV_REDUCE_MAX
, ie you can sum all pixels or take only the maximum value. 请注意,要检查列(行)中的值是否全部为零,您还可以使用
CV_REDUCE_SUM
或CV_REDUCE_MAX
,即,您可以对所有像素求和或仅取最大值。 In every case, when a column (row) contains only zero values, the result will be zero. 在每种情况下,当列(行)仅包含零值时,结果将为零。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.