# Am I checking for a white pixel correctly?

I am currently going through all the pixels in an image to determine what is a white pixel. I then have to decide where to drive the bot. I am also using sensor_msgs/Image.msg that I get from the /camera/rgb/image_raw channel.

However, I can't seem to locate any white image with the code but the RGBa values I set in my model in gazebo all have value 1 as shown in the image below the code .

I logged all my values(more than once) with ROS_INFO_STREAM but no values are 255, let alone 3 consecutive ones.

void process_image_callback(const sensor_msgs::Image img)
{
const int white_pixel = 255;

const int image_slice_width = img.step / 3;

int j = 0;
bool found = false;

for (int i = 0; not found and i < img.height; i++)
{
for (j; j < img.step-3; j += 3)
{
if (img.data[i*img.step + j] == white_pixel)
{
ROS_INFO_STREAM("img.data[i*img.step + (j + 0)]" + std::to_string(img.data[i*img.step + (j + 0)]));
ROS_INFO_STREAM("img.data[i*img.step + (j + 1)]" + std::to_string(img.data[i*img.step + (j + 1)]));
ROS_INFO_STREAM("img.data[i*img.step + (j + 2)]" + std::to_string(img.data[i*img.step + (j + 2)]));
}
// img.data only has one index
if (img.data[i*img.step +  j     ] == white_pixel and
img.data[i*img.step + (j + 1)] == white_pixel and
img.data[i*img.step + (j + 2)] == white_pixel)
{
found = true;
break;
}
}
ROS_INFO_STREAM("End of j loop");
}

if (found)
{
// go left, forward or right
}
else
{
// no white pixel seen so stop the bot
}
}


• why do you expect a white pixel to have an exact value of 255? May 14 '20 at 0:11
• It has the highest possible value of red, green and blue was my thinking since I set it. Why would it not have that? Oh, I missing the image to show my settings. May 14 '20 at 0:32
• I've worked on this same exercise before and didn't need nested for loops. You could borrow that part from mine and see if any pixels = 255 are found. If yes, then there's an issue with your nested for presumably. Here's my code: github.com/abhishek47kashyap/udacity-robotics-software-engineer/… May 18 '20 at 5:51
• I suggest you require pixel intensities to be above some specified value instead exactly the value. If the RGB values are all 254, is that not close enough? May 22 '20 at 1:06