【问题标题】:Read and write pcd file without PCL (Point Cloud library)无需PCL(点云库)读写pcd文件
【发布时间】:2020-08-02 13:38:48
【问题描述】:

我正在尝试编写一个无需 PCD(点云库)即可读写 PCL 文件的程序, 我可以毫无问题地读取每个点的位置, 但是 RGB 值是用 uint32_t 写的,我不知道如何读取这种格式并将其转换为 RGB 值。

# .PCD v0.7 - Point Cloud Data file format
VERSION 0.7
FIELDS x y z rgb
SIZE 4 4 4 4
TYPE F F F F
COUNT 1 1 1 1
WIDTH 100
HEIGHT 1
VIEWPOINT 0 0 0 1 0 0 0
POINTS 100
DATA ascii
-0.031568773 -0.99000001 0.99000013 2.3418052e-038
0.031568673 -0.98999995 0.99000013 2.3418052e-038
-0.031568974 -0.54999995 0.77000004 2.3418052e-038
0.031568889 -0.54999995 0.77000004 2.3418052e-038

将最后一个值 (2.3418052e-038) 转换为 RGB 值?

有没有办法在没有点云库的情况下做到这一点?

谢谢。

【问题讨论】:

标签: c++ point-cloud-library uint32-t


【解决方案1】:

请阅读以下来自维基百科的 PLY 格式数据,

https://en.wikipedia.org/wiki/PLY_(file_format)

添加示例 sn-p 以编写 PLY 文件,

std::string fname = "sample.ply";
std::ofstream out(fname);
out << "ply\n";
out << "format ascii 1.0\n";
out << "comment\n";
out << "element vertex " << cloud5->points.size() << "\n";
out << "property float" << sizeof(float) * 8 << " x\n";
out << "property float" << sizeof(float) * 8 << " y\n";
out << "property float" << sizeof(float) * 8 << " z\n";
out << "property uchar red\n";
out << "property uchar green\n";
out << "property uchar blue\n";
out << "property list uchar int vertex_indices\n";
out << "end_header\n";
out.close();

out.open(fname, std::ios_base::app);
for (size_t i = 0; i < cloud5->points.size(); ++i)
{
    out << cloud5->points[i].x << " " << cloud5->points[i].y << " " << cloud5->points[i].z << " " << (int)cloud5->points[i].r 
        << " " << (int)cloud5->points[i].g << " " << (int)cloud5->points[i].b << "\n";
}
out.close();

【讨论】:

    猜你喜欢
    • 2012-10-07
    • 1970-01-01
    • 1970-01-01
    • 2021-11-14
    • 2017-10-30
    • 1970-01-01
    • 1970-01-01
    • 2018-04-14
    • 1970-01-01
    相关资源
    最近更新 更多