Reputation: 2401
This snippet of code prints out garbage values.
cv::Mat_<cv::vec3b>::iterator it = img.begin<cv::vec3b>(),
itEnd = img.end<cv::vec3b>();
for(; it != itEnd; ++it)
std::cout << (*it)[1] << std::endl;
But this prints out the vector of RGB values.
std::cout << img.at(100,200);
The moment I try to access the individual RGB values I get garbage values printed,
Any reason why this might be happening?
Upvotes: 0
Views: 195
Reputation: 1420
I'm not sure about OpenCV but if each of your element in vector is of format say [221,123,321], then individually splitting string based on ',' seperator you can retrieve individual pixel values.
What i understand is this:
#include<sstream>
string buf;
cout<<"Printing elements:"<<endl;
for(unsigned i=0;i<img.size();i++)
{
istringstream is(img[i]);
while(getline(is, buf, ','))
{
if(buf.at(0)=='[')
{
buf.erase(0, 1);
}
if(buf.at(buf.length()-1)==']')
{
buf.erase(buf.length()-1, buf.length());
}
cout<<buf<<endl;
}
}
OUTPUT
Printing elements:
221
123
321
...
...
Upvotes: 1