成功的方法:

可以转成ply bin pcd格式,转换流程如下所示:
1、打开CloudCompare软件,加载点云数据(.las或者是.laz等等)。

2、选择要进行转换的文件,此时屏幕上会出现一个立方体。

3、点击【File】中的【Save】,选择你要保存的格式即可。

laspy的方法没成功,c++的方法还没试。

pip install laspy==1.5.1

不能安装2.0.0以后版本,2.0.1会报错。

https://github.com/grantbrown/laspy/releases

from laspy.file import File
import numpy as npdef las2pcd():inFile = File(r'F:\biadu_down\las-20200813-110417_1\data-20200813-110417_1.las', mode='r')I = inFile.Classification == 2outFile = File('aaaa.pcd', mode='w', header=inFile.header)outFile.points = inFile.points# outFile.points = inFile.points[I]outFile.close()if __name__ == '__main__':import numpy as nplas2pcd()import open3d as o3dpcd1 = o3d.io.read_point_cloud(r'aaaa.pcd')# pcd1 = o3d.io.read_point_cloud(r'F:\biadu_down\las-20200813-110417_1\data-20200813-110417_1.las')pcd1.paint_uniform_color([0, 0, 0])o3d.visualization.draw_geometries([pcd1])

转换之后,open3d直接读las,出来是白屏。

c++:

https://github.com/yoshiyama/las2pcd_gui/blob/master/las2pcd/las2pcd.cpp

#include <iostream>
#include <cstdlib>
#include <liblas/liblas.hpp>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>using namespace std;int main (int argc, char *argv[])
{string filePath;cout << "===================================================================" << endl;cout << "LAS2PCD - Converts .las point clouds into PCL-friendly format .pcd" << endl;cout << "ver 0.3 - 16 March 2018" << endl;cout << "(c) Arnadi Murtiyoso" << endl;cout << "PAGE Group, ICube Laboratory UMR 7357 INSA Strasbourg" << endl;cout << "contact: arnadi.murtiyoso@insa-strasbourg.fr" << endl;cout << "https://github.com/murtiad" << endl;cout << "Ubuntu tweaks by Jonathan Greenberg, jgreenberg@unr.edu" << endl;cout << "Ubuntu version: https://github.com/gearslaboratory/las2pcd" << endl;cout << "===================================================================" << endl;cout << endl;// cout << "Enter full .las file path: (or you can also drag the file here)" << endl;// getline(cin, filePath);// Edited to make fully command-line:filePath=argv[1];std::cerr << "INFO : Loading : " << filePath << std::endl;// instancing a new PCL pointcloud objectpcl::PointCloud<pcl::PointXYZRGB> cloud;// Opening  the las filestd::ifstream ifs(filePath.c_str(), std::ios::in | std::ios::binary);// Safeguard against opening failureif(ifs.fail()) {std::cerr << "ERROR : Impossible to open the file : " << filePath <<std::endl;return 1;}liblas::ReaderFactory f;liblas::Reader reader = f.CreateWithStream(ifs); // reading las fileunsigned long int nbPoints=reader.GetHeader().GetPointRecordsCount();// Fill in the cloud datacloud.width    = nbPoints;              // This means that the point cloud is "unorganized"cloud.height   = 1;                       // (i.e. not a depth map)cloud.is_dense = false;cloud.points.resize (cloud.width * cloud.height);cout << "INFO : " << cloud.points.size () << " points detected in " << filePath << endl;int i=0;               // counteruint16_t r1, g1, b1;  // RGB variables for .las (16-bit coded)int r2, g2, b2;         // RGB variables for converted values (see below)uint32_t rgb;          // "packed" RGB value for .pcdwhile(reader.ReadNextPoint()) {// get XYZ informationcloud.points[i].x = (reader.GetPoint().GetX());cloud.points[i].y = (reader.GetPoint().GetY());cloud.points[i].z = (reader.GetPoint().GetZ());// get intensity information//cloud.points[i].intensity = (reader.GetPoint().GetIntensity());// get RGB information. Note: in liblas, the "Color" class can be accessed from within the "Point" class, thus the triple getsr1 = (reader.GetPoint().GetColor().GetRed());g1 = (reader.GetPoint().GetColor().GetGreen());b1 = (reader.GetPoint().GetColor().GetBlue()); // .las stores RGB color in 16-bit (0-65535) while .pcd demands an 8-bit value (0-255). Let's convert them!r2 = ceil(((float)r1/65535)*(float)255);g2 = ceil(((float)g1/65535)*(float)255);b2 = ceil(((float)b1/65535)*(float)255);// PCL particularity: must "pack" the RGB into one single integer and then reinterpret them as floatrgb = ((int)r2) << 16 | ((int)g2) << 8 | ((int)b2);cloud.points[i].rgb = *reinterpret_cast<float*>(&rgb);i++; // ...moving on}// Allows output file to be set://pcl::io::savePCDFileASCII (argv[2], cloud);pcl::io::savePCDFileBinaryCompressed (argv[2], cloud);std::cerr << "Saved " << cloud.points.size () << " data points to pointcloud.pcd." << std::endl;return (0);
}

