Ask Your Question

CoReCam's profile - activity

2016-07-20 15:53:23 -0500 received badge  Supporter (source)
2016-07-20 13:07:17 -0500 commented answer Use of Mat in cvAvgSdv gives error

Thanks! That worked great!

I guess my googling and stackoverflow results are turning up examples with combinations of c and c++ code. I suppose most of the code is being migrated to be c++ code?

2016-07-20 12:23:26 -0500 asked a question Use of Mat in cvAvgSdv gives error

I am using VS2015, c++, and openCV 3.1

I am trying to calculate the mean and standard deviation of an image stored in a Mat using the cvAvgSdv function. My code is:

Mat gray_img;
cvtColor(gimage, gray_img, CV_RGB2GRAY);
calcHist(&gray_img, 1, 0, Mat(), hist, 1, &histSize, ranges, true, false);
CvScalar image_mean, image_std_dev;
cvAvgSdv(&gray_img, &image_mean, &image_std_dev, NULL);

This compiles but throws an exception when I run my program (I really wish VS explained more what went wrong versus giving some useless memory address). Why wouldn't this code work?

My work-around has been to convert gray_img to an IplImage with the following:

Mat gray_img;
cvtColor(gimage, gray_img, CV_RGB2GRAY);
calcHist(&gray_img, 1, 0, Mat(), hist, 1, &histSize, ranges, true, false);

// Convert Mat into IplImage so we can run cvAvgSdv without an error
    IplImage* image2;
    image2 = cvCreateImage(cvSize(gray_img.cols, gray_img.rows), 8, 1);
    IplImage ipltemp = gray_img;
    cvCopy(&ipltemp, image2);

CvScalar image_mean, image_std_dev;
cvAvgSdv(&image2, &image_mean, &image_std_dev, NULL);

Any insight would be appreciated!