import trimesh
import numpy as np
import time
if __name__ == '__main__':
path = 'box.obj' # 3D mesh
path_qem = 'box-qem.obj'
mesh_orig = trimesh.load(path)
mesh_qem = trimesh.load(path_qem)
points_meshA = mesh_orig.vertices
points_meshB = mesh_qem.vertices
time_start = time.time()
min_dis_sequen_A2B = np.ones(len(points_meshA))
for meshA_index in range(len(points_meshA)):
#min_dis_sequen = np.ones(len(points_qem))
min_dis = 9999
for meshB_index in range(len(points_meshB)):
dis = np.linalg.norm(points_meshA[meshA_index] - points_meshB[meshB_index])
if dis < min_dis:
min_dis = dis
min_dis_sequen_A2B[meshA_index] = min_dis
dis_A2B = max(min_dis_sequen_A2B)
min_dis_sequen_B2A = np.ones(len(points_meshB))
for meshB_index in range(len(points_meshB)):
min_dis = 9999
for meshA_index in range(len(points_meshA)):
dis = np.linalg.norm(points_meshB[meshB_index] - points_meshA[meshA_index])
if dis < min_dis:
min_dis = dis
min_dis_sequen_B2A[meshB_index]=min_dis
dis_B2A = max(min_dis_sequen_B2A)
huasdorff_distance = max(dis_A2B, dis_B2A)
time_end = time.time()
print("time1", time_end - time_start)
print('the huasdorff distance is: ', huasdorff_distance)
计算hausdorff distance 源码
最新推荐文章于 2023-06-05 09:53:40 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)