|
|
@@ -667,11 +667,20 @@ class AsyncCoordinator(Coordinator):
|
|
|
frame_count = 0
|
|
|
last_log_time = time.time()
|
|
|
log_interval = 5.0 # 每5秒打印一次帧率统计
|
|
|
+ detection_run_count = 0
|
|
|
+ detection_person_count = 0
|
|
|
+ last_no_detect_log_time = 0
|
|
|
+ no_detect_log_interval = 30.0
|
|
|
|
|
|
with self.stats_lock:
|
|
|
self.stats['start_time'] = time.time()
|
|
|
|
|
|
- logger.info(f"[检测线程] 启动, 检测间隔={detection_interval}s, PTZ冷却={ptz_cooldown}s")
|
|
|
+ if self.detector is None:
|
|
|
+ logger.warning("[检测线程] ⚠️ 人体检测器未初始化! 检测功能不可用, 请检查 YOLO 模型是否正确加载")
|
|
|
+ elif not self.enable_detection:
|
|
|
+ logger.warning("[检测线程] ⚠️ 人体检测已禁用 (enable_detection=False)")
|
|
|
+ else:
|
|
|
+ logger.info(f"[检测线程] ✓ 人体检测器已就绪, 检测间隔={detection_interval}s, PTZ冷却={ptz_cooldown}s")
|
|
|
|
|
|
while self.running:
|
|
|
try:
|
|
|
@@ -685,23 +694,39 @@ class AsyncCoordinator(Coordinator):
|
|
|
self._update_stats('frames_processed')
|
|
|
frame_size = (frame.shape[1], frame.shape[0])
|
|
|
|
|
|
- # 每隔 log_interval 打印帧率统计
|
|
|
if current_time - last_log_time >= log_interval:
|
|
|
elapsed = current_time - last_log_time
|
|
|
fps = frame_count / elapsed if elapsed > 0 else 0
|
|
|
- logger.info(f"[检测线程] 帧率={fps:.1f}fps, 处理帧={frame_count}")
|
|
|
+
|
|
|
+ state_str = self.state.name if hasattr(self.state, 'name') else str(self.state)
|
|
|
+ stats_parts = [f"帧率={fps:.1f}fps", f"处理帧={frame_count}", f"状态={state_str}"]
|
|
|
+
|
|
|
+ if self.detector is None:
|
|
|
+ stats_parts.append("检测器=未加载")
|
|
|
+ elif not self.enable_detection:
|
|
|
+ stats_parts.append("检测=已禁用")
|
|
|
+ else:
|
|
|
+ stats_parts.append(f"检测轮次={detection_run_count}(有人={detection_person_count})")
|
|
|
+
|
|
|
+ with self.targets_lock:
|
|
|
+ target_count = len(self.tracking_targets)
|
|
|
+ stats_parts.append(f"跟踪目标={target_count}")
|
|
|
+
|
|
|
+ logger.info(f"[检测线程] {', '.join(stats_parts)}")
|
|
|
frame_count = 0
|
|
|
last_log_time = current_time
|
|
|
|
|
|
# 周期性检测(约1次/秒)
|
|
|
if current_time - last_detection_time >= detection_interval:
|
|
|
last_detection_time = current_time
|
|
|
+ detection_run_count += 1
|
|
|
|
|
|
# YOLO 人体检测
|
|
|
detections = self._detect_persons(frame)
|
|
|
|
|
|
if detections:
|
|
|
self._update_stats('persons_detected', len(detections))
|
|
|
+ detection_person_count += 1
|
|
|
|
|
|
# 更新跟踪
|
|
|
tracked = self.tracker.update(detections)
|
|
|
@@ -712,7 +737,7 @@ class AsyncCoordinator(Coordinator):
|
|
|
for t in tracked:
|
|
|
x_ratio, y_ratio = t.position
|
|
|
logger.info(
|
|
|
- f"[检测] 目标ID={t.track_id} "
|
|
|
+ f"[检测] ✓ 目标ID={t.track_id} "
|
|
|
f"位置=({x_ratio:.3f}, {y_ratio:.3f}) "
|
|
|
f"置信度={getattr(t, 'confidence', 0):.2f}"
|
|
|
)
|
|
|
@@ -720,6 +745,13 @@ class AsyncCoordinator(Coordinator):
|
|
|
# 有检测但没跟踪上
|
|
|
for d in detections:
|
|
|
logger.debug(f"[检测] 未跟踪: {d.class_name} @ {d.center}")
|
|
|
+ else:
|
|
|
+ if current_time - last_no_detect_log_time >= no_detect_log_interval:
|
|
|
+ logger.info(
|
|
|
+ f"[检测] · YOLO检测运行正常, 本轮未检测到人员 "
|
|
|
+ f"(累计检测{detection_run_count}轮, 检测到人{detection_person_count}轮)"
|
|
|
+ )
|
|
|
+ last_no_detect_log_time = current_time
|
|
|
|
|
|
if tracked:
|
|
|
self._process_detections(tracked, frame, frame_size)
|