Can't use 2D indexing with an unorganized point cloud
I'm using perception_pcl package to convert sensor_msgs::msg::PointCloud2 to pcl::PointXYZRGB and get the rgb or x,y,z data according to the raw and column value according to below code:
pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2; pcl::PointCloud<pcl::pointxyzrgb> cloud_xyzrgb;
// Convert to PCL data type
pcl_conversions::toPCL(*cloud_msg, *cloud);
pcl::fromROSMsg (*cloud_msg, cloud_xyzrgb);
std::cout<<cloud_xyzrgb.height<<"\t"<<cloud_xyzrgb.width<<std::endl;
std::cout<<cloud_xyzrgb.at(1,1)<<std::endl;
But when i run this node. i'm getting the below error:
1 202403
terminate called after throwing an instance of 'pcl::UnorganizedPointCloudException'
what(): : Can't use 2D indexing with an unorganized point cloud
Environment:
Depth sensor: intel realsense d455 depth sensor
depth sensor driver: realsense-ros, foxy branch
ros version: ros2 foxy fitzroy
os: ubuntu 20.04 desktop
This same approach used to work in ros1 as i can remember. But as i migrated to ros2 foxy, looks like this feature hasn't implemented still now.