Subscribe to PointClud2 Ros2 [closed]
Hello together
I get a depth image from my intel d453 camera in a PointClud2 msgs. My problem is now the following. I do not understand how I can access the individual points, i.e. XYZ coordinates. It is only possible to access the whole data structure. Unfortunately it is not possible to sort the points correctly.
I need the following information for each point XYZ coordinates Color of the point
Is it possible to access the individual points within the data structure in this way?
Here is my Subscriber Callback:
void callback_depth_image_d435 (const sensor_msgs::msg::PointCloud2::SharedPtr depth_points)
{
printf("Cloud: width = %u, height = %u\n", depth_points->width, depth_points->height);
// Looking for Something like that
// BOOST_FOREACH(const Point& pt, depth_points->points)
// {
// printf("\tpos = (%f, %f, %f), w = %u, normal = (%f, %f, %f)\n",
// pt.pos.x, pt.pos.y, pt.pos.z, pt.w,
// pt.normal[0], pt.normal[1], pt.normal[2]);
// }
//test
std::cout << "data_size" << depth_points->data.size() << "\n";
std::cout << "point_step" << depth_points->point_step << "\n";
//std::cout << "data_size" << depth_points-> << "\n";
std::cout << "data_size" << depth_points->data.size() << "\n";
}
Many thanks in advance!