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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

PCL笔记二:PCD解析;PCD读取;PCD与XYZ转换;

發(fā)布時間:2023/12/16 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PCL笔记二:PCD解析;PCD读取;PCD与XYZ转换; 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

PCD文件解析

上一節(jié)中,我們獲取的PCD格式點云文件,內(nèi)容如下:

# .PCD v0.7 - Point Cloud Data file format VERSION 0.7 FIELDS x y z SIZE 4 4 4 TYPE F F F COUNT 1 1 1 WIDTH 5 HEIGHT 1 VIEWPOINT 0 0 0 1 0 0 0 POINTS 5 DATA ascii 1.28125 577.09375 197.9375 828.125 599.03125 491.375 358.6875 917.4375 842.5625 764.5 178.28125 879.53125 727.53125 525.84375 311.28125

PCD文由 “頭文件 + 點云數(shù)據(jù)” 構(gòu)成,頭文件聲明了該點云數(shù)據(jù)集的基本特性。

第零行為注釋:標明文件類型。

第一行:VERSION

  • 指定PCD文件的版本,由0.7可知該點云數(shù)據(jù)集是0.7版本的。

第二行:FIELDS

  • 指定本點云數(shù)據(jù)集中任意一個點可以有的維度信息和其他附加信息。如:FIELDS x y z? 指每個點都有xyz三個維度信息,FIELDS x y z rgb 指每個點除了xyz維度信息外還有顏色信息等。

第三行:SIZE

  • 儲存每個維度信息占用的字節(jié)數(shù)(byte)。1指用char型數(shù)據(jù)存儲維度信息,2指用short型數(shù)據(jù)存儲維度信息,4指用int或float型數(shù)據(jù)存儲維度信息,8指用double型數(shù)據(jù)存儲維度信息。

第四行:TYPE

  • 用字符指定每一個維度的數(shù)據(jù)類型。
    • I表示有符號類型:int8(char),int16(short),int32(int);
    • U表示無符號類型:uint8(unsigned char),uint 16(unsigned short),uint32(unsigned int);
    • F表示浮點型float和double。

第五行:COUNT

  • 每個維度包含的元素個數(shù)。

第六行:WIDTH

  • 點云數(shù)據(jù)集可分為有序數(shù)據(jù)集無序數(shù)據(jù)集兩種。
    • 有序數(shù)據(jù)集類似矩陣,有行列之分,無序數(shù)據(jù)集則無行列之分。
    • 根據(jù)數(shù)據(jù)集是否有序,WIDTH由不同的含義。
      • 對有序數(shù)據(jù)集而言:表示數(shù)據(jù)集的寬度(每行點的數(shù)目);
      • 對于無序數(shù)據(jù)集而言:表示數(shù)據(jù)集中點的總數(shù)(和下面的POINTS一樣)。

第七行:HEIGHT

  • 對有序數(shù)據(jù)集而言:表示數(shù)據(jù)集的高度(行數(shù));
  • 對于無序數(shù)據(jù)集而言:被設置為1,用于聲明一個數(shù)據(jù)集是否有序

第八行:VIEWPOINTS

  • 數(shù)據(jù)集中點云的獲取視點。視點信息被指定為“平移(txtytz) + 四元數(shù)(qwqxqyqz)”,默認值是:VIEWPOINT 0 0 0 1 0 0 0

第九行:POINTS

  • 點云中點的總數(shù),從0.7版本就開始顯得有點多余,可能會在后續(xù)版本中舍去這個參數(shù)。

第十行:DATA

  • 指定存儲點云數(shù)據(jù)的數(shù)據(jù)存儲格式:ASCLL碼或二進制數(shù)據(jù)。

后續(xù)是數(shù)據(jù)部分:

  • 以ASCLL碼存儲的點云數(shù)據(jù),每一個點占據(jù)一行,“nan”表示不存在或非法的數(shù)據(jù)。

PCD文件讀取

#include<iostream> #include<pcl/io/pcd_io.h> #include<pcl/point_types.h> using namespace std;int main() {pcl::PointCloud < pcl::PointXYZ >::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);// 創(chuàng)建點云指針。// 讀入PCD格式文件,如果文件不存在,返回-1if (pcl::io::loadPCDFile<pcl::PointXYZ>("test_pcd_file.pcd", *cloud) == -1) {PCL_ERROR("Couldn't read file test_pcd_file.pcd\n");return -1;}cout << "Loaded "<< cloud->points.size()<< " data points from test_pcd_file.pcd with the following fields:"<< endl;// 顯示前5個點:for (size_t i = 0; i < 5; i++){cout << cloud->points[i].x << "\t" << cloud->points[i].y << "\t" << cloud->points[i].z << endl;}system("pause");return 0; }

xyz文件轉(zhuǎn)pcd文件

  • xyz格式數(shù)據(jù)一般每行有6列數(shù)據(jù)前3列分別為點的 x,y,z坐標后3列為點的法向量,一般以空格分隔
#include<iostream> #include<pcl/io/pcd_io.h> #include<pcl/console/print.h> #include<pcl/console/parse.h> #include <boost/algorithm/string.hpp>using namespace std; using namespace pcl; using namespace pcl::io; using namespace pcl::console;bool loadCloud(const string& filename, PointCloud<PointNormal>& cloud) {ifstream fs;fs.open(filename.c_str(), ios::binary);if (!fs.is_open() || fs.fail()){PCL_ERROR("Could not open file '%s'! Error : %s\n", filename.c_str(), strerror(errno));fs.close();return(false);}string line;vector<string> st;while (!fs.eof()){getline(fs, line);if (line.empty()){continue;}boost::trim(line);// #include <boost/algorithm/string.hpp>包含頭文件,才可以使用split分割。boost::split(st, line, boost::is_any_of(" "), boost::token_compress_on);// 分割符是空格。//cout << "st.size() = " << st.size() << endl;if (st.size() != 6)continue;pcl::PointNormal point;point.x = float(atof(st[0].c_str()));point.y = float(atof(st[1].c_str()));point.z = float(atof(st[2].c_str()));point.normal[0]= float(atof(st[3].c_str()));point.normal[1]= float(atof(st[4].c_str()));point.normal[2]= float(atof(st[5].c_str()));cloud.push_back(point);}fs.close();cloud.width = uint32_t(cloud.size());cloud.height = 1;cloud.is_dense = true;return (true); }int main() {string XYZfileName = "camel.xyz";string PCDfileName = "camel.pcd";PointCloud<PointNormal> cloud;if (!loadCloud(XYZfileName, cloud))return (-1);cout << cloud.size() << endl;//system("pause");pcl::io::savePCDFileASCII(PCDfileName, cloud);system("pause");return 0; }

總結(jié)

以上是生活随笔為你收集整理的PCL笔记二:PCD解析;PCD读取;PCD与XYZ转换;的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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