【发布时间】: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