添加车辆进入ROI的阈值
This commit is contained in:
@@ -99,6 +99,8 @@ class KadianDetector:
|
||||
self.TIME_THRESHOLD_CAR_MIN_DURATION = 3.0
|
||||
# Car 丢帧/ID维持缓冲
|
||||
self.TIME_TOLERANCE_CAR = 2.0
|
||||
# 车辆进入ROI确认阈值(需要连续在ROI内出现这么多帧才正式注册)
|
||||
self.TIME_THRESHOLD_CAR_ENTER = 1.0
|
||||
|
||||
# police丢失阈值
|
||||
self.TIME_TOLERANCE_POLICE = 3.0
|
||||
@@ -110,6 +112,7 @@ class KadianDetector:
|
||||
self.frame_thresh_trunk_valid = int(self.TIME_THRESHOLD_TRUNK_OPEN * self.fps)
|
||||
self.frame_thresh_car_min_duration = int(self.TIME_THRESHOLD_CAR_MIN_DURATION * self.fps)
|
||||
self.frame_buffer_limit_car = int(self.TIME_TOLERANCE_CAR * self.fps)
|
||||
self.frame_thresh_car_enter = int(self.TIME_THRESHOLD_CAR_ENTER * self.fps)
|
||||
self.frame_buffer_limit_police = int(self.TIME_TOLERANCE_POLICE * self.fps)
|
||||
self.frame_thresh_nobody = int(self.TIME_THRESHOLD_NOBODY * self.fps)
|
||||
self.frame_thresh_only_one = int(self.TIME_THRESHOLD_ONLY_ONE * self.fps)
|
||||
@@ -127,8 +130,10 @@ class KadianDetector:
|
||||
|
||||
|
||||
|
||||
# 车辆注册表 (字典)
|
||||
# 车辆注册表 (字典) - 已确认进入ROI的车辆
|
||||
self.roi_car_registry = {}
|
||||
# 车辆进入确认等待区 - 刚进入ROI但还未确认的车辆
|
||||
self.car_enter_pending = {} # {tid: {'first_seen': frame_idx, 'frames_count': count}}
|
||||
# 违规车辆记录
|
||||
self.unchecked_trunk_alerts = {} # 后备箱未检
|
||||
self.fast_pass_alerts = {} # 通过过快
|
||||
@@ -322,20 +327,44 @@ class KadianDetector:
|
||||
# 仅处理ROI内的车辆
|
||||
if self.check_point_in_roi(roi_points_int32, (cx, cy)):
|
||||
current_cars.append({'id': tid, 'box': [x1, y1, x2, y2]})
|
||||
# 车辆注册表初始化
|
||||
if tid not in self.roi_car_registry:
|
||||
self.roi_car_registry[tid] = {
|
||||
|
||||
# 检查是否在等待确认区
|
||||
if tid in self.car_enter_pending:
|
||||
# 已在等待区,更新计数
|
||||
self.car_enter_pending[tid]['frames_count'] += 1
|
||||
self.car_enter_pending[tid]['last_seen'] = self.current_frame_idx
|
||||
self.car_enter_pending[tid]['last_box'] = [x1, y1, x2, y2]
|
||||
|
||||
# 检查是否达到确认阈值
|
||||
if self.car_enter_pending[tid]['frames_count'] >= self.frame_thresh_car_enter:
|
||||
# 从等待区移到正式注册
|
||||
self.roi_car_registry[tid] = {
|
||||
'first_seen': self.car_enter_pending[tid]['first_seen'],
|
||||
'last_seen': self.current_frame_idx,
|
||||
'last_seen_time': current_time_sec,
|
||||
'trunk_frames': 0,
|
||||
'is_checked': False,
|
||||
'last_box': [x1, y1, x2, y2],
|
||||
}
|
||||
del self.car_enter_pending[tid]
|
||||
label += " IN"
|
||||
else:
|
||||
label += " PENDING"
|
||||
elif tid not in self.roi_car_registry:
|
||||
# 新发现的车辆,加入等待确认区
|
||||
self.car_enter_pending[tid] = {
|
||||
'first_seen': self.current_frame_idx,
|
||||
'last_seen': self.current_frame_idx,
|
||||
'last_seen_time': current_time_sec,
|
||||
'trunk_frames': 0,
|
||||
'is_checked': False,
|
||||
#'frame_buffer': deque(maxlen=self.max_car_frames), # 新增
|
||||
'frames_count': 1,
|
||||
'last_box': [x1, y1, x2, y2],
|
||||
}
|
||||
label += " PENDING"
|
||||
else:
|
||||
# 已在正式注册表中
|
||||
self.roi_car_registry[tid]['last_seen'] = self.current_frame_idx
|
||||
self.roi_car_registry[tid]['last_seen_time'] = current_time_sec
|
||||
label += " IN"
|
||||
self.roi_car_registry[tid]['last_box'] = [x1, y1, x2, y2]
|
||||
label += " IN"
|
||||
elif role == "opentrunk":
|
||||
color = (255, 165, 0) # 橙色
|
||||
label = "OpenTrunk"
|
||||
@@ -396,6 +425,17 @@ class KadianDetector:
|
||||
if self.roi_car_registry[c_id]['trunk_frames'] >= self.frame_thresh_trunk_valid:
|
||||
self.roi_car_registry[c_id]['is_checked'] = True
|
||||
|
||||
# ==========================================
|
||||
# 清理等待确认区的车辆(如果离开ROI超过缓冲帧数)
|
||||
# ==========================================
|
||||
pending_to_remove = []
|
||||
for car_id, info in self.car_enter_pending.items():
|
||||
if (self.current_frame_idx - info['last_seen']) > self.frame_buffer_limit_car:
|
||||
pending_to_remove.append(car_id)
|
||||
|
||||
for car_id in pending_to_remove:
|
||||
del self.car_enter_pending[car_id]
|
||||
|
||||
# ==========================================
|
||||
# 维护车辆注册表 & 生成离场报警
|
||||
# ==========================================
|
||||
|
||||
Reference in New Issue
Block a user