我有以下代码:

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中一样创建 vector 。请解释。

最佳答案

这里有2个问题:

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

2)您的 vector 最初是空的

您可以使用标量,(预先分配的)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]

关于c++ - meanStdDev函数中的参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30523087/

10-09 03:15