https://www.freesion.com/article/2519238749/

https://blog.csdn.net/qq_42570058/article/details/83068759


#include <liblas\liblas.hpp>
#include <fstream>
#include <iostream>
#include <string>
#include<vector>
#include<pcl\io\pcd_io.h>
#include<pcl\point_types.h>
#include<time.h>
int main()
{clock_t sT, tT,eT;//打开文件ifstream fp;fp.open("1.las",ios::in|ios::binary);sT = clock();//读取liblas::ReaderFactory readerFactory;liblas::Reader reader = readerFactory.CreateWithStream(fp);tT = clock();cout << "读取" << reader.GetHeader().GetPointRecordsCount() <<"个点花费"<<(double)(tT-sT)/CLOCKS_PER_SEC<<"s"<<endl;//点云类型pcl::PointCloud<pcl::PointXYZ> cloudOutput;cloudOutput.clear();//转换xyzwhile (reader.ReadNextPoint()){double x = reader.GetPoint().GetX();double y = reader.GetPoint().GetY();double z = reader.GetPoint().GetZ();pcl::PointXYZ thePt(x,y,z);cloudOutput.push_back(thePt);}cloudOutput.width = cloudOutput.size();cloudOutput.height = 1;cloudOutput.is_dense = false;cloudOutput.resize(cloudOutput.width*cloudOutput.height);pcl::io::savePCDFileASCII("1.pcd",cloudOutput);cloudOutput.clear();eT = clock();cout << "存入" << reader.GetHeader().GetPointRecordsCount() << "个点花费" << (double)(eT - tT) / CLOCKS_PER_SEC << "s" << endl;return 0;
}

https://www.dtmao.cc/news_show_15044.shtml

.las数据转.pcd格式是参考这里点击打开链接,很容易能够得到正确的.pcd格式文件;

但是,当用PCL库读取并显示的时候,却看不到图形,我是用的PCL的第一种显示方法CloudViewer显示的,也是用的官网示例代码

