Ask Your Question

# 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

## 1 answer

Sort by » oldest newest most voted
more

## Comments

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

@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@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, euc, euc, euc,euc,euc,euc);
std::cout << "euc1 " <<euc1 << std::endl;

meanStdDev ( euc1, mean, stddev );
std::cout << "mean" <<mean << std::endl;
std::cout << "stdev" <<stddev << std::endl;


@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;


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 five arrays and different values.

vector<float> euc1 = (euc, euc, euc, euc,euc,euc);

try something like this:

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


Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2015-10-19 07:13:10 -0500

Seen: 13,924 times

Last updated: Oct 19 '15