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
}
}