用PCL计算法线并显示
calculate normals and displaying with PCL
你好,我正试图与点云一起工作,通过从点聚集法线来获得一些平面,所以我使用以下代码,但它似乎不像我想要的那样工作。我对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);
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 为什么这个运算符<重载函数对 STL 算法不可见?
- 字符串-C++后显示的随机字符
- 继承期间显示未知行为的子类
- 仅使用绝对值对数组进行排序,并在C++中显示实际值
- 基于ELO的团队匹配算法
- C++选择排序算法中的逻辑错误
- 有没有办法将谓词中的元素偏移量传递给 std 算法?
- C++A*算法并不总是在路径中具有目标节点
- 程序崩溃并显示"std::out_of_range"错误
- 排序算法c++
- 构建可组合有向图(扫描仪生成器的汤普森构造算法)
- 如何在C++中用std::cout正确显示带十六进制的字符串文本
- 为什么在C的循环中使用printf的Rust代码不显示输出,而在C++的循环中显示std::cout
- C++公历年显示算法
- 素数算法:通过边权重的总和显示相关边
- 如何编写一种算法,该算法在哪个行中显示出在哪个行中显示(我使用的是std :: map)
- 无重载运算符=显示在算法.cpp中
- 是由DFS算法找到的生成树总是显示在预序中