#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>int user_data;void
viewerOneOff (pcl::visualization::PCLVisualizer& viewer)
{viewer.setBackgroundColor (1.0, 0.5, 1.0);pcl::PointXYZ o;o.x = 1.0;o.y = 0;o.z = 0;viewer.addSphere (o, 0.25, "sphere", 0);std::cout << "i only run once" << std::endl;}void
viewerPsycho (pcl::visualization::PCLVisualizer& viewer)
{static unsigned count = 0;std::stringstream ss;ss << "Once per viewer loop: " << count++;viewer.removeShape ("text", 0);viewer.addText (ss.str(), 200, 300, "text", 0);//FIXME: possible race condition here:user_data++;
}int
main ()
{pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>);pcl::io::loadPCDFile ("my_point_cloud.pcd", *cloud);pcl::visualization::CloudViewer viewer("Cloud Viewer");//blocks until the cloud is actually renderedviewer.showCloud(cloud);//use the following functions to get access to the underlying more advanced/powerful//PCLVisualizer//This will only get called onceviewer.runOnVisualizationThreadOnce (viewerOneOff);//This will get called once per visualization iterationviewer.runOnVisualizationThread (viewerPsycho);while (!viewer.wasStopped ()){//you can also do cool processing here//FIXME: Note that this is running in a separate thread from viewerPsycho//and you should guard against race conditions yourself...user_data++;}return 0;
}于是查找原因,准备换一种显示方法,就是比较复杂的PCLVisualizer,但是代码有点多,也是第一次学习使用PCL,就没有立刻写代码,而是分析了一下源代码中的示例数据,bunny.pcd;这只兔子的数据都是小于1的,猜测应该是归一化之后得到的坐标,所以,网上找相关内容,但没有得到肯定的答案,因为也担心归一化的效率问题,想看看有没有更好的办法啊,最终,没有找到更好的办法来保留原始坐标系统,通过修改.las转.pcd格式的代码,也就是增加了一个归一化步骤,之后得到数据,居然能够正常显示了,也算是有点收获;// LASlib_3DlasTo2D.cpp: 定义控制台应用程序的入口点。
//#include "stdafx.h"
#include "lasreader.hpp"
#include "laswriter.hpp"
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <GL/glut.h>
#include "stdafx.h"
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <string>
#include <vector>
#include <fstream>
#include <ios>
#include <iostream>//#include <glut.h>
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL);
VTK_MODULE_INIT(vtkInteractionStyle);/*
将'/'格式的文件路径转换成 '\\';
*/
static std::string convertFilePath(const std::string& file)
{int i = 0;std::string s(file);for (i = 0; i < s.size(); ++i){if (s[i] == '/')s[i] = '\\';}return s;
}
int main()
{/*LASreadOpener lasreadopener;lasreadopener.set_file_name("1.las");LASreader* lasreader = lasreadopener.open();LASwriteOpener laswriteopener;laswriteopener.set_file_name("2.laz");LASwriter* laswriter = laswriteopener.open(&lasreader->header);while (lasreader->read_point())laswriter->write_point(&lasreader->point);laswriter->close();delete laswriter;lasreader->close();delete lasreader;
*/const char* your_las_file_path = "D:\\任务:点云和影像配准\\data\\LIDAR\\4test_60km.las";const char* your_pcd_out_file_path = "XX.pcd";//laslib只允许'\\'格式的文件路径。std::string lasFile = convertFilePath(your_las_file_path);//打开las文件LASreadOpener lasreadopener;lasreadopener.set_file_name(lasFile.c_str());LASreader* lasreader = lasreadopener.open();size_t count = lasreader->header.number_of_point_records;pcl::PointCloud<pcl::PointXYZ>::Ptr pointCloudPtr(new pcl::PointCloud<pcl::PointXYZ>);pointCloudPtr->resize(count);pointCloudPtr->width = 1;pointCloudPtr->height = count;pointCloudPtr->is_dense = false;size_t i = 0;int maxX = -9999, minX = 9999999999, MaxY = -999999999, minY = 9999999999, maxZ = -999999999, minZ=999999999;/*int x, y, z;*/maxX = lasreader->get_max_x();minX = lasreader->get_min_x();MaxY = lasreader->get_max_y();minY = lasreader->get_min_y();maxZ = lasreader->get_max_z();minZ = lasreader->get_min_z();double dx = maxX - minX;double dy = MaxY - minY;double dz = maxZ - minZ;double maxd = dx > dy ? (dx > dz ? dx : dz) : (dy > dz ? dy : dz);/*double maxd,mind,Dd;dx > dy ? (dx > dz ? (maxd = maxX, mind = minX, Dd = dx) : (maxd = maxZ, mind = minZ, Dd = dz)) : (dy > dz ? (maxd = MaxY, mind = minY, Dd = dy) : (maxd = maxZ, mind = minZ, Dd = dz));
*/printf( "%f",maxd);size_t j = 0;while (lasreader->read_point() && j < count){pointCloudPtr->points[j].x = (lasreader->point.get_x() - minX)/maxd;pointCloudPtr->points[j].y = (lasreader->point.get_y() - minY)/maxd;pointCloudPtr->points[j].z = (lasreader->point.get_z() - minZ)/maxd;/*pointCloudPtr->points[j].x = (lasreader->point.get_x()) / 1;pointCloudPtr->points[j].y = (lasreader->point.get_y()) / 1;pointCloudPtr->points[j].z = (lasreader->point.get_z()) / 1;*/++j;}pcl::io::savePCDFileASCII(your_pcd_out_file_path, *pointCloudPtr);getchar();return 0;
}

这是CloudViewer显示结果,没有添加渲染效果;

这是原始.las数据,ENVILiDar软件显示:
————————————————
版权声明:本文为CSDN博主「啊吼!」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xujie126/article/details/80824924

