[OpenCV] Java and OpenCV: Calculate Median / Mean / Stdev value of MAT (Gray-Image)

프로그래밍/그 외2018. 4. 19. 22:14

https://stackoverflow.com/questions/22390131/java-and-opencv-calculate-median-mean-stdev-value-of-mat-gray-image


I've got an image as grayscale image using

Mat m = Highgui.imread(path, Highgui.CV_LOAD_IMAGE_GRAYSCALE);

in Java and now I want to calculate the median value, the mean value and the standard deviation. I'n new to this and I simply don't know how to find out the calculations and stuff... Tried 2 hours of googeling, please give me some basic advise on how to do research on this. I tried keywords like "mean value java opencv" and found this:

http://docs.opencv.org/java/2.4.2/org/opencv/core/Core.html#meanStdDev

I'm now doing this:

MatOfDouble mu = new MatOfDouble();
MatOfDouble sigma = new MatOfDouble();
Core.meanStdDev(m, mu, sigma);

But HOW the hell to access the mean/stdev value as a double? Tried things like

double d = mu.get(0,0)

but there's something wrong. I can't find it out by reading the OpenCV Java docs myself unfortunately as I don't know what to look for/at.

I need mean/stdev to calculate the thresholds for the canny filter... Thanks so far in advance



Answer===========


accepted

try this:

double d = mu.get(0,0)[0]

mu.get(0,0) returns a double[], so you can just get the first element - it's equivalent to the C++ version of:

mu.val[0]

Hope it helps.


작성자

Posted by 드리머즈

관련 글

댓글 영역