【问题标题】:Reading ascii point clouds in x y z r g b format以 x y z r g b 格式读取 ascii 点云
【发布时间】:2020-11-25 22:08:36
【问题描述】:

我在一个 txt 文件中有一个点云,其中每一行的格式如下:

x y z r g b

我应该如何将其读入 PCL 中的 XYZRGB 点云? PCL 中的 ascii 阅读器或 pcdreader 期望格式为 x y z rgb 形式,其中 rgb 是一个代表 r g b 通道的值。

有没有什么方法可以读取我上面提到的格式的点云,而不必自己修改点云?

编辑:添加我当前的代码和点云中的一些行以响应评论

    pcl::ASCIIReader ptsReader;
    ptsReader.setSepChars(" ");
    ptsReader.read(m_pointCloudFilePath,*m_pointCloudRef);

如果m_pointCloudRef 的类型为:pcl::PointCloud<pcl::PointXYZRGB>::Ptr,则此代码不适用于运行时错误消息:Failed to find match for field 'rgb'.。如果m_pointCloudRef 的类型为pcl::PointCloud<pcl::PointXYZ>::Ptr,则相同的代码有效(这也意味着我正在使用每行为x y z 的ASCII 文件)

以下是我正在使用的点云的前几行:

0.792 9.978 12.769 234 220 209
0.792 9.978 12.768 242 228 217
0.794 9.978 12.771 241 227 214
0.794 9.978 12.770 247 231 218
0.793 9.979 12.769 234 217 207
0.793 9.979 12.768 238 224 213
0.794 9.979 12.767 239 227 215
0.795 9.978 12.772 230 221 206
0.795 9.978 12.771 243 229 216
0.795 9.979 12.770 242 226 213
0.795 9.979 12.769 235 218 208
0.795 9.979 12.768 235 221 210
0.795 9.979 12.767 240 228 216
0.795 9.979 12.766 240 230 218
0.795 9.979 12.765 240 230 218
0.795 9.978 12.763 244 234 222

【问题讨论】:

  • 你目前拥有的代码是什么?
  • 请用实数显示每个文件的几行实际行,而不是您当前拥有的概念化行。另外,您运行什么操作系统?
  • @MarkSetchell 在 OSX 上运行此代码
  • pcdreader 期望在第一行代替 234 220 209 什么?
  • 一种表示将所有三个值打包在一个表示中。就像这里提到的:docs.pointclouds.org/1.7.0/structpcl_1_1_point_x_y_z_r_g_b.html

标签: c++ point-cloud-library point-clouds


【解决方案1】:

如果您不想更改云在磁盘上的保存方式并且只需要使用极少数云类型,您可以手动读取它们。

 bool loadAsciCloud(std::string filename, pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud)
{
    std::cout << "Begin Loading Model" << std::endl;
    FILE* f = fopen(filename.c_str(), "r");

    if (NULL == f)
    {
        std::cout << "ERROR: failed to open file: " << filename << endl;
        return false;
    }

    float x, y, z;
    char r, g, b;

    while (!feof(f))
    {
        int n_args = fscanf_s(f, "%f %f %f %c %c %c", &x, &y, &z, &r, &g, &b);
        if (n_args != 6)
            continue;

        pcl::PointXYZRGB point;
        point.x = x; 
        point.y = y; 
        point.z = z;
        point.r = r;
        point.g = g;
        point.b = b;

        cloud->push_back(p);
    }

    fclose(f);

    std::cout << "Loaded cloud with " << cloud->size() << " points." << std::endl;

    return cloud->size() > 0;
}

【讨论】:

    【解决方案2】:

    您需要引用类型:pcl::PointCloud\&lt;pcl::PointXYZRGB\&gt;::Ptr

    【讨论】:

      猜你喜欢
      • 2020-05-08
      • 1970-01-01
      • 1970-01-01
      • 2021-04-25
      • 1970-01-01
      • 2019-05-26
      • 1970-01-01
      • 2022-06-19
      • 1970-01-01
      相关资源
      最近更新 更多