feat: 离岗算法滑动窗口抗抖动优化

- 上岗确认阈值从 0.7 降为 0.6,降低漏确认
- 离岗触发从 ratio==0 改为 ratio<0.2,允许 20% 抖动
- 离岗中断从单帧判断改为 ratio>=0.5,避免偶尔一帧误检打断确认
- 入侵算法不变,通过调高 conf 到 0.6 解决误报

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-08 23:20:31 +08:00
parent 7a5ddef2f6
commit 1211fc7207

View File

@@ -241,7 +241,7 @@ class LeavePostAlgorithm:
self.state_start_time = current_time
self.detection_window.clear()
logger.debug(f"ROI {roi_id}: CONFIRMING_ON_DUTY → INIT (人消失)")
elif elapsed >= self.confirm_on_duty_sec and detection_ratio >= 0.7:
elif elapsed >= self.confirm_on_duty_sec and detection_ratio >= 0.6:
# 上岗确认成功(命中率>=70%
self.state = self.STATE_ON_DUTY
self.state_start_time = current_time
@@ -250,8 +250,8 @@ class LeavePostAlgorithm:
elif self.state == self.STATE_ON_DUTY:
# 在岗状态:监控是否离岗
if detection_ratio == 0:
# 滑动窗口内完全没有人,进入离岗确认
if detection_ratio < 0.2:
# 滑动窗口内 80% 以上帧无人,进入离岗确认
self.state = self.STATE_CONFIRMING_OFF_DUTY
self.state_start_time = current_time
logger.debug(f"ROI {roi_id}: ON_DUTY → CONFIRMING_OFF_DUTY")
@@ -260,12 +260,12 @@ class LeavePostAlgorithm:
# 离岗确认中:需要持续未检测到人
elapsed = (current_time - self.state_start_time).total_seconds()
if roi_has_person:
# 人回来了回到ON_DUTY
if detection_ratio >= 0.5:
# 窗口内检测率恢复到 50% 以上,人确实回来了
self.state = self.STATE_ON_DUTY
self.state_start_time = current_time
logger.debug(f"ROI {roi_id}: CONFIRMING_OFF_DUTY → ON_DUTY (人回来了)")
elif elapsed >= self.confirm_off_duty_sec and detection_ratio == 0:
logger.debug(f"ROI {roi_id}: CONFIRMING_OFF_DUTY → ON_DUTY (人回来了, ratio={detection_ratio:.2f})")
elif elapsed >= self.confirm_off_duty_sec and detection_ratio < 0.2:
# 离岗确认成功,进入倒计时
self.state = self.STATE_OFF_DUTY_COUNTDOWN
self.state_start_time = current_time