问题描述
我有两个点云,我想在同一窗口中对其进行可视化.
I have two point cloud, which I want to visualise in the same window.
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/cloud_viewer.h>
int main ()
{
pcl::visualization::CloudViewer viewer("Cloud Viewer");
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr body (new pcl::PointCloud<pcl::PointXYZRGBA>);
pcl::io::loadPCDFile ("body.pcd", *body);
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr head (new pcl::PointCloud<pcl::PointXYZRGBA>);
pcl::io::loadPCDFile ("head.pcd", *head);
viewer.showCloud (body);
viewer.showCloud (head);
while (!viewer.wasStopped ())
{
}
return 0;
}
我只能看到最后一个PCD文件.
I can see only the last PCD file.
请注意,我不想使用pcd_viewer工具,因为我需要对该数据进行其他处理.
推荐答案
关于评论
好的.我会尽快检查它.您能告诉我使用cloud_viewer API设置相机参数和背景颜色吗?"
我不确定100%是否可以使用pcl::visualization::CloudViewer
执行此操作.但是,如果将代码移到pcl::visualization::PCLVisualizer
,则可以执行viewer.setBackgroundColor(double red,double green,double blue)
(其中值的范围是0..1.设置摄像机).对于相机,您可以使用 pcl::visualization::PCLVisualizer::setCameraPosition
.将代码从CloudViewer迁移到PCLVisualizer非常容易.
I am not 100% sure if you can do this using pcl::visualization::CloudViewer
. However, if you move your code to pcl::visualization::PCLVisualizer
you can do viewer.setBackgroundColor(double red,double green,double blue)
(where the values range 0..1. To set a camera). For the camera, you can use pcl::visualization::PCLVisualizer::setCameraPosition
. Moving your code from CloudViewer to PCLVisualizer is preatty easy.
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
int main ()
{
pcl::visualization::PCLVisualizer viewer("Cloud Viewer");
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr body (new pcl::PointCloud<pcl::PointXYZRGBA>);
pcl::io::loadPCDFile ("body.pcd", *body);
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr head (new pcl::PointCloud<pcl::PointXYZRGBA>);
pcl::io::loadPCDFile ("head.pcd", *head);
viewer.addPointCloud (body,"body");// note that before it was showCloud
viewer.addPointCloud (head,"head");// note that before it was showCloud
viewer.spin();
return 0;
}
编辑从某种意义上说,这是一种方法.通过查看此处,您可以看到您可以运行pcl::visualization::PCLVisualizer
使用pcl::visualization::CloudViewer::runOnVisualizationThreadOnce
或pcl::visualization::CloudViewer::runOnVisualizationThread
功能.为此,您将需要创建一个函数,该函数执行使用pcl::visualization::PCLVisualizer
的所有部分,并将其传递给CloudViewer::runOnVisualizationThreadOnce
或CloudViewer::runOnVisualizationThread
.
EDITTher is acutally a way to do this. By looking into here, you can see that you can run any of the function of the pcl::visualization::PCLVisualizer
using the pcl::visualization::CloudViewer::runOnVisualizationThreadOnce
or pcl::visualization::CloudViewer::runOnVisualizationThread
functions. For this, you will need to create a function that does all the part that uses pcl::visualization::PCLVisualizer
and pass it to the CloudViewer::runOnVisualizationThreadOnce
or CloudViewer::runOnVisualizationThread
.
例如
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/cloud_viewer.h>
void
setBackground (pcl::visualization::PCLVisualizer& viewer)
{
viewer.setBackgroundColor (1.0, 0.5, 1.0);
}
int main ()
{
pcl::visualization::PCLVisualizer viewer("Cloud Viewer");
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr body (new pcl::PointCloud<pcl::PointXYZRGBA>);
pcl::io::loadPCDFile ("body.pcd", *body);
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr head (new pcl::PointCloud<pcl::PointXYZRGBA>);
pcl::io::loadPCDFile ("head.pcd", *head);
viewer.showCloud (body,"body");
viewer.showCloud (head,"head");
viewer.runOnVisualizationThreadOnce(setBackground);
while (!viewer.wasStopped ())
{
}
return 0;
}
唯一的问题是,我看不到如何潜在地将参数传递给要在我们创建的函数中使用的pcl::visualization::PCLVisualizer
函数(在上一个示例中,在setBackground
中为pcl::visualization::PCLVisualizer::setBackgroundColor
.),为此,我认为直接使用pcl::visualization::PCLVisualizer
会更好.
The only issue is that I do not see how you could potentially pass arguments to the pcl::visualization::PCLVisualizer
function that you want to use in the function we crated (in the previous example pcl::visualization::PCLVisualizer::setBackgroundColor
in setBackground
. For this, I think using directly pcl::visualization::PCLVisualizer
is much better.
这篇关于使用C ++中的PCL在同一窗口中查看多个点云的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!