first white pixel in binary image
How to find first white pixel in binary image with opencv c++???
How to find first white pixel in binary image with opencv c++???
The simple way is:
for (int row=0;row<image.height;row++)
{
for (int col=0;col<image.width;col++)
{
if(image.at<uchar>(i,j) != 0)//do what you want;
}
}
that pixel access isn't the fastest,,, if you need more speed:
for (int row=0;row<image.height;row++)
{
unsigned char data = image.ptr(row);
for (int col=0;col<image.width;col++)
{
// then use *data for the pixel value
if(*data==1)//do what you want;
data++;
}
}
In addition to this nice answer, I would like to point out the documents page that discusses the internal image structure and show different ways of accessing it's data. Look here!
Asked: Aug 13 '13
Seen: 3,443 times
Last updated: Aug 14 '13
Create two nested for-loops, one that goes from 0 to width and the other one from 0 to height (change the order if necessary, first loop should have the smaller side). Then you can check if the pixel is white with: if (image.at<uchar>(i,j) != 0 ) This is not the fastest way though, since .at might be quite slow.
@Moster: don't hesitate to write your comments as answers :)
Yes, you are right, since I could format the code then