Advertisement

配准评价指标双向Hausdorff距离计算

阅读量:

目录

1 原理介绍

2 数学公式推导

2.1 单向距离定义:

2.2 双向Hausdorff距离:

3 计算流程

4 示例代码

该方法广泛应用于点云处理与配准领域,在这一过程中起到关键作用

1 原理介绍

Hausdorff距离用于度量两个点集之间的最大值与最小值的距离。对于两个点集A和B来说,双向Hausdorff距离d_H(A,B)被定义为:

其中,单向Hausdorff距离从 A 到 B 定义为:

而从 B 到 A 的距离为:

双侧Hausdorff距离等于这些单向距离中的最大值,并用于衡量这两组点云之间的最大偏差程度。

2 数学公式推导

2.1 单向距离定义

从集合 A 到集合 B:

从集合 B 到集合 A:

2.2 双向Hausdorff距离

  • 组合以上两个方向的距离:

3 计算流程

输入 :获取两个点云数据集 AA 和 BB。

计算单向距离

  • 基于KD树和暴力搜索技术来计算从AA到BB的单向Hausdorff距离。
    • 通过使用KD树和暴力搜索来计算BB到AA之间的单向Hausdorff距离。

取最大值 :取两个单向Hausdorff距离的最大值作为双向Hausdorff距离。

4 示例代码

复制代码
 #include <pcl/point_types.h>

    
 #include <pcl/io/pcd_io.h>
    
 #include <pcl/kdtree/kdtree_flann.h>
    
 #include <iostream>
    
 #include <vector>
    
 #include <limits>
    
  
    
 typedef pcl::PointXYZ PointT;
    
 typedef pcl::PointCloud<PointT> PointCloudT;
    
  
    
 double computeSingleDirectionalHausdorffDistance(const PointCloudT::Ptr& cloudA, const PointCloudT::Ptr& cloudB) {
    
     pcl::KdTreeFLANN<PointT> kdtree;
    
     kdtree.setInputCloud(cloudB);
    
  
    
     double maxDist = 0.0;
    
  
    
     for (const auto& pointA : cloudA->points) {
    
     std::vector<int> nearestNeighborIndex(1);
    
     std::vector<float> nearestNeighborDistanceSquared(1);
    
  
    
     if (kdtree.nearestKSearch(pointA, 1, nearestNeighborIndex, nearestNeighborDistanceSquared) > 0) {
    
         double distance = std::sqrt(nearestNeighborDistanceSquared[0]);
    
         if (distance > maxDist) {
    
             maxDist = distance;
    
         }
    
     }
    
     }
    
     return maxDist;
    
 }
    
  
    
 int main(int argc, char** argv) {
    
     PointCloudT::Ptr cloudA(new PointCloudT);
    
     PointCloudT::Ptr cloudB(new PointCloudT);
    
  
    
     if (pcl::io::loadPCDFile("source.pcd", *cloudA) == -1 ||
    
     pcl::io::loadPCDFile("target.pcd", *cloudB) == -1) {
    
     PCL_ERROR("Couldn't read file\n");
    
     return -1;
    
     }
    
  
    
     double hausdorffAB = computeSingleDirectionalHausdorffDistance(cloudA, cloudB);
    
     double hausdorffBA = computeSingleDirectionalHausdorffDistance(cloudB, cloudA);
    
     double symmetricHausdorff = std::max(hausdorffAB, hausdorffBA);
    
  
    
     std::cout << "Hausdorff Distance AB: " << hausdorffAB << std::endl;
    
     std::cout << "Hausdorff Distance BA: " << hausdorffBA << std::endl;
    
     std::cout << "Symmetric Hausdorff Distance: " << symmetricHausdorff << std::endl;
    
  
    
     return 0;
    
 }

全部评论 (0)

还没有任何评论哟~