|
|
@@ -458,17 +458,29 @@ class Coordinator:
|
|
|
|
|
|
def _update_tracking_targets(self, detections: List[DetectedObject],
|
|
|
frame_size: Tuple[int, int]):
|
|
|
- """更新跟踪目标"""
|
|
|
+ """更新跟踪目标(仅添加有效人员)"""
|
|
|
current_time = time.time()
|
|
|
frame_w, frame_h = frame_size
|
|
|
center_x, center_y = frame_w / 2, frame_h / 2
|
|
|
|
|
|
+ # 获取人员置信度阈值
|
|
|
+ person_threshold = DETECTION_CONFIG.get('person_threshold', 0.8)
|
|
|
+
|
|
|
with self.targets_lock:
|
|
|
- # 更新现有目标
|
|
|
+ # 清空上一轮目标(不再跟踪,每轮独立)
|
|
|
+ self.tracking_targets.clear()
|
|
|
+
|
|
|
+ # 只添加有效人员(class_name == 'person' 且置信度达标)
|
|
|
for det in detections:
|
|
|
if det.track_id is None:
|
|
|
continue
|
|
|
|
|
|
+ # 严格过滤:只处理人员且置信度达标
|
|
|
+ if det.class_name != 'person':
|
|
|
+ continue
|
|
|
+ if det.confidence < person_threshold:
|
|
|
+ continue
|
|
|
+
|
|
|
x_ratio = det.center[0] / frame_w
|
|
|
y_ratio = det.center[1] / frame_h
|
|
|
|
|
|
@@ -481,25 +493,15 @@ class Coordinator:
|
|
|
dy = abs(det.center[1] - center_y) / center_y
|
|
|
center_distance = (dx + dy) / 2 # 归一化到0-1
|
|
|
|
|
|
- if det.track_id in self.tracking_targets:
|
|
|
- # 更新位置
|
|
|
- target = self.tracking_targets[det.track_id]
|
|
|
- target.position = (x_ratio, y_ratio)
|
|
|
- target.last_update = current_time
|
|
|
- target.area = area
|
|
|
- target.confidence = det.confidence
|
|
|
- target.center_distance = center_distance
|
|
|
- else:
|
|
|
- # 新目标
|
|
|
- if len(self.tracking_targets) < self.config['max_tracking_targets']:
|
|
|
- self.tracking_targets[det.track_id] = TrackingTarget(
|
|
|
- track_id=det.track_id,
|
|
|
- position=(x_ratio, y_ratio),
|
|
|
- last_update=current_time,
|
|
|
- area=area,
|
|
|
- confidence=det.confidence,
|
|
|
- center_distance=center_distance
|
|
|
- )
|
|
|
+ # 添加为跟踪目标
|
|
|
+ self.tracking_targets[det.track_id] = TrackingTarget(
|
|
|
+ track_id=det.track_id,
|
|
|
+ position=(x_ratio, y_ratio),
|
|
|
+ last_update=current_time,
|
|
|
+ area=area,
|
|
|
+ confidence=det.confidence,
|
|
|
+ center_distance=center_distance
|
|
|
+ )
|
|
|
|
|
|
def _process_detections(self, detections: List[DetectedObject],
|
|
|
frame: np.ndarray, frame_size: Tuple[int, int]):
|