首页 > 编程语言 >Python,C++中点云 .las转.pcd

Python,C++中点云 .las转.pcd

时间:2022-10-27 19:44:11浏览次数:76  
标签:GetPoint Python C++ pcd pcl reader cloud las

(39条消息) Python,C++中点云 .las转.pcd_程序媛一枚~的博客-CSDN博客

1. Python .las转.pcd

# -*- coding: utf-8 -*-
# 读取las文件 并保留为 XYZI格式的pcd文件

import pcl  # 调用pcl保留pcd文件
from laspy.file import File  # las文件读取
import numpy as np  # np数组处理
import time  # 计算耗时

# las读取转为 pcd的cloud形式,只保留 XYZI
def getCloud():
    file = r"D:/pcd/1001140020191217.las"
    f = File(file, mode='r')
    inFile = np.vstack((f.x, f.y, f.z, f.intensity)).transpose()
    cloud = pcl.PointCloud_PointXYZI()
    cloud.from_array(np.array(inFile, dtype=np.float32))
    f.close()

    return cloud


def main():
    end1 = time.time()
    cloud = getCloud()
    pcl.save(cloud, r"D:/pcd/1001140020191217_las2pcd.pcd")
    end2 = time.time()
    print("las2pcd 耗时:%.2f秒" % (end2 - end1))
    print('-------endl----------')


if __name__ == '__main__':
    main()

2. C++ .las转.pcd

用到liblas库,需要安装好PCL1.8.1

start las2pcd.exe D:/pcd/1001140020191217.las D:/pcd/1001140020191217_las2pcd.pcd

#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)
{
    std::ifstream ifs(argv[1], std::ios::in | std::ios::binary); // 打开las文件
    liblas::ReaderFactory f;
    liblas::Reader reader = f.CreateWithStream(ifs); // 读取las文件

    unsigned long int nbPoints=reader.GetHeader().GetPointRecordsCount();//获取las数据点的个数

    pcl::PointCloud<pcl::PointXYZI> cloud;
    cloud.width    = nbPoints;    //保证与las数据点的个数一致    
    cloud.height   = 1;            
    cloud.is_dense = true;
    cloud.points.resize (cloud.width * cloud.height);

    int i=0;                
    /* uint16_t r1, g1, b1;    
    int r2, g2, b2;            
    uint32_t rgb;        */    

    while(reader.ReadNextPoint()) 
    {
        // 获取las数据的x,y,z信息
        cloud.points[i].x = (reader.GetPoint().GetX());
        cloud.points[i].y = (reader.GetPoint().GetY());
        cloud.points[i].z = (reader.GetPoint().GetZ());
        cloud.points[i].intensity = (reader.GetPoint().GetIntensity());
        
        //获取las数据的r,g,b信息
        /*r1 = (reader.GetPoint().GetColor().GetRed());
        g1 = (reader.GetPoint().GetColor().GetGreen());
        b1 = (reader.GetPoint().GetColor().GetBlue()); 
        r2 = ceil(((float)r1/65536)*(float)256);
        g2 = ceil(((float)g1/65536)*(float)256);
        b2 = ceil(((float)b1/65536)*(float)256);
        rgb = ((int)r2) << 16 | ((int)g2) << 8 | ((int)b2);
        cloud.points[i].rgb = *reinterpret_cast<float*>(&rgb);*/
        i++; 
    }
  
    pcl::io::savePCDFileASCII (argv[2], cloud);//存储为pcd类型文件
    return (0);
}

 

标签:GetPoint,Python,C++,pcd,pcl,reader,cloud,las
From: https://www.cnblogs.com/yibeimingyue/p/16833505.html

相关文章

  • 如何在CMake中启用C++ 17
    如何在CMake中启用C++17MiP*_*MiP  38 c++ cmake visual-studio c++17 我正在使用VS15.3,它支持集成的CMake3.8.如何在不为每个特定编译器编写标志的情况下定......
  • python crawler 入门学习 ---初爬豆瓣
    #进入豆瓣电影网站,点击排行榜、选择喜剧分类 按下F12进入检查界面,点击Network(网络)、重新加载网站、点击typerank文件、选择XHR(XMLHttpRequest(简称xhr),是浏览器提供的JS......
  • UE4 C++实现第三人称角色基本功能
    首先基于Character创建一个角色类,在头文件为其添加弹簧臂和摄像机组件UPROPERTY(VisibleAnywhere,Category="Comp")classUCameraComponent*CameraComp......
  • python(hashlib模块,subprocess模块,logging模块)
    今日内容概要hashlib加密模块subprocess模块logging模块软件开发主要流程hashlib加密模块1.什么是加密? 将明文数据处理成密文数据,让人无法看懂2.为什么要加密? ......
  • python模块之hashlib、subprocess
    今日内容概要hashlib加密模块subprocess模块logging日志模块软件开发主要流程今日内容详细hashlib加密模块1.何为加密 将明文数据处理成密文数据让人无法看......
  • python基础:hashilib加密模块
    目录hashilib加密模块1加密的含义简介2加密算法基本操作3加密补充说明(hashlib的特点)4加密操作的用处5优秀hash算法的特性hashilib加密模块hashlib是一个提供了......
  • python模块之日志模块
    logging日志模块1.如何理解日志 简单的理解为是记录行为举止的操作(历史史官)2.日志的级别 五种级别3.日志模块要求 代码无需掌握但是得会CV并稍作修改importlogg......
  • python基础:subprocess子进程模块
    子进程模块subprocess模块模拟操作系统,执行命令并获取结果subprocess模块允许我们启动一个新进程,并连接到它们的输入/输出/错误管道,从而获取返回值。importsubproce......
  • python基础:logging日志模块
    目录logging日志模块1.如何理解日志2.日志的级别3日志的组成4日志配置字典logging日志模块1.如何理解日志​简单的理解为记录数据行为的文件。​......
  • Python基础22
    今日内容概要hashlib加密模块subprocess模块logging日志模块软件开发主要流程今日内容详细hashlib加密模块1.何为加密 将明文数据处理成密文数据让人无法看懂2......