PCL:可视化点云 [英] PCL: Visualise a point cloud
问题描述
我正在尝试使用 PCL CloudViewer可视化点云.问题是我刚接触C ++,并且发现了两个教程第一演示了PointCloud的创建,并第二演示了点云.但是,我无法将这两个教程结合在一起.
I'm trying to visualise 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 demonstration the visualisation 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.foo
s更改为cloud->foo
s.
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.foo
s to cloud->foo
s.
看您提供的第二个示例,他们这样做好吧:
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屋!