我正在试着读RGB图像。但是,我只能使用Vec3b类型访问,而不是每个通道。我知道问题出在哪里。想帮我摆脱痛苦吗?
imgMod = imread("rgb.png");
for (int iter_x = 0; iter_x < imgMod.cols; ++iter_x)
{
for (int iter_y = 0; iter_y < imgMod.rows; ++iter_y)
{
cout << imgMod.at<cv::Vec3b>(iter_y, iter_x) << "\t";
cout << imgMod.at<cv::Vec3b>(iter_y, iter_x)[0] << "\t";
cout << imgMod.at<cv::Vec3b>(iter_y, iter_x)[1] << "\t";
cout << imgMod.at<cv::Vec3b>(iter_y, iter_x)[2] << endl;
}
}以下是RGB图像像素值的结果。
[153, 88, 81] X Q
[161, 94, 85] 。 ^ T
...发布于 2014-09-30 06:42:57
你的权限很好。
[]运算符返回的类型是char,因此该值被打印为char --一个文本字符。只需将其转换为int,将灰色值视为整数:
cout << int(imgMod.at<cv::Vec3b>(iter_y, iter_x)[0]) << "\t";一种(更易读和更显式的) C++方法是:
static_cast<int>(imgMod.at<cv::Vec3b>(iter_y, iter_x)[0]) << "\t";更酷的是这个(晦涩?)小把戏 -注意+
cout << +imgMod.at<cv::Vec3b>(iter_y, iter_x)[0] << "\t";
// ^https://stackoverflow.com/questions/26114053
复制相似问题