Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameters in meanStdDev function

Tags:

c++

opencv

I have the following code:

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

It works well but it doesn't work for the following.

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

I am not able to understand the problem as here also I am creating a vector just like in the case of Scalar. Please explain.

like image 581
Navdeep Avatar asked Nov 04 '25 07:11

Navdeep


1 Answers

2 problems here:

1) it needs something with a fixed size.

2) your vectors are initially empty

you can use a Scalar, a (pre-allocated) Mat, or a Vec4d, but not a 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]
like image 65
berak Avatar answered Nov 06 '25 02:11

berak