【发布时间】:2018-11-19 14:23:25
【问题描述】:
我有一个点云 (.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( cloud, "cloud", 0);
我参考了文档并在网络上花费了相当长的时间来解决这个问题,但没有成功。
我是否正确地将点云添加到查看器?如果没有,请告诉我将点云与生成的法线一起添加到查看器的正确方法。
【问题讨论】: