我有一个点云(.pcd)文件,我从中生成了法线。现在我想在同一个查看器窗口(而不是多个视口)中显示输入点云以及生成的法线。我开发的代码是
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/features/normal_3d.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/features/integral_image_normal.h>
int main ()
{
// load point cloud
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
if (pcl::io::loadPCDFile<pcl::PointXYZ> ("table_scene_mug_stereo_textured.pcd", *cloud) == -1)
{
PCL_ERROR ("Couldn't read file table_scene_mug_stereo_textured.pcd \n");
return (-1);
}
std::cout << "Loaded "
<< cloud->width * cloud->height
<< " data points from test_pcd.pcd with the following fields: "
<< std::endl;
std::cout << "Input cloud Point Size "
<< cloud->points.size ()
<< std::endl;
// organized or unorganized normal estimation
pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>);
if (cloud->isOrganized ())
{
std::cout << "Computing normals Inside organized block " << std::endl;
pcl::IntegralImageNormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
ne.setInputCloud (cloud);
ne.setNormalEstimationMethod (ne.AVERAGE_3D_GRADIENT);
ne.setNormalSmoothingSize (float (0.03));
ne.setDepthDependentSmoothing (true);
ne.compute (*cloud_normals);
}
else
{
std::cout << "Computing normals Inside non-organized block " << std::endl;
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
ne.setInputCloud (cloud);
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ> ());
ne.setSearchMethod (tree);
ne.setRadiusSearch (0.03);
ne.compute (*cloud_normals);
}
std::cout << "cloud_normals Point Size "<< cloud_normals->points.size () << std::endl;
//write the normals to a PCD file
pcl::PCDWriter writer;
writer.write("computed_normals.pcd", *cloud_normals, false);
// visualize normals
pcl::visualization::PCLVisualizer viewer("PCL Viewer");
viewer.setBackgroundColor (0.0, 0.0, 0.0);
viewer.addPointCloud< pcl::PointXYZRGB >( cloud, "cloud", 0);
viewer.addPointCloudNormals<pcl::PointXYZ,pcl::Normal>(cloud, cloud_normals);
while (!viewer.wasStopped ())
{
viewer.spinOnce ();
}
return 0;
}
当我尝试调试代码时,我收到一个错误
没有重载函数的实例“pcl :: visualization :: PCLVisualizer :: addPointCloud”匹配参数列表
在线
viewer.addPointCloud <pcl :: PointXYZRGB>(云,“云”,0);
我已经参考了文档并花了很长时间在网上解决这个问题而没有成功。
我正确地向观众添加点云吗?如果没有,请告诉我将点云与生成的法线一起添加到查看器的正确方法。
您曾尝试添加错误类型的点云。将行更改为:
viewer.addPointCloud< pcl::PointXYZ >( cloud, "cloud", 0);
这个问题在这里也回答了:
有关点云类型的更多信息,请在此处参考PCL库:http://pointclouds.org/documentation/tutorials/adding_custom_ptype.php#what-pointt-types-are-available-in-pcl