c++ 读取csv文件格式点云

在这里插入图片描述
如图点云以csv文件存储,下面代码读取每个点的坐标值存放在 pcl::PointCloud中:

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
using namespace std;

//删除字符串中空格,制表符tab等无效字符
string Trim(string& str)
{
	//str.find_first_not_of(" \t\r\n"),在字符串str中从索引0开始,返回首次不匹配"\t\r\n"的位置
	str.erase(0, str.find_first_not_of(" \t\r\n"));
	str.erase(str.find_last_not_of(" \t\r\n") + 1);
	return str;
}

void csv2pointCloud(std::string filename, pcl::PointCloud<pcl::PointXYZ>::Ptr &cloud)
{
	cloud->points.clear();
	ifstream fin(filename); //打开文件流操作
	string line;
	while (getli

版权声明:本文为zfjBIT原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。