I am trying to average the pixel value of an image across a circular region of interest. I am trying to use cvAvgSdv
and it returns a sensible mean, but zero standard deviation. I also try cvCountNonZero
which also returns zero. Must be a basic mistake I am making but hope someone can point it out. The roi.png looks correct (a white spot in the correct place on a black background). My full code is below (VS C++ 2010 Express, Opencv245):
#include <opencv/cv.h>
#include <opencv2/highgui/highgui.hpp>
#include <stdio.h>
int main( int argc, char** argv )
{
IplImage* src;
if( argc >= 2 && (src=cvLoadImage(argv[1], 0))!= 0)
{
IplImage * roi;
roi = cvCreateImage(cvGetSize(src), 8, 1);
int n;
int centre_x = 396, centre_y = 317;
CvScalar pixel_mean, pixel_stdev;
cvZero(roi);
cvCircle(
roi,
cvPoint(centre_x, centre_y),
15, //radius<<<<<<<<<<<<<<<<<<<<<<<<<<<
cvScalar(255),
-1, 8, 0
);
cvAvgSdv(src, &pixel_mean, &pixel_stdev, roi);
n = cvCountNonZero(roi);
printf
(
"center x: %d y: %d A: %d B: %d av: %f stdev: %f n: %d\n",
centre_x,
centre_y,
15,
15,
pixel_mean, //new
pixel_stdev, //new
n //new
);
cvSaveImage("roi.png", roi, 0);
}
}
Thanks