【发布时间】: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