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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python读取pcd文件_PCL读取PCD文件的数据

發(fā)布時(shí)間:2023/12/16 python 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python读取pcd文件_PCL读取PCD文件的数据 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.pcd文件——rabbit.pcd

新建項(xiàng)目pcl

rabbit.pcd 和pcl.cpp在同一目錄下

2.讀取文件

(1)顯示數(shù)據(jù)

#include#include#include

int main(int argc, char**argv) {

//創(chuàng)建了一個(gè)名為cloud的指針,儲(chǔ)存XYZ類型的點(diǎn)云數(shù)據(jù)

pcl::PointCloud<:pointxyz>::Ptr cloud(new pcl::PointCloud<:pointxyz>);//

//*打開點(diǎn)云文件

if (pcl::io::loadPCDFile<:pointxyz>("rabbit.pcd", *cloud) == -1) {

PCL_ERROR("Couldn't read file rabbit.pcd\n");return(-1);

}

std::cout<< "Loaded:" << cloud->width*cloud->height<points.size(); ++i) {

std::cout<< " " << cloud->points[i].x << " " << cloud->points[i].y << " " << cloud->points[i].z << " " <<:endl>

}

system("pause");return 0;

}

文件里的數(shù)據(jù)就一次顯示出來了

說明:

PointCloud是PCL中的一個(gè)基類,pcl::PointCloud<:pointxyz>::Ptr是一個(gè)Boost共享指針

PointCloud中的數(shù)據(jù)域

width(int),如果是無組織,無結(jié)構(gòu)的點(diǎn)云數(shù)據(jù),表示點(diǎn)云的個(gè)數(shù);如果是有結(jié)構(gòu)的點(diǎn)云數(shù)據(jù),表示點(diǎn)云數(shù)據(jù)集一行的點(diǎn)數(shù)。

height(int),如果是無結(jié)構(gòu)的點(diǎn)云數(shù)據(jù),height=1;如果是有結(jié)構(gòu)的點(diǎn)云數(shù)據(jù),height表示點(diǎn)云總行數(shù)。

points(std::vector)存儲(chǔ)了數(shù)據(jù)類型為PointT的一個(gè)動(dòng)態(tài)數(shù)組。

PointXYZ 是最常見的一個(gè)點(diǎn)數(shù)據(jù)類型,它只包含三維X,Y,Z坐標(biāo)信息

X:points[i].x

size_t 整型,保存一個(gè)整數(shù),記錄一個(gè)大小(size)

points.size() 表示點(diǎn)云數(shù)據(jù)大小

(2)數(shù)據(jù)可視化

#include#include#include#include

int main(int argc, char**argv) {

pcl::PointCloud<:pointxyz>::Ptr cloud(new pcl::PointCloud<:pointxyz>);//

//*打開點(diǎn)云文件

if (pcl::io::loadPCDFile<:pointxyz>("rabbit.pcd", *cloud) == -1) {

PCL_ERROR("Couldn't read file rabbit.pcd\n");return(-1);

}

std::cout<< cloud->points.size() <<:endl>

pcl::visualization::CloudViewer viewer("cloud viewer");

viewer.showCloud(cloud);while (!viewer.wasStopped()) {

}

system("pause");return 0;

}

運(yùn)行結(jié)果

轉(zhuǎn)一下滾輪

修改背景色

#include#include#include#include

void viewerOneOff(pcl::visualization::PCLVisualizer&viewer) {

viewer.setBackgroundColor(1.0f, 0.5f, 1.0f);

}int main(int argc, char**argv) {

pcl::PointCloud<:pointxyz>::Ptr cloud(new pcl::PointCloud<:pointxyz>);//*打開點(diǎn)云文件

if (pcl::io::loadPCDFile<:pointxyz>("rabbit.pcd", *cloud) == -1) {

PCL_ERROR("Couldn't read file rabbit.pcd\n");return(-1);

}

std::cout<< cloud->points.size() <<:endl>

pcl::visualization::CloudViewer viewer("cloud viewer");

viewer.showCloud(cloud);

viewer.runOnVisualizationThreadOnce(viewerOneOff);

system("pause");return 0;

}

輸出文字

#include#include#include#include

intuser_data;void viewerOneOff(pcl::visualization::PCLVisualizer&viewer) {

viewer.setBackgroundColor(1.0f, 0.5f, 1.0f);

}voidviewerPsycho(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(),20, 100, "text", 0);//this is to set the coordination of text "Once per viewer loop:"

user_data++;

}int main(int argc, char**argv) {

pcl::PointCloud<:pointxyz>::Ptr cloud(new pcl::PointCloud<:pointxyz>);//*打開點(diǎn)云文件

if (pcl::io::loadPCDFile<:pointxyz>("rabbit.pcd", *cloud) == -1) {

PCL_ERROR("Couldn't read file rabbit.pcd\n");return(-1);

}

std::cout<< cloud->points.size() <<:endl>

pcl::visualization::CloudViewer viewer("cloud viewer");

viewer.showCloud(cloud);

viewer.runOnVisualizationThreadOnce(viewerOneOff);

viewer.runOnVisualizationThread(viewerPsycho);

system("pause");return 0;

}

總結(jié)

以上是生活随笔為你收集整理的python读取pcd文件_PCL读取PCD文件的数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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