基于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包括如下那么几个步骤: 创建并设置一个私有的 ...
随机推荐
- openssl Rsa 分段加密解密
密钥长度 1024 openssl genrsa -out rsa_private_key.pem openssl rsa -in rsa_private_key.pem -pubout -out r ...
- Android Win7 上使用cmd生成Jks
Android Win7 上使用cmd生成Jks cmd 命令 C:\Program Files\Java\jre1.8.0_111\bin>keytool -genkeypair -alias ...
- Linux和Windows兼容
1. 介绍 我们知道Linux上的应用程序是ELF格式的,而Windows则是PE格式 所以要解决这个问题首先二进制加载问题:其次,就是API问题,两者的API完全不同要实现兼容,就需要构建一个虚拟层 ...
- C#byte怎么转成图片
这个其实很简单我给大家提供一个方法吧 /// <summary> /// 字节数组生成图片 /// </summary> /// <param name="By ...
- HDU4757 Tree(可持久化Trie)
写过可持久化线段树,但是从来没写过可持久化的Trie,今天补一补. 题目就是典型的给你一个数x,和一个数集,问x和里面的某个数xor起来的最大值是多少. 最原始的是数集是固定的,只需要对数集按照高到低 ...
- centos 7 安装git并配置ssh
一.安装 1.查看是否安装git rpm -qa|grep git 有git加版本号就说明已经安装过了 2.安装git yum install git 3.查看git版本 git version 二. ...
- hdu 4541(麻烦的模拟)
Ten Googol Time Limit: 500/200 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Su ...
- git tag 的使用
// 查看tag,列出所有tag,列出的tag是按字母排序的,和创建时间没关系. $ git tag v0.1 v1.3 /查看指定版本的tag,git tag -l “v1.4.2.**” $ gi ...
- CVPR 2019|PoolNet:基于池化技术的显著性检测 论文解读
作者 | 文永亮 研究方向 | 目标检测.GAN 研究动机 这是一篇发表于CVPR2019的关于显著性目标检测的paper,在U型结构的特征网络中,高层富含语义特征捕获的位置信息在自底向上的传播过 ...
- POJ 3254 Corn Fields [DP]
题意:略. 思路:第一次做状态压缩的dp. 在这里说一下状态压缩的原则.因为每一行只有最多12个格子,每个格子只有1(可放牛)和0(不可放牛)两种状态,这总共是2^12种状态,直接用一个int整型变量 ...