用PCL计算法线并显示

calculate normals and displaying with PCL

本文关键字:显示 算法 PCL 计算      更新时间:2023-10-16

你好,我正试图与点云一起工作,通过从点聚集法线来获得一些平面,所以我使用以下代码,但它似乎不像我想要的那样工作。我对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;
 }

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

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