#include "pch.h"
#include <iostream>//标准C++库中的输入输出类相关的头文件
#include <string.h>
#include <pcl/io/auto_io.h>//pcd读写类相关的头文件
int main(int argc, char** argv)
{
std::string filename = "F:\\cout-saved\\back_1.pcd";
//创建一个pcl::PointCloud<pcl::PointXYZI>boost共享指针并进行实例化
pcl::PointCloud<pcl::PointXYZI>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZI>);
//打开点云文件
if (pcl::io::loadPCDFile(filename, *cloud) < 0)
{
std::cout << "open file error" << std::endl;
Sleep(3000);
return -1;
}
pcl::PointCloud<pcl::PointXYZ>::Ptr new_cloud(new pcl::PointCloud<pcl::PointXYZ >);
new_cloud->width = cloud->width;
new_cloud->height = cloud->height;
new_cloud->points.resize(cloud->points.size());
for (int i = 0; i < cloud->points.size(); ++i)
{
new_cloud->points[i].x = cloud->points[i].x;
new_cloud->points[i].y = cloud->points[i].y;
new_cloud->points[i].z = cloud->points[i].z;
}
if (pcl::io::savePCDFile("F:\\cout-saved\\back_1_remove.pcd", *new_cloud) < 0)
{
std::cout << "save file error" << std::endl;
Sleep(3000);
return -1;
}
else
{
std::cout << "save file success" << std::endl;
Sleep(3000);
return 0;
}
}
上述代码功能为:将点云数据的Pcd格式数据包含XYZI的删除掉I,仍保存为Pcd格式。此点云数据有(841行X777列)=653457个点