First time here? Check out the FAQ!

Ask Your Question
0

Standard Deviation In Array OpenCV c++

asked Oct 19 '15

zms gravatar image

Hello, I had save 5 data inside the array and will require this to be computed for the Std Dev. Does OpenCV has the library for the array calculation? Do I need to follow the C++ coding to do the calculation?

What I had read so far is the Std Deviation for an image or using the GPU to calculate it

Preview: (hide)

1 answer

Sort by » oldest newest most voted
2

answered Oct 19 '15

Preview: (hide)

Comments

Does that library is for the array images? Would the values inside the declared array for eg. float arr1[5], can use this library? Thanks

zms gravatar imagezms (Oct 19 '15)edit

@zms yes you can use this function for calculating the standard deviation of your array. It should work for both cases where you have your data in a matrix or in a vector/array.

theodore gravatar imagetheodore (Oct 19 '15)edit

@theodore@FooBar, I'm not sure wether I'm doing the right method BUT it seems working after few adjustment on the MAT paramaters. Is this the right way? Or shoud I can read from the array and put it into the function? I think it is quite weird Im doing this code yet function.

Scalar mean, stddev;
Mat euc1;

euc1 = (Mat_<float>(1,7) << euc[0], euc[1], euc[2], euc[3],euc[4],euc[5],euc[6]);
std::cout << "euc1 " <<euc1 << std::endl;

meanStdDev ( euc1, mean, stddev );
std::cout << "mean" <<mean << std::endl;
std::cout << "stdev" <<stddev << std::endl;
zms gravatar imagezms (Oct 20 '15)edit

@zms yes that's the correct way to do it. The result is written in the first index of the the Scalar objects. Moreover, as I told you you can pass a vector instead of a Mat. For example:

vector<float> vec = ...; // put some values in your vector
meanStdDev(vec, mean, stddev);
std::cout << "mean" <<mean << std::endl;
std::cout << "stdev" <<stddev << std::endl;
theodore gravatar imagetheodore (Oct 20 '15)edit

Hi Theodore, I tried your method but have some problem. I cannot insert the array values to the new vector vec. Am I doing the right here? Assuming that we have euc[5] five arrays and different values.

vector<float> euc1 = (euc[0], euc[1], euc[2], euc[3],euc[4],euc[5]);

zms gravatar imagezms (Oct 20 '15)edit

try something like this:

vector<float> euc1(euc, euc + sizeof(euc) / sizeof(euc[0]) );
theodore gravatar imagetheodore (Oct 20 '15)edit

ok noted on the suggestion.

zms gravatar imagezms (Oct 20 '15)edit

Question Tools

1 follower

Stats

Asked: Oct 19 '15

Seen: 17,185 times

Last updated: Oct 19 '15