我无法使用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'