las数据转pcd并显示相关推荐

  1. php数据库查询中文方块,解决Python数据可视化中文部分显示方块问题

    一.问题 代码如下,发现标题的中文显示的是方块 import matplotlib import matplotlib.pyplot as plt fig = plt.figure() ax = fi ...

  2. Ionic+Angular+Express实现前后端交互使用HttpClient发送get请求数据并加载显示(附代码下载)

    场景 Ionic介绍以及搭建环境.新建和运行项目: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/106308166 在上面搭建起 ...

  3. db2 两个结构相同的表_从两个工作表提取数据记录,并显示相同记录的报告

    大家好,今日继续VBA数据库解决方案的讲解,今日讲解的是第47讲,内容是:在两个工作表提取数据记录,并显示相同记录的报告. 我们在工作中经常会遇到这样的情况,要分析两个工作表,知道哪些记录是重复的,如 ...

  4. 客户端出错:无法在数据表视图中显示该列表: 没有安装与 Windows SharePoint Services 兼容的数据表组件...

    P:客户端想在数据表中编辑时提示下列错误: 数据视图由于下列一个或多个原因,无法在数据表视图中显示该列表: 没有安装与 Windows SharePoint Services 兼容的数据表组件,浏览器 ...

  5. 【ArcGIS风暴】ArcGIS+CASS点云(.las)数据生成等高线方法案例精解

    本文讲解基于点云LAS数据,在ArcGIS+CASS平台上生成等高线的方法. 扩展阅读: 什么是点云?什么是Las数据集?一篇文章告诉你点云数据的奥秘 ArcGIS+CASS点云(.las)数据生成等 ...

  6. date数据要在前台显示

    date数据要在前台显示,如果要截取一部分使用,最好用SimpleDateFormat不要用toString不牢靠. 转载于:https://www.cnblogs.com/king12345678/ ...

  7. js如何实现动态显示表格数据(点奇数显示奇数单元格内容)

    js如何实现动态显示表格数据(点奇数显示奇数单元格内容) 一.总结 一句话总结: 1.动态指定表格中每个单元格的id,然后通过id可以获取每个单元格,然后对里面的innerHTML进行赋值. 2.弄了 ...

  8. 设置oracle每行显示字符个数,Oracle一列的多行数据拼成一行显示字符-Oracle

    Oracle一列的多行数据拼成一行显示字符 oracle 提供了两个函数WMSYS.WM_CONCAT 和 ListAgg函数. www.2cto.com 先介绍:WMSYS.WM_CONCAT 例: ...

  9. wpf datagrid 数据为null时 显示背景图_[C#.NET 拾遗补漏]09:数据标注与数据校验

    数据标注(Data Annotation)是类或类成员添加上下文信息的一种方式,在 C# 通常用特性(Attribute)类来描述.它的用途主要可以分为下面这三类: 验证 Validation:向数据 ...

最新文章

  1. 【 MATLAB 】MATLAB 实现模拟信号采样后的重建(一)
  2. IntelliJ IDEA 2020 创建xml文件
  3. Apache beam其他学习记录
  4. 计算机中是如何存储图片的,电脑如何保存图片
  5. 一个bootstrap.css的使用案例
  6. 使用JDOM生成/解析XML文档
  7. HTML——<blockquote>与<q>的区别
  8. 网上体育商城的设计与实现毕业设计论文
  9. autojs 串口通信 替代无障碍 串口
  10. linux删除文件子最后两行,关于linux:如何使用sed删除文件的最后n行
  11. html内嵌式选择器,CSS样式 CSS选择器(Cascading Style Sheet)
  12. Echarts曲线渐变色lineStyle
  13. PMBOK(第六版) PMP笔记——《十三》第十三章(项目干系人管理)
  14. unity实现简单游戏——井字棋
  15. distill_bert和tiny_bert
  16. 计算机C语言二级操作题之编程题
  17. Ghost过程中出现GHOSTERR.TXT文件的解决方法
  18. fmri|SPM contrast manager
  19. Java中详述构造方法与setter方法
  20. 市政管网检测机器人收费标准_迁安市政下水道机器人检测费用多少

热门文章

  1. NtQueryInformationProcess用法
  2. 如何动态添加菜单/菜单项、子菜单、右键菜单
  3. 读秦小波《设计模式之禅》 -- 单例模式
  4. java设计模式---策略模式
  5. C语言头文件和库的一些问题
  6. nova api 分析
  7. qt widget 窗口拉伸_QTDesigner的QVBoxLayout自动随窗口拉伸
  8. 等待队列——休眠与唤醒
  9. OpenStack neutron中AsyncProcess类
  10. html5时间轴列表,HTML5 时间轴/日程安排表模板