0
$\begingroup$

Rosanswers logo

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::PointCloudpcl::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.


Originally posted by dinesh on ROS Answers with karma: 932 on 2021-05-30

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Ok after few hours of debugging and research i found that their is a parameter in realsense node which enables the pointcloud being publishing to be organized, default being un-organized. So setting ordered_pc:=true made this issue solved. Here is my full command:

ros2 launch realsense2_camera rs_launch.py enable_pointcloud:=true ordered_pc:=true

Originally posted by dinesh with karma: 932 on 2021-05-30

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.