Ask Your Question
1

Accessing depth data from a pointcloud2 message

asked 2017-09-20 11:10:16 -0600

sykatch gravatar image

updated 2017-09-21 12:14:20 -0600

Hi all!

I want to select the depth (z) values of a given row from a sensor_msgs/pointcloud2 message. I have this code so far:

for (int i = 0; i < cloud->width; i++)
{
  int index = cloud->row_step*ROW_NUM + cloud->point_step*i + cloud->fields[2].offset;
  memcpy(&depth_data[i], &cloud->data[index], sizeof(float));
}

However the code is probably not correct, as the values it gives don't seem to be the real ones. I chose the middle row of the pointcloud (num. 239) and put the sensor in front of the wall, so "the ray of the middle row" should be normal to the wall and so the z value should be the real distance from the wall. The result was: real distance 2m, the z value from the message 0.001. When I changed the row number to some other value, the z values were even below 0 (which is definitely not correct as I want to get the forward distances). So what am I doing wrong in my code? (I do not want to convert the ros message to a pcl structure.) Thanks in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-09-21 12:30:30 -0600

Hi there,

You code all seems spot on, however you're assumption that depth is the z axis may be incorrect. See here for the coordinate conventions used in ROS, the standard convention has X as the forward direction and Z pointing up. Unless your sensor is using an optical frame convention in which case Z does face forwards.

It's probably worth printing out all three dimensions at several positions in the point cloud to find out what's going on with the data.

Hope this helps,

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-09-20 11:10:16 -0600

Seen: 830 times

Last updated: Sep 21 '17