I'm trying to find a solution of converting PointCloud2 message data into xyz array for further analysis. Though, in my case I'm interested only in 2d application.

The information is either scarce or confusing.

Each point data in the PointCloud2 is stored as a binary blob. For example: First 1-4 numbers represent x as a 32 bit float, 5-8 represents y, 9-12 represents z, 13-16 represents the intensity.

So, my question is, is there any ROS2 library to make the conversion? Alternatively, any example of implementing it in C++.

For both cases, please provide a full code snippet or a link to an example


1 Answer 1


Look in the sensor_msgs_py package. It contains support functions for working with some of the more complex sensor messages, including point clouds. For your specific case, you could use the read_points() or read_points_numpy() or even the read_points_list() function to get the data out as a numpy array, which you can then analyse in the way you want.

  • $\begingroup$ Thank you. Primarily, I was interested in C++ implementation. Any examples of that? $\endgroup$
    – nigeno
    Apr 4, 2022 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.