日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

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

發(fā)布時間:2023/11/27 生活经验 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python,C++中点云 .las转.pcd 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Python las 讀取可以參考之前的博客,用laspy 或者 pylas

今天主要解決Python、C++ 的las轉(zhuǎn)pcd文件

1. Python .las轉(zhuǎn).pcd

# -*- coding: utf-8 -*-
# 讀取las文件 并保留為 XYZI格式的pcd文件import pcl  # 調(diào)用pcl保留pcd文件
from laspy.file import File  # las文件讀取
import numpy as np  # np數(shù)組處理
import time  # 計算耗時# las讀取轉(zhuǎn)為 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 clouddef 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轉(zhuǎn).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數(shù)據(jù)點的個數(shù)pcl::PointCloud<pcl::PointXYZI> cloud;cloud.width    = nbPoints;	//保證與las數(shù)據(jù)點的個數(shù)一致	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數(shù)據(jù)的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數(shù)據(jù)的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);
}

總結(jié)

以上是生活随笔為你收集整理的Python,C++中点云 .las转.pcd的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。