使用PCL

时间:2019-06-05 12:05:27

标签: c++ ros

我正在尝试将PCL与ROS结合使用以估计已发布的点云形凉亭模拟器的表面法线;这是我的回调函数,但是,出现以下错误。你能帮忙吗?。

我按照PCL教程进行了正常估算,对我来说很好用。

void     cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud_msg)
    { 
 // Container for original & filtered data
 pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2; 
 pcl::PCLPointCloud2ConstPtr cloudPtr(cloud);    
//  pcl::PCLPointCloud2 cloud_filtered;


 // Convert to PCL data type
 pcl_conversions::toPCL(*cloud_msg, *cloud);



 // Create the normal estimation class, and pass the input dataset to 
 pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
 ne.setInputCloud (cloud);


// Create an empty kdtree representation, and pass it to the normal  estimation object.
 // Its content will be filled inside the object, based on the given input dataset (as no other search surface is given).
 pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ> ());
 ne.setSearchMethod (tree);

 // Output datasets
 pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>);

 // Use all neighbors in a sphere of radius 3cm
 ne.setRadiusSearch (0.03);

 // Compute the features
 ne.compute (*cloud_normals);


 // cloud_normals->points.size () should have the same size as the input cloud->points.size ()*
 // visualize normals
 pcl::visualization::PCLVisualizer viewer("PCL Viewer");
 viewer.setBackgroundColor (0.0, 0.0, 0.5);
 viewer.addPointCloudNormals<pcl::PointXYZ,pcl::Normal>(cloud, cloud_normals);

 while (!viewer.wasStopped ())  // THE ORGINAL !viewer.wasStopped () 
         {
           viewer.spinOnce ();
         }







 // Convert to ROS data type
 sensor_msgs::PointCloud2 output;
 pcl_conversions::moveFromPCL(cloud, output);





 // Publish the data.
 pub.publish (output);    }

错误:没有匹配的函数可调用“ pcl :: NormalEstimation :: setInputCloud(pcl :: PCLPointCloud2 *&)”       ne.setInputCloud(cloud);

错误:没有匹配的函数调用“ pcl :: visualization :: PCLVisualizer :: addPointCloudNormals(pcl :: PCLPointCloud2 *&,pcl :: PointCloud :: Ptr&)”       viewer.addPointCloudNormals(cloud,cloud_normals);

错误:模板参数个数错误(2,应为1)       viewer.addPointCloudNormals(cloud,cloud_normals);                                                                                  ^

错误:没有匹配的函数调用“ moveFromPCL(pcl :: PCLPointCloud2 *&,sensor_msgs :: PointCloud2&)”       pcl_conversions :: moveFromPCL(cloud,output);

1 个答案:

答案 0 :(得分:0)

我解决了这个问题;我应该将消息类型转换为正确的格式。 this answer对我有很大帮助。