# calculate intensity for region of interest hi. good time.I have a gray scale image with a bounding box in it.I want to calculate intensity for bounding box.the resolution of my picture is 720*750 and my rectangle is: rectangle(400,210,70,50).do you have any idea to calculate the intensity for this region of my image?Thanks a lot for you're help.

edit retag close merge delete

Sort by » oldest newest most voted

you can use cv::mean() for this:

Mat image = ....
Mat roi( image, Rect(400,210,70,50) );
Scalar m = mean(roi);

more

Thank for you're answer.I'am beginner in opencv.when I cout m,return me 4 number in [] that Three last is zero .what is this number?

since you use a grayscale image (which has only 1 channel), the 1st number holds the mean inntensity of your ROI. so you could use:

uchar intensity = m;


for a color image, you would get 3 numbers, if it also has alpha, all 4 numbers in the Scalar are filled.

Heartiest congratulations.Exactly what I want.if I want to compare the mean intensity of 2 ROI's,When I do this:  Mat roi(frame, Rect(405, 210, 70, 50)); Scalar m = mean(roi); Mat roi2(frame, Rect(365, 185, 150, 100)); Scalar M = mean(roi2); if (mean (roi) > mean (roi2)) cout << "louis89" << endl; my code can't bulid because of sign <.but for == or != it work.why?

there is no > operator for cv::Scalar. but again, since you have grayscale image (need only a single number) you could simply write:

if ( mean(roi1) > mean(roi2) )

1

Official site

GitHub

Wiki

Documentation