0
我想读取RGB图像。但是,我只能使用Vec3b类型访问,而不是每个频道。 我相信是什么问题。想帮助我摆脱苦难吗?如何访问RGB图像的每个像素值?
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
...
谢谢!有效。顺便说一下,int(imgMod.at(iter_y,iter_x)[0])和(int)imgMod.at (iter_y,iter_x)[0]之间有什么区别吗? –
2014-09-30 08:17:00
很酷,那么你可以将答案标记为已回答。我不确定会有什么区别。 (更可读和明确的)C++方法是:'static_cast(imgMod.at (iter_y,iter_x)[0])''。 –
2014-09-30 08:34:38
哦,我明白了!再次感谢:) – 2014-10-01 09:12:59