ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

How to get at the rgb values within a pcl::PointXYZRGB cloud

asked 2013-03-12 12:27:55 -0600

MartinW gravatar image

updated 2013-03-13 01:16:43 -0600

Ben_S gravatar image

Hello all,

I am trying write a simple code to segment a red coloured tile on a desk, in rviz I can visualize the point cloud seen by the kinect and I have observed that it's rgb colour ranges from ~2.1810^-38 to ~2.2410^-38. I want to filter this out and find it's position.

So I have a loop on the coloured_cloud to fill the coloured_tile if it finds any points with this specific colour. With my desk rgb value at ~1.8*10^-38, an if-statement should segment the specific colour out and put it into coloured_tile.

double maxVal_RT = pow(2.18,-38.0);
double minVal_RT = pow(2.24,-38.0);

for (size_t l = 0; l < coloured_cloud->points.size(); l++) 
            if(coloured_cloud->points[l].rgb > minVal_RT && coloured_cloud->points[l].rgb < maxVal_RT)

But this doesn't work and when I use ROS_INFO to see what these values it has for minVal_RT and maxVal_RT it says 0.00000 and coloured_cloud->points[l].rgb prints out nans.

It appears that maybe these values are too small to work with the way I am, is there another way to accomplish this? I just want to simply segment out this point cloud of a known, and static, colour.

Kind Regards, Martin

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-03-13 03:12:05 -0600

Which version of the PCL are you using? if i remember it correctly, for PCL >= 1.4, you can directly access the point's r,g,b value by

pcl::PointXYZRGB point;
point.r = red;
point.g = green;
point.b = blue;

where red, green and blue are all uchar ranging from 0 to 255.

edit flag offensive delete link more


I'm running 1.7, but when I use rviz's 'select' to look at points in my region of interest it gives me their .rgb values, is there a way to get them to display the r g b values separately? (I'm referring to the value in the bottom right corner of this image:

MartinW gravatar image MartinW  ( 2013-03-14 07:54:40 -0600 )edit

sorry, i don't know how to show that in rviz

yangyangcv gravatar image yangyangcv  ( 2013-03-14 14:45:01 -0600 )edit

It's ok, I went ahead and just used the .r,.g.,b. values like you suggested. And I believe all you need to do is click the 'Select' tab in the top-left corner of rviz and select a point cloud to bring up that information, in case you wanted to see how the .rgb or xyz values! Thanks again yangyangcv

MartinW gravatar image MartinW  ( 2013-03-15 05:59:38 -0600 )edit

answered 2013-03-13 01:15:22 -0600

Ben_S gravatar image
  • First: 2.18*10^-38 is completely different from 2.18^-38
  • Second: There is no single continuous rgb-value. Its a combination of 3 single indepedent values (red, green, blue) and has to be treated as such.

If you want a continuous indicator of "color", you should convert the rgb-values to something like HSV and use the hue component (together with appropriate saturation and value of course). Read this documentation of the pcl::PointXYZRGB Struct to understand, why they packed rgb into a float and how to access the single rgb-values of the point. (Either by recasting and bit shifting or directly by using the .r, .g, .b accessors)

edit flag offensive delete link more


Ahh, thank you Ben. I was hoping to just get around switching it to a hue, and just do a really quick segmentation of the point cloud based on values that I observed in rviz (referring to my picture in the comment of yangyangcv's answer). Thanks for the answer!

MartinW gravatar image MartinW  ( 2013-03-14 08:01:40 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2013-03-12 12:27:55 -0600

Seen: 12,985 times

Last updated: Mar 13 '13