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