首页 > 解决方案 > 在相交处找到入口出口

问题描述

我使用以下代码查找人员的进入和退出人数。

 # check to see if the object has been counted or not
            if not to.counted:
                # if the direction is negative (indicating the object
                # is moving up) AND the centroid is above the center
                # line, count the object
                if direction < 0 and centroid[1] < H // 2:
                    totalUp += 1
                    to.counted = True

                # if the direction is positive (indicating the object
                # is moving down) AND the centroid is below the
                # center line, count the object
                elif direction > 0 and centroid[1] > H // 2:
                    totalDown += 1
                    to.counted = True

根据此代码,如果同一个人回来并再次进入,则进入计数仍然与已计数的人相同。每次当人与线相交时,我都想找到进入和退出计数。我该如何解决?

标签: pythonopencvimage-processingtrackingdlib

解决方案


一种快速的方法是counted完全忽略该属性:

# if the direction is negative (indicating the object
# is moving up) AND the centroid is above the center
# line, count the object
if direction < 0 and centroid[1] < H // 2:
      totalUp += 1

# if the direction is positive (indicating the object
# is moving down) AND the centroid is below the
# center line, count the object
elif direction > 0 and centroid[1] > H // 2:
    totalDown += 1

这是假设您的总计数不是每人,而是发生的总数。如果是这种情况,请忽略,if to.counted因为您不在乎它们是否已经被计算在内,您只关心您设置的条件是否已满足


推荐阅读