A PCL point cloud curiosity [closed]

asked 2012-06-18 03:55:43 -0500

kameleon gravatar image

updated 2012-06-19 22:57:44 -0500

I had a recent question about getting certain points from a pointcloud, and user Dan Lazewatsky explained how my approach was wrong, and that in fact, you can't fetch a point by it's index and be sure that it is always the same point in the same position. I was advised to use the depth image instead where such a thing would be possible, but in the end, I didn't even need to.

What I'm doing is a simple obstacle detection for a mobile robot, and I needed to find if there are any points (obstacles, that is) in the section of space right in front of the robot, on it's left, and on it's right, and now, i finally managed to do it, but I did it by taking the original pointcloud, iterating through the points vector, and if I detect a point that belongs in one of those portions of space, I have to place it in it's own cloud, and then check if the clouds are empty or not. Just checking if the point is in one of those portions in the original cloud and changing indicator variables accordingly gives wrong readings.

When I tried to visualize it and see what's going on, I first colored all points with Z less than 1 meter in red (z seems to get me the precise distance from the sensor), and the rest of them white. When there was nothing in the range of 1m of the camera, everything was white as expected, but when an object got in range, it would be colored red and white in a zebra pattern along with the far away objects (!). I got it working now, but only by putting the points that get in range in a new empty cloud for each portion of space.

It works now, but I'd really like to know what is causing this problem. It's almost like the cloud is changing while I'm iterating through the points and coloring them, and I know that isn't possible. The function recieved a cloud and did like so:

  • Iterate through points
  • if point has z < 1, color it red
  • else, color it white
  • display the cloud
  • return to main and allow the node to fetch a brand new cloud

Thanks in advance

P.S. here is the complete function that I used back then:

void display(pcl::PointCloud<pcl::PointXYZ> cloudPCL)
const pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloudPCLRGBA (new     pcl::PointCloud<pcl::PointXYZRGBA>);

pcl::PointXYZRGBA newpoint;
pcl::PointCloud<pcl::PointXYZ>::iterator b1;
pcl::visualization::CloudViewer viewer ("CloudViewer");

 int white = ((int)255) << 16 | ((int)255) << 8 | ((int)255);
 int red = ((int)255) << 16 | ((int)0) << 8 | ((int)0);

cloudPCLRGBA->width = cloudPCL.width;
cloudPCLRGBA->height = cloudPCL.height;

for (b1 = cloudPCL.points.begin(); b1 < cloudPCL.points.end(); b1++, b2++)
    newpoint.x = b1->x;
    newpoint.y = b1->y;
    newpoint.z = b1->z;

    if (newpoint.z < Z_THRESH)
        newpoint.rgba = red;
        if (newpoint.x > xmax ...
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2013-01-11 09:08:45


Could you include a minimal code example? Also, is your code a nodelet? Is this cloud from a Kinect? What is the frame_id of the cloud (Z forward seems to indicate an optical reference frame)?

Eric Perko gravatar image Eric Perko  ( 2012-06-18 12:05:50 -0500 )edit

Oops, sorry, yes, it's from a Kinect, and yes, it is the optical reference frame, and Z is indeed forward. I'll paste the actual code soon...

kameleon gravatar image kameleon  ( 2012-06-19 09:01:27 -0500 )edit

Can you try either setting the point.r, point.g, point.b values individually or shifting your colors an extra 8 bits to account for the fact that there is an alpha channel?

Eric Perko gravatar image Eric Perko  ( 2012-06-20 11:50:42 -0500 )edit

Eric, I tried that as well, but it's not due to adding the color itself. After I separated the closer objects and put their points in a new cloud and displayed that cloud instead of the original one, all points were colored red as they should be.

kameleon gravatar image kameleon  ( 2012-06-26 04:59:52 -0500 )edit

Please post your solution as an answer and then mark it as accepted once you are able to. This will help keep ROS Answers organized and easy to use in the future. Thanks!

Eric Perko gravatar image Eric Perko  ( 2012-06-26 05:17:30 -0500 )edit

No solution found yet. I have been working with PCL and ROS for quite a short time, so I was hoping someone here would know how this could happen, but it's not at all crucial for my project. I appreciate the help anyway, guys. Thanks.

kameleon gravatar image kameleon  ( 2012-07-05 05:26:11 -0500 )edit