首页 > 解决方案 > PCL 读取 PLY 错误

问题描述

我无法使用 PCL 读取 PLY 文件,并且尝试了各种输入,甚至是斯坦福兔子。我得到的错误是

parse error: couldn't read the magic string
[pcl::PLYReader::read] problem parsing header!
[pcl::PLYReader::read] problem parsing header!
Couldn't read ply file 

看这里https://github.com/PointCloudLibrary/pcl/blob/master/io/src/ply/ply_parser.cpp它正在尝试读取与文件内容匹配的4个字符

ply
format ascii 1.0
element vertex 3511
property double x
property double y
property double z
element face 0
property list int int vertex_indices
end_header

编辑

编码

if (pcl::io::loadPLYFile(filename, out_pcd) == -1) {
    PCL_ERROR("Couldn't read ply file \n");
    return 0;
}

我已经在 meshlab 中成功打开了文件,所以我不认为文件格式错误。

编辑 2

我的 C++ 不是很好,我不确定如何深入调试 PCL,因此将他们的代码复制到我的main(). 它运行良好,可以解析魔术字符串而不会触发上述错误(!istream)。

// PCL SRC START
std::ifstream istream (pathToInput, std::ios::in | std::ios::binary);

std::string line;
int line_number_ = 0;

char line_delim = '\n';
int char_ignore_count = 0;

// magic
char magic[4];
istream.read (magic, 4);

// Check if CR/LF, setup delim and char skip
if (magic[3] == '\r')
{
    istream.ignore (1);
    line_delim = '\r';
    char_ignore_count = 1;
}

++line_number_;
if (!istream)
{
  if (error_callback_)
    error_callback_ (line_number_, "parse error: couldn't read the magic string");
  return false;
}
// PCL SRC END

// VALUE OF magic IS 'ply\r'

标签: c++point-cloud-library

解决方案


推荐阅读