Cannot Access Mean Values

匿名 (未验证) 提交于 2019-12-03 02:41:02

问题:

I have computed mean and standart deviation values of a region in the image. The code:

Mat img=imread("a.jpg"); Mat hsv1; Mat mean, stdev; cvtColor(img, hsv1, CV_BGR2HSV); cv::meanStdDev(hsv1, mean, stdev, superpixel_mask); cout << "mean: " << mean << endl << "standard deviation: " << stdev << endl;

The output is:

mean: [150.8399251737039;   103.6980224478888;   226.161411010155] standard deviation: [23.98981564590477;   46.73491195049309;   34.41166394765997]

I would like to access those numbers. I wrote that code:

float Mi = mean.at<float>(0,0); cout << Mi << endl;

It gives that error:

OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)si ze.p[0] && (unsigned)(i1*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channel s()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3 ) - 1))*4) & 15) == elemSize1()) in cv::Mat::at, file C:\OpenCV249\opencv\build\ include\opencv2/core/mat.hpp, line 537

回答1:

The problem here is that you're trying to access a CV_64F Mat using at<float>.

You can solve this like:

double Mi = mean.at<double>(0,0);

Or declaring Scalar instead of Mat:

Scalar mean, stdev; cv::meanStdDev(hsv1, mean, stdev, superpixel_mask); double Mi = mean[0]; 


转载请标明出处:Cannot Access Mean Values
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!