Ask Your Question
0

OpenCV JavaScript - meanStdDev

asked 2019-01-16 03:28:19 -0600

robertral gravatar image

I'm having a hard time trying understand how to extract the Mean and Stddev from the function cv.meanStdDev in the JS version of OpenCV.

I've tried the following JS code, but I'm struggling with how to get the Mean and Stddev from the meanStdDev function:

let myMean = new cv.Mat(1,4,cv.CV_64F);
let myStddev = new cv.Mat(1,4,cv.CV_64F);
cv.meanStdDev(img, myMean, myStddev);

I can't seem to find any documentation about this function on the site https://docs.opencv.org/3.4/d5/d10/tu...

Thanks in advance for any help.

edit retag flag offensive close merge delete

Comments

are there any errors ? where is the actual problem, now ?

berak gravatar imageberak ( 2019-01-16 03:33:55 -0600 )edit
1

The problem is I'm not sure how to get the scalar value for the Mean or Stddev from this function. I've tried various ways, with the latest being: let stddev = myStddev.data[0];

But I'm not sure that the numbers are correct, or even if this is the correct approach at computing the Mean and Stddev of an image (img in this example).

Thanks

robertral gravatar imagerobertral ( 2019-01-16 03:38:48 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2019-01-16 06:15:14 -0600

berak gravatar image

updated 2019-01-16 06:15:53 -0600

you're close !

mat.data is unfortunately the uchar data pointer, you need to access the Mat with double, like:

console.log(myMean.doubleAt(0,0))

try with an all red image, you should get 255, 0, 0, 255 for the mean and all 0 for the stdev.

edit flag offensive delete link more

Comments

1

Thanks, this works for me now. I've read the documentation again and I can see it being mentioned but was hard to find (probably my level of JS coding prevented me from seeing it first time). Tthanks for your help @berak

robertral gravatar imagerobertral ( 2019-01-16 08:24:04 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-01-16 03:28:19 -0600

Seen: 1,319 times

Last updated: Jan 16 '19