我在尝试计算之前尝试获取像素值。当我在loc(10,10)运行以下代码时,我得到以下答案。我不确定为什么颜色值与其他颜色不同。当对于loc(0,0)做同样的事情时,我会得到相同的答案。图像是黑白的,有3个通道。或者,对于3个频道,我应该总是使用Vec3b吗?
char imageName[] = "0001.png";
cv::Mat img = cv::imread(imageName);
cout << "Image rows is: " << img.rows << " cols is : " << img.cols << endl;
cout << "Image channels " << img.channels() << endl;
cout << "Image depth " << img.depth() << endl; //CV_8U == 0
cout << (int)img.at<uchar>(10, 10) << endl;
cout << (int)img.ptr(10)[10] << endl;
Scalar intensity = img.at<uchar>(10, 10);
cout << intensity << endl;
Vec3b color = img.at<Vec3b>(10, 10);
cout << color << endl;
输出:
图像行是:96列是:72
图片频道3
图像深度0
103
103
[103,0,0,0]
[164,164,164]