PCL点云将带强度信息LAS格式转换成PCD文件
很多人说在CloudCompare里面不是有现成的格式转换吗,但是我试了下CloudCompare里面转换出来的效果是这样的。。。我们可以发现他是这种Intensity在前面的形式,其实这种格式的PCD在PCL读取中是读不出来强度信息的。
我的方法是用CloudCompare把LAS格式转换成TXT格式,再读取TXT格式,代码转换成符合PCL规范的PCD文件。(其实可以直接将LAS转为PCD的,但是我的库函数有点问题,就换了成TXT了,有点麻烦了)
#include<fstream>
#include<string>
#include<iostream>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/io/pcd_io.h>
#include <time.h>
#include <boost/thread/thread.hpp>
typedef pcl::PointXYZI PointT;
typedef pcl::PointCloud<PointT> PointCloud;
using namespace std;
int main() {
double x, y, z;
float intensity;
string s;
FILE* fp_txt;
fp_txt = fopen("txt.txt", "r");
PointCloud::Ptr cloud_src_o(new PointCloud);//原点云,待配准
pcl::io::loadPCDFile("鼎垵6_13_1yes.pcd", *cloud_src_o);
cout << "start" << endl;
int i=0;
int point_size = cloud_src_o->size();
while (i< point_size) {
if (fscanf(fp_txt, "%lf %lf %lf %f",&x,&y,&z,&intensity)) {
cloud_src_o->points[i].intensity = intensity;
}
else {
cout << "error" << endl;
}
i++;
}
pcl::io::savePCDFileASCII("intensity.pcd", *cloud_src_o);
cout << "success" << endl;
}