1
$\begingroup$

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

gazebo RGBA settings

$\endgroup$
4
  • $\begingroup$ why do you expect a white pixel to have an exact value of 255? $\endgroup$
    – jsotola
    May 14 '20 at 0:11
  • $\begingroup$ 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. $\endgroup$ May 14 '20 at 0:32
  • $\begingroup$ 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/… $\endgroup$ May 18 '20 at 5:51
  • $\begingroup$ 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? $\endgroup$
    – Ralff
    May 22 '20 at 1:06
2
$\begingroup$

You said:

the RGBa values I set in my model in gazebo all have value 1

and you also said:

but no values are 255

Which I would expect is correct, because you just said you set them all to 1. Did you mean to scale them from 1 to 255 at some point? Casting 1.0 from float to uint8 will give you 1, not 255.

$\endgroup$
1
$\begingroup$

It looks like there might be a bug in your code as pointed to by @MorganStark47 above in the comment

You may also want to use Gazebo/White as the material versus Gazebo/Grey to get the full brightness. I think the settings your adjusting effect how it interacts with different light sources and may not fully override the texture which a grey will take off some of the brightness.

There's a list here: http://wiki.ros.org/simulator_gazebo/Tutorials/ListOfMaterials

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.