Point Cloud Filtering and processing using PCL is slow
Hi All
I have code for a ROS node that subscribes to A PointCloud2 topic published by iai_kinect2's kinect bridge. My problem is that the code runs quite slowly. I have narrowed down the slowing-down to my spinOnce() statement, so I'm pretty sure it's my callback function that's being slow. However, my callback is using the reccommended way of converting the pc2 message into a PCL point cloud. Here it is for reference:
void cloudCallback(const sensor_msgs::PointCloud2ConstPtr& msg){
// Create a container for the data.
pcl::PCLPointCloud2 pcl_pc2;
pcl_conversions::toPCL(*msg,pcl_pc2);
pcl::fromPCLPointCloud2(pcl_pc2,*cloud);
pcl::removeNaNFromPointCloud(*cloud,*outputCloud, indices);
sor.setInputCloud(outputCloud);
sor.setLeafSize (0.01f, 0.01f, 0.01f);
sor.filter (*outputCloudFilt);
}
All the objects used here were pre-initialised before main(). The code runs just as slowly if I remove the filtering from the callback.
I should also add that the speed is slow independently of how many points are in the cloud.
EDIT: Using fromROSMsg() doesn't help with my problem.
Something to check: did you compile with optimisations enabled?
And not an answer, but
pcl_ros
comes with a few PCL filters wrapped in nodelets: wiki/pcl_ros - Nodelets.Also, please give us your full code, for all we know the issue is somewhere over there. Also please describe what "slow" means to you. Give us some metrics to work with.
Yeah fair enough. I meant that my code was running at like 0.1Hz, which is way slower than you would actually expect.