我正在一个项目中,我必须计算实时视频供稿中检测到的人之间的距离。为此,我遵循以下管道:
1. Detect person using MobilenetSSD Caffe model
2. Extract bouding box of the persons detected
3. Calculate the centroid of each bouding box
4. Calculate the distance between the each centroid
下面是代码段:
for (id1, p1), (id2, p2) in combinations(centroid_dict.items(), 2):
ec_dist = dist.euclidean((p1[0], p1[1]), (p2[0], p2[1]))
print("Euclidean distance {}".format(ec_dist))
在上面的代码中,id1
和id2
是两个人的ID。 p1[0]
和p1[1]
是人员1的x
和y
坐标,p2[0]
p2[1]
是人员2的x
y
坐标。我正在计算两个人的euclidean
和x
坐标之间的y
距离。
现在让两个人彼此站在2米的距离上,为此,我在代码250
中得到了欧式距离。现在让我们说,如果这两个人现在离摄像机有点远,但是他们之间的距离仍然是2米,那么在这种情况下,我得到的欧氏距离为343,这意味着如果代码中的人之间的距离正在增加离相机有点远。
最初,我认为无论人们在框架中的什么位置,此逻辑都可以正常工作,但看起来好像不起作用。谁能帮我提出一些很好的解决方案。请帮忙。谢谢