我正在制作一个自己的质心跟踪器来跟踪视频中的一些对象
从我的检测函数中,我从给定的数据中得到一个列表,列表的格式如下:
[startX, startY, endX, endY,cX,cY,score]
这是检测到两个对象时的示例:
[[10,10,200,200,105,105,0.9],[350,120,410,500,380,310,0.7]]
我想做一个函数,从给定的质心点X,Y,从我的跟踪器返回列表中最近的(cX,cY)
最好的方法是什么?所有质心跟踪器都使用欧几里德算法来计算距离。这是最好的方式吗?有人能给我解释一下吗
我在一个网站上找到了这个功能:
def pClosest(points, K):
points.sort(key = lambda K: K[0]**2 + K[1]**2)
return points[:K]
# Driver program
points = [[3, 3], [5, -1], [-2, 4]]
K = 2
print(pClosest(points, K))
我怎样才能把它转换成我所需要的
您可以使用
np.linalg.norm
和ord=2
来获得两个numpy数组之间的欧几里德距离。应用于您的示例,您可以使用以下内容:然后您可以按如下方式使用它:
我的一位朋友向我发送了此功能:
这很有效
相关问题 更多 >
编程相关推荐