1

我有以下代码来估计和显示点云中点的法线向量:

int main(int argc, char* argv[]) {

      pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);

      if (pcl::io::loadPCDFile<pcl::PointXYZ> ("coffee_mug_1_1_1.pcd", *cloud) == -1) //* load the file
      {
        PCL_ERROR ("Couldn't read file coffee_mug_1_1_1.pcd \n");
        return (-1);
      }
      std::cout << "Loaded "
                << cloud->width * cloud->height
                << " data points from test_pcd.pcd with the following fields: "
                << std::endl;


      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);

      cout << "Computed normals " << cloud_normals->width * cloud_normals->height << cloud_normals->points[0] << endl;    

      pcl::visualization::PCLVisualizer viewer("PCL Viewer");

      viewer.setBackgroundColor(0.0, 0.0, 0.5);
      viewer.addPointCloud(cloud);
      viewer.addPointCloudNormals<pcl::PointXYZ,pcl::Normal>(cloud, cloud_normals);
      while (!viewer.wasStopped ())
      {
          viewer.spinOnce ();
      }
}

但是,当我运行它时,PCLVisualizer 在屏幕上闪烁,然后程序终止。我不知道为什么它不留下来。如果我只使用 CloudViewer 来显示点云(而不是法线),那么它可以正常工作并保留在屏幕上。

4

2 回答 2

1

您可以检查 3 件事:

  1. 检查您确实没有错误地阅读您的文件。你可以在后面加上一个cin.get()right ,PCL_ERROR ("Couldn't read file coffee_mug_1_1_1.pcd \n");这样它就不会直接退出,以防它无法读取文件。
  2. 如果你想可视化它们,可能你应该给你的法线一个不同的 id,因为我认为现在,你的云和法线都使用 id“云”。检查正常可视化的 PCL 示例。(例如viewer.addPointCloud(cloud, "cloud"); viewer.addPointCloudNormals<pcl::PointXYZ,pcl::Normal>(cloud, cloud_normals, 10, 0.05, "normals");
  3. 确保获得法线的有效值。

如果这些作品没有任何效果,您能否将您的咖啡杯 pcd 上传到某个地方并提供链接?

于 2012-12-12T23:26:56.913 回答
0

我发现了我在这里遇到的问题,我没有链接到我正在编译的 boost 库,因为我的链接库路径中有 /usr/lib

于 2013-01-24T17:10:19.670 回答