meanStdDev seems to have a bug? Or am I using it wrong?
When I use meanStdDev for an array with more than a million elements (m = 1228800x1 matrix, by reshaping a single channel 1280x960 image), I seem to get an overflow or something like that.
Code snippet:
m=cvarrToMat(img, true);
m=m.reshape(0,1); //makes m a 1228800x1 matrix
m.copyTo(m1);
meanStdDev(m1, meanframe1, stdframe1);
If I use a 128x96 matrix as an input, I get values like meanframe(0)=3067.9 stdframe1(0)=107.072 which seem to be correct for a dark frame from a cmos camera.
But if I use a 1280x960 image as input under the same conditions, I get meanframe(0)=-454.69 stdframe1(0)=14832.8 which is absolutely wrong - negative number for mean!
Additional info:
meanframe1=mean(m1);
gives the correct answer even for large matrices. So, meanStdDev along seems to be the culprit....
More additional info:
my own code for StdDev also gives correct results,
meanframe1=mean(m1);
double dstddev = 0.0;
double dmean = meanframe1(0); // only one channel
for (int i = 0; i < w*h; i++)
{
dstddev += (dmean - m1.at<ushort>(i)) * (dmean - m1.at<ushort>(i));
}
dstddev = sqrt(dstddev / (w*h));
std::cout<<"mean="<<meanframe1(0)<<std::endl;
std::cout<<"stddev="<<dstddev<<std::endl;
"I use meanStdDev for an unsigned int array" -- not supported from opencv. also, using cvarrToMat raises a red flag here. show us, how you construct that, please !
cvarrToMat, from https://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#Mat%20cvarrToMat
That part is fine, I use
and after that,
you should NOT use anything like that, from the (since 2010) deprecated C-api.
but this does not explain: "I use meanStdDev for an unsigned int array". (again, only signed ints are supported, and it's entirely unclear, where your data comes from)
Sorry for the confusion. My data comes from a QHY camera. (The deprecated code is from a QHY sample :) The code for getting the data is as follows.
That populates ImgData, in my case since I have used the camera in 16bit mode, with unsigned 16 bit numbers.
Have edited my question to remove the "unsigned int" from the array, since that may be incorrect :)