def find_nn(point, neighborhood):
"""
Finds the nearest neighborhood of a vector.
Args:
point (float array): The initial point.
neighborhood (numpy float matrix): The points that are around the initial point.
Returns:
float array: The point that is the nearest neighbor of the initial point.
integer: Index of the nearest neighbor inside the neighborhood list
"""
min_dist = float('inf')
nn = neighborhood[0]
nn_idx = 0
for i in range(len(neighborhood)):
neighbor = neighborhood[i]
dist = cv2.norm(point - neighbor)
if dist < min_dist:
min_dist = dist
nn = neighbor
nn_idx = i
return nn, nn_idx
评论列表
文章目录