我使用 libLAS 库来读取.las 文件的浊点。然后我将点存储在 PCL 点云变量中,以便使用点云库处理和显示点云。
这是我使用的代码:
class PointCloud
{
public:
//PointCloud(const std::string& path);
uint32_t getVertsCount();
float4* getVertsData();
template<typename PointT>
typename pcl::PointCloud<PointT>::Ptr read(const std::string& path);//void read(const std::string &path);
}
template<typename PointT>
typename pcl::PointCloud<PointT>::Ptr PointCloud::read(const string& path)
{
typename pcl::PointCloud<PointT>::Ptr lasCloud(new pcl::PointCloud<PointT>);
std::ifstream ifs;
ifs.open(path, std::ios::in | std::ios::binary);
//std::ifstream inf(path, std::ios::in | std::ios::binary);
liblas::ReaderFactory f;
liblas::Reader reader = f.CreateWithStream(ifs);
liblas::Header const& header = reader.GetHeader();
std::cout << "Compressed: " << (header.Compressed() == true) ? "true" : "false";
std::cout << "Signature: " << header.GetFileSignature() << '\n';
std::cout << "Points count: " << header.GetPointRecordsCount() << '\n';
while (reader.ReadNextPoint())
{
liblas::Point const& p = reader.GetPoint();
PointT cloudPoint;
cloudPoint.x = float(p.GetX()) * 0.001 + 590284.000; // (double)(x * scaleX) + offsetX;
cloudPoint.y = float(p.GetY()) * 0.001 + 4339456.000; // (double)(y * scaleY) + offsetY;
cloudPoint.z = float(p.GetZ()) * 0.001 + 157.000; // (double)(z * scaleZ) + offsetZ;
std::cout << p.GetX() << ", " << p.GetY() << ", " << p.GetZ() << "\n";
//cloudPoint.intensity = p.GetIntensity(); // (double)(intensity) / 65536.0;
lasCloud->points.push_back(cloudPoint);
}
if (!ifs.good())
throw runtime_error("Reading went wrong!");
lasCloud->width = lasCloud->points.size();
lasCloud->height = 1;
lasCloud->is_dense = true;
std::cout << "Cloud size = " << lasCloud->points.size() << endl;
return lasCloud;
}
int main (int argc, char** argv)
{
std::cout << "starting enviroment" << std::endl;
pcl::visualization::PCLVisualizer::Ptr viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
CameraAngle setAngle = FPS; //XY, FPS, Side, TopDown
initCamera(setAngle, viewer);
pcl::PointCloud<pcl::PointXYZ>::Ptr inputCloudI; //
inputCloudI = pcd.read<pcl::PointXYZ>("C:/Users/hedey/OneDrive/Documents/Research_papers/STDF/10_4231_MFQF-Q141/I-65/LiDAR/RoadSurface/NB/20180524_I65_NB_RoadSurface_1_50.5.las");
std::cout << "Cloud size = " << inputCloudI->points.size() << endl;
renderPointCloud(viewer, inputCloudI, "lasCloud");
while (!viewer->wasStopped())
{
viewer->spinOnce();
}
}
但是,使用 PCL 查看器显示的云看起来像一个点。我注意到,当我打印出使用 libLAS 读取的坐标时,x & y 坐标没有十进制值,这与 las 文件中存储的实际坐标相比是不准确的。我在命令提示符下使用 las2txt 得到了实际的点坐标。这是包含实际坐标的 txt 文件。这是显示 cout 结果的图像:
此外,这也是我使用 CloudCompare 打开点云时的样子。当我将它读入 PCL 点云变量并使用 PCL 查看器显示结果时,我期待得到相同的显示,因为我需要进行进一步处理才能进行传感器融合(相机和激光雷达)。