在导入点云时检测是否有错误并显示警报消息,而无需关闭应用程序PCL和C++

问题描述 投票:0回答:1

我正在尝试将点云导入到我用 PCL 和 C++ 库编写的程序中。该程序必须能够加载不同的文件,并且如果在编码时遇到错误,则表明存在错误,但无论如何都不会导致应用程序中断。

现在导致程序中断的点云标题如下。

ply
format ascii 1.0
comment PCL generated
element vertex 88655
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
element face 0
element camera 1
property float view_px
property float view_py
property float view_pz
property float x_axisx
property float x_axisy
property float x_axisz
property float y_axisx
property float y_axisy
property float y_axisz
property float z_axisx
property float z_axisy
property float z_axisz
property float focal
property float scalex
property float scaley
property float centerx
property float centery
property int viewportx
property int viewporty
property float k1
property float k2
end_header

我正在尝试将云导入为

pcl::PointCloud<pcl::PointXYXRGB>
以及
pcl::PolygonMesh
。在这种情况下,云没有网格信息,但据我注意到其他云,系统能够检测到它并导入它,没有任何问题。

我用来导入文件的代码是:

std::string filepath = "cloud.ply";
// Load cloud
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
pcl::PolygonMesh::Ptr cloud_mesh (new pcl::PolygonMesh);

if (pcl::io::loadPLYFile(filepath_cloud, *cloud) == -1) {
  std::cerr << "Error reading cloud" << std::endl;
}
std::cout << "Reading cloud OK" << std::endl;

if (pcl::io::loadPolygonFilePLY(filepath_cloud, * cloud_mesh) == -1) {
  std::cerr << "Error reading cloud mesh" << std::endl;
}
std::cout << "Reading cloud mesh OK" << std::endl;

使用此代码,我可以获得这些消息,直到应用程序崩溃:

[pcl::PLYReader] C:/Users/Ale/Documents/tmp/cloud.ply:25: property 'float32 focal' of element 'camera' is not handled
[pcl::PLYReader] C:/Users/Ale/Documents/tmp/cloud.ply:26: property 'float32 scalex' of element 'camera' is not handled
[pcl::PLYReader] C:/Users/Ale/Documents/tmp/cloud.ply:27: property 'float32 scaley' of element 'camera' is not handled
[pcl::PLYReader] C:/Users/Ale/Documents/tmp/cloud.ply:28: property 'float32 centerx' of element 'camera' is not handled
[pcl::PLYReader] C:/Users/Ale/Documents/tmp/cloud.ply:29: property 'float32 centery' of element 'camera' is not handled
[pcl::PLYReader] C:/Users/Ale/Documents/tmp/cloud.ply: property 'float32 k1' of element 'camera' is not handled
[pcl::PLYReader] C:/Users/Ale/Documents/tmp/cloud.ply: property 'float32 k2' of element 'camera' is not handled
Reading cloud OK
Warning:  Can't find property 'vertex_indices' in element 'face'

因此,您可以看到,直到将其导入到

pcl::PolygonMesh
时,都没有发生错误。我想要管理的是,虽然不可能被读作
polygonmesh
,但应用程序不会关闭。换句话说,将
pcl::PolygonMesh
的读取放入
try{}
catch{}
中,以便它在可能的情况下简单地读取文件。但我不知道这是否可以做到,或者什么,如果可以做到,该怎么做。

c++ graphics 3d point-cloud-library
1个回答
1
投票

尝试

pcl::io::loadPLYFile()
(https://pointclouds.org/documentation/group__io.html#ga0cfc645cc531647728e16088b6342204) 而不是
pcl::io::loadPolygonFilePLY()

© www.soinside.com 2019 - 2024. All rights reserved.