【问题标题】:calculate normals and displaying with PCL计算法线并用 PCL 显示
【发布时间】:2023-03-12 03:10:02
【问题描述】:

您好,我正在尝试使用点云通过对点的法线进行聚类来获取一些平面,因此我正在使用以下代码,但它似乎无法按我的意愿工作。 我对在 PCL 上编程几乎一无所知,所以我怀疑如果我想使用包含云的变量在哪里,并且显示法线是使用 PCLVisualizer 所必需的,但我尝试了一些东西但没有得到好结果。 因此,您能否提供一些建议以获得我需要的结果。 最好的问候,谢谢。

#include <pcl/point_types.h>
#include <pcl/visualization/pcl_visualizer.h>    
#include <pcl/io/openni_grabber.h>
#include <pcl/sample_consensus/sac_model_plane.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/features/normal_3d.h>
using namespace std;


class SimpleOpenNIViewer
 {
   public:
     pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
     SimpleOpenNIViewer () : viewer ("PCL OpenNI Viewer") {}
     void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud)
     {
       if (!viewer.wasStopped())
       {
            ne.setInputCloud (cloud);

            pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ> ());
            ne.setSearchMethod (tree);
            pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>);
            ne.setRadiusSearch (0.03);
           ne.compute (*cloud_normals);
           cout<<"Normales calculadas"<<endl;
           viewer.showCloud (cloud);
       }

     }
     void run ()
     {

       pcl::Grabber* interface = new pcl::OpenNIGrabber();
       boost::function<void (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr&)> f =
       boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1);

       interface->registerCallback (f);
       interface->start ();
       while (!viewer.wasStopped())
       {
         boost::this_thread::sleep (boost::posix_time::seconds (1));
       }
       interface->stop ();
     }
     pcl::visualization::CloudViewer viewer;
 };

 int main ()
 {
   SimpleOpenNIViewer v;
   v.run ();
   return 0;
 }

【问题讨论】:

    标签: c++ boost point-cloud-library


    【解决方案1】:

    我不知道你在做什么,但我猜你输入的云是无组织的点云。所以没有给出宽度和高度。在此示例中更改传感器的宽度和高度。

    if (!viewer.wasStopped())
    {
    
    cloud->width = 640;
    cloud->height = 480;
    
    ne.setInputCloud (cloud);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-26
      • 2014-06-17
      • 1970-01-01
      • 2022-07-04
      相关资源
      最近更新 更多