解决PCL报错: Assertion `point_representation_->isValid (point) && “Invalid (NaN, Inf) point coordinates

参考资料:

  1. https://github.com/PointCloudLibrary/pcl/blob/master/kdtree/include/pcl/kdtree/impl/kdtree_flann.hpp
  2. https://blog.csdn.net/AileenNut/article/details/80170146

先说结论: 如果在使用PCL库时遇到了上述报错, 很有可能是程序中调用nearestKSearch()函数处出现了Nan点, 需要对这些点进行剔除或跳过处理.

  1. 首先, 需要定位到出错的代码, 这里调用了nearestKSearch()
  2. 其次, 可以在函数nearestKSearch()之前打印出nearestKSearch()中第一个参数的内容, 以确定是否是出现了Nan点, 进而导致程序终止, 如:
std::cout << "point value: " << point.x << " " << point.y << " " << point.z << " " << point.intensity << std::endl; 

若是出现了Nan点导致的程序挂掉, 那么需要对这些点进行剔除或跳过处理. 剔除的方式可以参考此博客, 这里提供一种跳过处理的方式:

if (!pcl_isfinite(point.x) || !pcl_isfinite(point.y) || !pcl_isfinite(point.z) || !pcl_isfinite(point.intensity))
{
  continue;
}

你可能感兴趣的:(PCL)