Optimized ROS->PCL conversion

Hi perception engineers!

if you use PCL with ROS, you are certainly using the function pcl::fromROSMsg to converts sensor_msgs::PointCloud2 to pcl::PointCloud<PointT>.

This function consumes a considerable amount of CPU and we haven’t started processing the PointCloud yet!

Luckily, you can make this function almost 2 times faster.

The implementation is available here: Drop in replacement for pcl::fromROSMsg · GitHub

You can easily convert this to ROS2, simply renaming the namespace of the sensors_msgs.

A PR has already been submitted, but if you want to take advantage of this improvement right now, you may try the stand-alone file I shared.


PS: I also take the opportunity that friends don’t let friends allocate memory. Remember that you should try to reuse existing pointclouds in each loop, instead of allocating new ones.


Great discovery, Davide! Could you elaborate shortly on what does the improvement lie in?

I’ll also add a link to a relevant piece of information - pcl::toPclPointCloud2 and pcl::toROSMsg keep the alignment bytes introduced by the PCL library to make memory operations faster. But inflating the message size might decrease preformance elsewhere…

Very easy! The new function is as efficient as pcl::moveFromROS would be, if I could use it.
Unfortunately, we can not move the sensor_msg, because it is a ConstReference.

This obliges the original implementation to copy data from sensor_msgs::PointCloud2 to pcl::PointCloud2.

I skip that part, modifying the pcl::PointCloud2 to pclPintCloud<T> function, to make it able to accept the data from sensor_msgs.

Apart from that, I am not doing anything that PCL isn’t doing.


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.