简体   繁体   中英

calculate normals and displaying with PCL

Hello I'm trying to work whith a point cloud to get some planes by clustering the normals from the points, so I'm using the following code but it seems is not working as I want. I don`t know almost anything about programming on PCL, so my doubts are where is the variable that contains the cloud if I want to work with, and for displaying the normals is necessary to use PCLVisualizer, but I tried some stuff without getting a good result. So could you pleas give some advices to get the results, that I need. Best Regards and thank you.

#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;
 }

I don't know exactly what you are doing, but I guess you input cloud the is unorganized point cloud. So no width and height are given. Change in this example the width and the height to you sensor.

if (!viewer.wasStopped())
{

cloud->width = 640;
cloud->height = 480;

ne.setInputCloud (cloud);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM