为了分析点云数据,然后想查看一下原始的pcd,结果使用cat查看时出现乱码,因为保存形式二进制形式,所以这里就是简单的一个pcd另存为的操作!
#include <iostream>
#include <cstring>
#include <pcl/io/pcd_io.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
bool LoadPCD(std::string filename, pcl::PointCloud<pcl::PointXYZ>::Ptr cloud)
{
if (pcl::io::loadPCDFile<pcl::PointXYZ>(filename, *cloud) == -1)
{
std::cout<< "can't read file " << filename << std::endl;
return (-1);
}
}
int main(int argc, char **argv) {
std::cout << "Hello, world!" << std::endl;
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_source(new pcl::PointCloud<pcl::PointXYZ>);
std::string filename = "/home/frr/Documents/code/3d_pointcloud_plane_fitting/test_planefitting.pcd";
// std::string filename = "../table_scene_lms400.pcd";
LoadPCD(filename, cloud_source);
std::cout << "PointCloud_source has: " << cloud_source->points.size () << " data points." << std::endl;
pcl::PCDWriter writer;
std::stringstream ss;
ss << "/home/frr/Documents/code/pcl_learning/ascii_change/build/ascii_change.pcd";
writer.write<pcl::PointXYZ> (ss.str (), *cloud_source, false); //*
return 0;
}
再次读取使用cat查看时,就是正常的数据显示了
PCL用的还不是很熟,还在慢慢摸索很多功能中,如果有理解不到位的地方还请小伙伴们指正!