PCL:可视化点云 [英] PCL: Visualize a point cloud

查看:139
本文介绍了PCL:可视化点云的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PCL CloudViewer 可视化点云.问题是我对 C++ 很陌生,我发现了两个教程 首先 演示了 PointCloud 的创建和 第二 演示点云的可视化.但是,我无法将这两个教程结合起来.

I'm trying to visualize a point cloud using PCL CloudViewer. The problem is that I'm quite new to C++ and I have found two tutorials first demonstrating the creation of PointCloud and second demonstrating the visualization of a PointCloud. However, I'm not able to combine these two tutorials.

这是我想出的:

#include <iostream>

#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/visualization/cloud_viewer.h>

int main (int argc, char** argv)
{
  pcl::PointCloud<pcl::PointXYZ> cloud;
  
  // Fill in the cloud data
  cloud.width    = 5;
  cloud.height   = 1;
  cloud.is_dense = false;
  cloud.points.resize (cloud.width * cloud.height);

  for (size_t i = 0; i < cloud.points.size (); ++i)
  {
    cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
    cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
  }

  pcl::visualization::CloudViewer viewer ("Simple Cloud Viewer");
  viewer.showCloud (cloud);

  while (!viewer.wasStopped ())
  {
  }

  return (0);
}

但即使不编译:

error: no matching function for call to   
‘pcl::visualization::CloudViewer::showCloud(pcl::PointCloud<pcl::PointXYZ>&)’

推荐答案

您的错误消息告诉您需要做什么:

Your error message tells you what you need to do:

error: no matching function for call to ‘pcl::visualization::CloudViewer::showCloud(pcl::PointCloud<pcl::PointXYZ>&)’

因此请转到 CloudViewer 的文档并查看此成员函数采用哪些参数:http://docs.pointclouds.org/1.5.1/classpcl_1_1visualization_1_1_cloud_viewer.html

So go to the documentation for CloudViewer and see what arguments this member function takes: http://docs.pointclouds.org/1.5.1/classpcl_1_1visualization_1_1_cloud_viewer.html

我们看到它需要一个 const MonochromeCloud::ConstPtr &cloud 而不是您传入的原始引用.这是 boost 中智能指针的 typedef:

There we see that it takes a const MonochromeCloud::ConstPtr &cloud not the raw reference that you are passing in. This is a typedef of a smart pointer from boost:

typedef boost::shared_ptr<const PointCloud<PointT> > pcl::PointCloud< PointT >::ConstPtr

因此,当您创建云时,您需要将其包装在这些智能指针之一中,而不是使其成为局部变量.类似(未经测试):

So when you create your cloud you need to wrap it in one of these smart pointers instead of making it a local variable. Something like (untested):

pcl::MonochromeCloud::ConstPtr cloud(new pcl::PointCloud<pcl::PointXYZ>());

然后,当你传入变量cloud时,它的类型是正确的,你不会得到你报告的错误.您还必须将 cloud.foos 更改为 cloud->foos.

Then, when you pass in the variable cloud, it will have the correct type and you won't get the error that you report. You will also have to change your cloud.foos to cloud->foos.

查看您提供的第二个示例,他们这样做嗯:

Looking at the second example you give, they do this as well:

pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>);

这篇关于PCL:可视化点云的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