meanStdDev函数中的参数

时间:2015-05-29 06:57:49

标签: c++ opencv

我有以下代码:

Scalar m;   //Scalar is a class for a 4 variable vector. m is its instance.        
Scalar std;
meanStdDev(hist, m, std);

效果很好,但对以下内容无效。

vector < float > m;
vector < float > std;
meanStdDev(hist, m, std);

我无法理解这个问题,因为我也在创建一个向量,就像Scalar一样。请解释一下。

1 个答案:

答案 0 :(得分:5)

这里有两个问题:

1)它需要具有固定大小的东西。

2)你的矢量最初是空的

你可以使用标量,(预先分配)Mat或Vec4d,但 std :: vector。

Mat hist(10,1,CV_32F);
randu(hist,1,100);

cerr << hist << endl;

{
    Scalar m, stdv;

    meanStdDev(hist, m, stdv);
    cerr << m << " " << stdv << endl;
}

{
    Mat m(1,4,CV_64F),stdv(1,4,CV_64F);

    meanStdDev(hist, m, stdv);
    cerr << m << " " << stdv << endl;
}

{
    Vec4d m,stdv;

    meanStdDev(hist, m, stdv);
    cerr << m << " " << stdv << endl;
}


[53.497997;
 20.72666;
 40.704884;
 81.624123;
 44.276165;
 25.63018;
 77.537399;
 76.447281;
 31.471653;
 70.540741]
[52.2457, 0, 0, 0] [21.8056, 0, 0, 0]
[52.245703125] [21.80564409388921]
[52.2457, 0, 0, 0] [21.8056, 0, 0, 0]