如何使用python opencv计算两个人之间的距离? [英] How to calculate distance between two person using python opencv?

查看:141
本文介绍了如何使用python opencv计算两个人之间的距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,我必须计算实时视频供稿中检测到的人之间的距离。为此,我遵循以下管道:

I am working on a project where I have to calculate the distance between the detected persons in live video feed. To do this I am following the below pipeline:

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] x y 坐标1人和 p2 [0] p2 [1] 是person2的 x y 坐标。我正在计算 x y 之间的 euclidean 距离两个人的坐标。

In above code id1 and id2 are the id of the two persons. p1[0] and p1[1] are the x and y coordinate of person 1 and p2[0] p2[1] are the x y coordinate of person2. I am calculating the euclidean distance between the x and y coordinates of both the person.

现在让我们说两个人彼此之间的距离为2米,为此,我在代码中得到的欧氏距离为 250 。现在让我们说,如果这两个人现在离相机有点远,但是他们之间的距离仍然是2米,那么在这种情况下,我得到的欧氏距离为343,这意味着如果代码中人的距离在增加,离相机有点远。

Now lets say two persons are standing at a distance of 2meter to each other, for this I am getting euclidean distance in the code as 250. Now lets say if those two persons are now standing a bit far from the camera but the distance between them is still 2meter, in this case, I am getting euclidean distance as 343, which means the distance between person in the code is increasing if they are a bit far from the camera.

最初,我认为无论人们在框架中的什么位置,这种逻辑都可以正常工作,但是看起来好像不起作用。谁能帮助我为此提供一些有效的解决方案。请帮忙。谢谢

Initially I thought this logic will work fine regardless of where the persons are in the frame but looks like it is not working. Can anyone please help me suggest some good working solutions for this. Please help. Thanks

推荐答案

作为对您评论中问题的回答。

As an answer to the question in your comment.

在相机视图中,您将3d缩短。在人的视野中,您唯一可以确定的就是他们的脚在地面上。

In a camera view you have 3d shortening. And the only thing that you can be certain of with a persons position in the view is their feet on the ground.

如果考虑到3d缩短并在视图上绘制网格,则可以通过重新计算网格和正方形位置来很好地估计距离。

If you take in account the 3d shortening and draw a grid on the view you could make a good estimate of the distance by recalculating the grid and positions to square.

这篇关于如何使用python opencv计算两个人之间的距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