我使用的是名为球体扣球2的开放源代码。据我所知,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我做错了什么?
发布于 2018-10-03 07:27:31
发布于 2018-10-03 07:26:01
看起来您的格式中有一个错误:
// Create PCD init string
std::string begin = std::string("# .PCD v.7 - Point Cloud Data file format\nVERSON .7\n");VERSON是正在编写的,而不是VERSION (它缺少一个I)。
https://stackoverflow.com/questions/52605176
复制相似问题