ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This works for me:

void cloudCb(const sensor_msgs::PointCloud2ConstPtr & cloud) {
  pcl::PointCloud<pcl::PointXYZ> depth;
  pcl::fromROSMsg( *cloud, depth);
  int x = 0, y = 0; // set x and y
  pcl::PointXYZ p1 = depth.at(x, y);
}

That comes from a sample that uses the full ROS pointCloud2 data structure, but you should be able to do the same by subscribing to the pcl::PointCloud<pcl::PointXYZ> type.

Perhaps if you described the problem better by posting the code that's giving you trouble, how you're running it, describing the desired results, and the actual results, we might be be able to provide more useful advice.

This works for me:

void cloudCb(const sensor_msgs::PointCloud2ConstPtr & cloud) {
  pcl::PointCloud<pcl::PointXYZ> depth;
  pcl::fromROSMsg( *cloud, depth);
  int x = 0, y = 0; // set x and y
  pcl::PointXYZ p1 = depth.at(x, y);
}

That comes from a sample that uses the full ROS pointCloud2 data structure, but you should be able to do the same by subscribing to the pcl::PointCloud<pcl::PointXYZ> type.

Note that the PointCloud is already transformed into sensor-relative world coordinates; I don't need to perform any additional transformation or use the camera intrinsics to get XYZ data.

Perhaps if you described the problem better by posting the code that's giving you trouble, how you're running it, describing the desired results, and the actual results, we might be be able to provide more useful advice.