基于pcl 和 liblas 库 las与pcd格式(rgb点)相互转换(win10 VS2013 X64环境 )
#include <liblas/liblas.hpp>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <cmath>
#include <pcl/point_cloud.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/visualization/pcl_visualizer.h> // 实现Unshort转为Unchar类型
//int Unshort2Unchar(uint16_t &green, uint8_t &g)
//{
// unsigned short * word;
// word = &green;
// int size = WideCharToMultiByte(CP_ACP, 0, LPCWSTR(word), -1, NULL, 0, NULL, FALSE);
// char *AsciiBuff=new char[size];
// WideCharToMultiByte(CP_ACP, 0, LPCWSTR(word), -1, AsciiBuff, size, NULL, FALSE);
// g = *AsciiBuff;
//
// delete[] AsciiBuff;
// AsciiBuff = NULL;
// return 0;
//} void writePointCloudFromLas(const char* strInputLasName, const char* strOutPutPointCloudName)
{
//打开las文件
std::ifstream ifs;
ifs.open(strInputLasName, std::ios::in | std::ios::binary);
if (!ifs.is_open())
{
std::cout << "无法打开.las" << std::endl;
return;
}
liblas::ReaderFactory readerFactory;
liblas::Reader reader = readerFactory.CreateWithStream(ifs);
//写点云
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloudOutput(new pcl::PointCloud<pcl::PointXYZRGBA>());
cloudOutput->clear();
while (reader.ReadNextPoint())
{
double x = reader.GetPoint().GetX();
double y = reader.GetPoint().GetY();
double z = reader.GetPoint().GetZ();
uint16_t red = reader.GetPoint().GetColor()[];
uint16_t green = reader.GetPoint().GetColor()[];
uint16_t blue = reader.GetPoint().GetColor()[]; /*****颜色说明
* uint16_t 范围为0-256*256 ;
* pcl 中 R G B利用的unsigned char 0-256;
* 因此这里将uint16_t 除以256 得到 三位数的0-256的值
* 从而进行rgba 值32位 的位运算。
*
******/ pcl::PointXYZRGBA thePt; //int rgba = 255<<24 | ((int)r) << 16 | ((int)g) << 8 | ((int)b);
thePt.x = x; thePt.y = y; thePt.z = z;
thePt.rgba = (uint32_t) << | (uint32_t)(red / ) << | (uint32_t)(green / ) << | (uint32_t)(blue / );
//uint32_t rgb = *reinterpret_cast<int*>(&thePt.rgb); //reinterpret_cast 强制转换
cloudOutput->push_back(thePt);
} //boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
//viewer->setBackgroundColor(0, 0, 0); //设置背景
//viewer->addPointCloud(cloudOutput,"cloudssd");
//while (!viewer->wasStopped()){
// viewer->spinOnce();
//}
pcl::io::savePCDFileASCII(strOutPutPointCloudName, *cloudOutput);
cloudOutput->clear();
} //读入点云,写.las void writeLasFromPointCloud3(const char* strInputPointCloudName, const char* strOutLasName)
{
std::ofstream ofs(strOutLasName, ios::out | ios::binary);
if (!ofs.is_open())
{
std::cout << "err to open file las....." << std::endl;
return;
}
liblas::Header header;
header.SetVersionMajor();
header.SetVersionMinor();
header.SetDataFormatId(liblas::PointFormatName::ePointFormat3);
header.SetScale(0.001, 0.001, 0.001); pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGBA>);
pcl::io::loadPCDFile(strInputPointCloudName, *cloud);
std::cout << "总数:" << cloud->points.size() << std::endl;
//写liblas,
liblas::Writer writer(ofs, header);
liblas::Point point(&header); for (size_t i = ; i < cloud->points.size(); i++)
{
double x = cloud->points[i].x;
double y = cloud->points[i].y;
double z = cloud->points[i].z;
point.SetCoordinates(x, y, z); uint32_t red = (uint32_t)cloud->points[i].r;
uint32_t green = (uint32_t)cloud->points[i].g;
uint32_t blue = (uint32_t)cloud->points[i].b;
liblas::Color pointColor(red, green, blue);
point.SetColor(pointColor);
writer.WritePoint(point);
//std::cout << x << "," << y << "," << z << std::endl;
}
double minPt[] = { , , };
double maxPt[] = { , , };
header.SetPointRecordsCount(cloud->points.size());
header.SetPointRecordsByReturnCount(, cloud->points.size());
header.SetMax(maxPt[], maxPt[], maxPt[]);
header.SetMin(minPt[], minPt[], minPt[]);
writer.SetHeader(header);
} int main()
{
//char strInputLasName[] = "qq.las";//"Scan_az001.las";
//char strOutPutPointCloudName[]="qqqq.pcd";
//writePointCloudFromLas(strInputLasName, strOutPutPointCloudName); //std::string strInputPointCloudName = "eewge";
//std::string strOutLasName = "eewge";
//writeLasFromPointCloud(strInputPointCloudName.c_str(), strOutLasName.c_str());
char strInputPointCloudName[] = "qq.pcd";
char strOutLasName[] = "qq.las";
writeLasFromPointCloud3(strInputPointCloudName, strOutLasName); return ;
}
基于pcl 和 liblas 库 las与pcd格式(rgb点)相互转换(win10 VS2013 X64环境 )的更多相关文章
- 25 面向对象设计实例——基于PCL点云库的通用工具开发
0 引言 问题背景:pcl中提供了大量工具,用于对点云和三角面片文件进行处理和显示.在研究中,存在很多简易的需求,比如点云坐标转换,点云的打开显示以及同步显示,点云的最小包络求解,点云的格式转换等等. ...
- PCL点云库中的坐标系(CoordinateSystem)
博客转载自:https://blog.csdn.net/qq_33624918/article/details/80488590 引言 世上本没有坐标系,用的人多了,便定义了坐标系统用来定位.地理坐标 ...
- Windows 8 64位系统 在VS2010 32位软件上 搭建 PCL点云库 开发环境
Windows 8 64位系统 在VS2010 32位软件上 搭建 PCL点云库 开发环境 下载PCL For windows 软件包 到这个网站下载PCL-All-In-One Installer: ...
- [PCL]1 PCL点云库安装
1.安装文件下载:官网,我还是比较喜欢别人编译好的安装包啊,哈哈. http://www.pointclouds.org/downloads/windows.html 2.傻瓜式安装(下面的依赖项都集 ...
- PCL点云库:ICP算法
ICP(Iterative Closest Point迭代最近点)算法是一种点集对点集配准方法.在VTK.PCL.MRPT.MeshLab等C++库或软件中都有实现,可以参见维基百科中的ICP Alg ...
- 基于Qt的第三方库和控件
====================== 基于Qt的第三方库和控件 ====================== libQxt -------- http://dev.libqxt.o ...
- 利用cocoapods创建基于git的私有库
上一篇文章记录了我利用cocoapods创建基于SVN的私有库的全部过程,今天我再记录一下基于git创建的过程. 整体先说明一下创建一个私有的podspec包括如下那么几个步骤: 创建并设置一个私有的 ...
- Axios 是一个基于 promise 的 HTTP 库
Axios 是一个基于 promise 的 HTTP 库 vue项目中关于axios的简单使用 axios介绍 Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.j ...
- 利用cocoapods创建基于git的私有库Spec Repo
上一篇文章记录了我利用cocoapods创建基于SVN的私有库的全部过程,今天我再记录一下基于git创建的过程. 整体先说明一下创建一个私有的podspec包括如下那么几个步骤: 创建并设置一个私有的 ...
随机推荐
- Web表单提交之disabled问题
例如,有如下表单 <form id="inputForm" action="shorttermrental.action" method="po ...
- PAT 天梯赛 L1-043 阅览室
L1-043. 阅览室 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 天梯图书阅览室请你编写一个简单的图书借阅统计程序.当读者 ...
- rsync Linux系统下的数据镜像备份工具
rsync是Linux系统下的数据镜像备份工具,从软件的命名上就可以看出来了——remote sync.rsync支持大多数的类Unix系统,无论是Linux.Solaris还是BSD上都经过了良好的 ...
- What and How in an Application
Basically, two concerntrations: 1. What: business docs and prototype design 2. How: technical docs a ...
- 【Visual Studio】error c4996: 'fopen': This function or variable may be unsafe(转)
原文转自 http://blog.csdn.net/zhangyuehuan/article/details/12012635 [解决方案]项目 =>属性 =>c/c++ =>预处 ...
- 使用python将ppm格式转换成jpg【转】
转自:http://blog.csdn.net/hitbeauty/article/details/48465017 最近有个很火的文章,叫 有没有一段代码,让你觉得人类的智慧也可以璀璨无比? 自己试 ...
- Akka Stream之Graph
最近在项目中需要实现图的一些操作,因此,初步考虑使用Akka Stream的Graph实现.从而学习了下: 一.介绍 我们知道在Akka Stream中有三种简单的线性数据流操作:Source/Flo ...
- Beginning Auto Layout Tutorial in iOS 7: Part 1
可以更好的结局屏幕方向和兼容iphone和ipad的解决方案. iOS6有一个新的技术auto layout来帮助解决这个问题.这个技术不仅可以支持app不同尺寸下的开发,而且你也不需要为每一种语言创 ...
- Android属性动画:动画流控制
今天的文章里,我将会和大家讨论对动画流的控制.我们可以通过Animator系列的API来控制动画的开始.停止和取消.在 KitKat也就是API level 19中,我们还可以控制动画的暂停和恢复.在 ...
- 15.【nuxt起步】-Nuxt使用jsweixin sdk
npm install weixin-js-sdk --save 这个不行,这个是vue前端用的 网上找了一些vue jsweixin的案例 不能直接用 因为nuxt是后端运行,windows对象取不 ...