python - 在相交处找到入口出口
问题描述
我使用以下代码查找人员的进入和退出人数。
# 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
根据此代码,如果同一个人回来并再次进入,则进入计数仍然与已计数的人相同。每次当人与线相交时,我都想找到进入和退出计数。我该如何解决?
解决方案
一种快速的方法是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
因为您不在乎它们是否已经被计算在内,您只关心您设置的条件是否已满足
推荐阅读
- reactjs - ReactJS:无法解析“@babel/runtime/helpers/builtin/interopRequireDefault”
- linux - supervisorctl 无法启动logstash
- javascript - Javascript在函数中同步运行异步方法
- html - 不在导航栏下方和居中的项目 - 响应式顶部导航
- php - 如何在不同的表中添加审核日志?
- ruby-on-rails - 如何在不将数据保存在数据库中且不使用 Ember-Data 的情况下将数据从 Rails 后端显示到 Ember 前端?
- angular - 无法在 Angular 7 应用程序中显示 mapbox-gl 地图
- r - 如何计算每行中重复值或值的出现次数?
- typescript - 强制 Webpack 从无效的 TypeScript 代码构建输出
- python - Jupyter Notebook 主题改变了我的 python 版本