我计算了图像中某个区域的平均值和标准偏差值。 代码:
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;
输出结果为:
mean: [150.8399251737039;
103.6980224478888;
226.161411010155]
standard deviation: [23.98981564590477;
46.73491195049309;
34.41166394765997]
我想访问这些数字。 我写了那段代码:
float Mi = mean.at<float>(0,0);
cout << Mi << endl;
它给出了错误:
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
答案 0 :(得分:0)
此处的问题是您尝试使用CV_64F
访问Mat
at<float>
。
你可以解决这个问题:
double Mi = mean.at<double>(0,0);
或声明Scalar
代替Mat
:
Scalar mean, stdev;
cv::meanStdDev(hsv1, mean, stdev, superpixel_mask);
double Mi = mean[0];