Ask Your Question
0

Standard Deviation In Array OpenCV c++

asked 2015-10-19 07:13:10 -0600

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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-10-19 07:28:07 -0600

edit flag offensive delete link more

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 ( 2015-10-19 09:11:21 -0600 )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 ( 2015-10-19 09:36:38 -0600 )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 ( 2015-10-20 01:20:16 -0600 )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 ( 2015-10-20 04:51:44 -0600 )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 ( 2015-10-20 05:48:00 -0600 )edit

try something like this:

vector<float> euc1(euc, euc + sizeof(euc) / sizeof(euc[0]) );
theodore gravatar imagetheodore ( 2015-10-20 07:21:25 -0600 )edit

ok noted on the suggestion.

zms gravatar imagezms ( 2015-10-20 07:48:58 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 16,926 times

Last updated: Oct 19 '15