【问题标题】:How can I view Point Clouds?如何查看点云?
【发布时间】:2018-10-03 17:53:40
【问题描述】:

我正在使用名为ORB SLAM 2 的开源代码。据我所知,ORB SLAM 2 不保存地图。所以为了保存点(点云),我在 System.cc 中包含了一个小代码:

void System::CreatePCD(const string &filename){
    cout << endl << "Saving map points to " << filename << endl;

    vector<MapPoint*> vMPs = mpMap->GetAllMapPoints();

    // Create PCD init string
    std::string begin = std::string("# .PCD v.7 - Point Cloud Data file format\nVERSON .7\n");
    begin += "FIELDS x y z\n";
    begin += "SIZE 4 4 4\n";
    begin += "TYPE F F F\n";
    begin += "COUNT 1 1 1\n";

    int width = vMPs.size();
    begin += "WIDTH ";
    begin += std::to_string(width);
    begin += "\nHEIGHT 1\n";
    begin += "VIEWPOINT 0 0 0 1 0 0 0\n";
    begin += "POINTS ";
    begin += std::to_string(width);
    begin += "\nDATA ascii\n";

    // File Opening:
    ofstream f;
    f.open(filename.c_str());
    f << begin;

    // Write the point clouds:
    for(size_t i= 0; i < vMPs.size(); ++i){
        MapPoint *pMP = vMPs[i];
        if (pMP->isBad()) continue;
        cv::Mat MPPositions = pMP->GetWorldPos();
        f << setprecision(7) << MPPositions.at<float>(0) << " " << 
        MPPositions.at<float>(1) << " " << MPPositions.at<float>(2) << endl;
    }

    f.close();
    cout << endl << "Map Points saved!" << endl;

  }
}

如您所见,我已经包含了 PCL 版本 7 的所有必要内容。我新创建的点云文件如下所示:

# .PCD v.7 - Point Cloud Data file format
VERSON .7
FIELDS x y z
SIZE 4 4 4
TYPE F F F
COUNT 1 1 1
WIDTH 1287
HEIGHT 1
VIEWPOINT 0 0 0 1 0 0 0
POINTS 1287
DATA ascii
0.1549043 -0.3846602 0.8497394
0.01127081 -0.2949406 0.9007485
0.6072361 -0.3651089 1.833479
…

但每当我尝试通过运行 pcl_viewer pointclouds.pcd 来可视化文件时,我都会收到错误消息:

> Loading pointcloud.pcd [pcl::PCDReader::readHeader] No points to read

我做错了什么?

【问题讨论】:

    标签: ros point-cloud-library point-clouds


    【解决方案1】:

    PCD(点云数据)文件格式为well documented。乍一看,您的文件似乎是正确的,但您的代码中有一个小错字(缺少 I):

    std::string begin = std::string("# .PCD v.7 - Point Cloud Data file format\nVERSON .7\n");
    

    代码写道:

    版本 .7

    正确的是:

    VERS开 .7

    快速查看source code 会发现拼写错误会导致提前退出,因为它不匹配有效参数。这意味着所有以下参数,包括 POINTS,都将被忽略。结果将是 No points to read 错误。

    修正错字,您的文件将按预期工作。

    【讨论】:

      【解决方案2】:

      您的格式似乎有错字:

      // Create PCD init string
      std::string begin = std::string("# .PCD v.7 - Point Cloud Data file format\nVERSON .7\n");
      

      VERSON 被写入而不是 VERSION(它缺少 I)。

      【讨论】:

        猜你喜欢
        • 2020-08-03
        • 2018-11-19
        • 2013-12-07
        • 2023-01-22
        • 2021-11-26
        • 1970-01-01
        • 1970-01-01
        • 2017-12-31
        • 2015-11-03
        相关资源
        最近更新 更多