程序
// PCL點云數(shù)據(jù)的讀取和顯示
#include <iostream> //標(biāo)準(zhǔn)輸入輸出流
#include <pcl/io/pcd_io.h> //PCL的PCD格式文件的輸入輸出頭文件
#include <pcl/point_types.h> //PCL對各種格式的點的支持頭文件
#include <pcl/visualization/cloud_viewer.h>
// 更改背景顏色
void viewerOneOff(pcl::visualization::PCLVisualizer& viewer)
{
viewer.setBackgroundColor(1.0f, 0.5f, 1.0f);
}
int main(int argc, char** argv)
{
// 創(chuàng)建點云(指針)
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// 讀入PCD格式的文件,如果文件不存在,返回-1
if (pcl::io::loadPCDFile<pcl::PointXYZ>("/home/xx/下載/rabbit.pcd", *cloud) == -1)
{
PCL_ERROR("Couldn't read file test_pcd.pcd \n"); //文件不存在時,返回錯誤,終止程序。
return (-1);
}
std::cout << "cloud points size= " << cloud->points.size() << std::endl;
std::cout << "Loaded:" << cloud->width*cloud->height
<< "data points from test_pcd.pcd with the following fields:"
<< std::endl;
for (size_t i = 0; i < cloud->points.size(); ++i)
{
std::cout << "x= " << cloud->points[i].x
<< "y= " << cloud->points[i].y
<< "z= " << cloud->points[i].z
<< "; " << std::endl;
}
pcl::visualization::CloudViewer viewer("cloud viewer");
viewer.showCloud(cloud);
// 更改背景顏色
viewer.runOnVisualizationThreadOnce(viewerOneOff);
// 保證不閃退
while (!viewer.wasStopped())
{
}
system("pause");
return (0);
}

image.png
按R鍵
image.png
