无法访问平均值
Cannot Access Mean Values
我计算了图像中某个区域的均值和标准差值。
代码:
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
这里的问题是您正在尝试使用 at<float>
.
访问 CV_64F
Mat
你可以这样解决:
double Mi = mean.at<double>(0,0);
或声明 Scalar
而不是 Mat
:
Scalar mean, stdev;
cv::meanStdDev(hsv1, mean, stdev, superpixel_mask);
double Mi = mean[0];
我计算了图像中某个区域的均值和标准差值。 代码:
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
这里的问题是您正在尝试使用 at<float>
.
CV_64F
Mat
你可以这样解决:
double Mi = mean.at<double>(0,0);
或声明 Scalar
而不是 Mat
:
Scalar mean, stdev;
cv::meanStdDev(hsv1, mean, stdev, superpixel_mask);
double Mi = mean[0];