Ask Your Question
0

Point Cloud Filtering and processing using PCL is slow

asked 2020-03-24 08:32:15 -0500

christophecricket gravatar image

updated 2020-03-24 11:19:00 -0500

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.

edit retag flag offensive close merge delete

Comments

2

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.

gvdhoorn gravatar image gvdhoorn  ( 2020-03-24 12:29:59 -0500 )edit

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.

stevemacenski gravatar image stevemacenski  ( 2020-03-24 13:06:31 -0500 )edit

Yeah fair enough. I meant that my code was running at like 0.1Hz, which is way slower than you would actually expect.

christophecricket gravatar image christophecricket  ( 2020-03-24 13:41:08 -0500 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2020-03-24 13:44:14 -0500

christophecricket gravatar image

Thanks @gvdhoorn turning on compiler optimisation gives me speeds more in line with what I expect (~20-30Hz, and actually scales with the size of the cloud). To anyone else experiencing this problem: set the following flag in catkin_make:

-DCMAKE_BUILD_TYPE=Release
edit flag offensive delete link more

Comments

Sounds about right! Was this for setting in your application or in your PCL/PCL ROS build itself?

stevemacenski gravatar image stevemacenski  ( 2020-03-24 21:34:21 -0500 )edit

I just turned it on for the entirety of the packages in my src/ folder.

christophecricket gravatar image christophecricket  ( 2020-03-25 03:26:58 -0500 )edit

And what’s in that? PCL, pcl_perception? Just your application code?

stevemacenski gravatar image stevemacenski  ( 2020-03-25 10:40:29 -0500 )edit
1

Oooh I just got what you're trying to ask. No it's just my application code. I didn't recompile the binaries for PCL or ROS.

christophecricket gravatar image christophecricket  ( 2020-03-25 14:18:00 -0500 )edit

ah ok,thanks

stevemacenski gravatar image stevemacenski  ( 2020-03-25 15:13:51 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2020-03-24 08:24:21 -0500

Seen: 33 times

Last updated: Mar 24