# Standard Deviation In Array OpenCV c++

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

edit retag close merge delete

Sort by ยป oldest newest most voted
more

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

( 2015-10-19 09:11:21 -0500 )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.

( 2015-10-19 09:36:38 -0500 )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;

( 2015-10-20 01:20:16 -0500 )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;

( 2015-10-20 04:51:44 -0500 )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]);

( 2015-10-20 05:48:00 -0500 )edit

try something like this:

vector<float> euc1(euc, euc + sizeof(euc) / sizeof(euc[0]) );

( 2015-10-20 07:21:25 -0500 )edit

ok noted on the suggestion.

( 2015-10-20 07:48:58 -0500 )edit

Official site

GitHub

Wiki

Documentation