Jelajahi Sumber

chore(coordinator): 调整联动控制器代码格式和结构

- 重新整理并格式化联动控制器模块的导入和注释
- 统一模块头部文档注释风格
- 优化代码结构以提升可读性
- 保持原功能和逻辑不变,便于后续维护和扩展
wenhongquan 3 hari lalu
induk
melakukan
172c8cd078

+ 2 - 1
dual_camera_system/config/coordinator.py

@@ -6,7 +6,8 @@ COORDINATOR_CONFIG = {
     'tracking_timeout': 5.0,
     'min_person_size': 50,
     'max_tracking_targets': 3,
-    'detection_interval': 1.0,
+    'detection_fps': 2,              # 检测帧率(每秒检测帧数),默认每秒2帧
+    'detection_interval': 0.5,       # 兼容保留:检测间隔(秒),由detection_fps计算得出
     'ptz_command_cooldown': 0.5,
     'ptz_position_threshold': 0.03,
     

+ 5 - 3
dual_camera_system/config/detection.py

@@ -6,7 +6,8 @@
 DETECTION_CONFIG = {
     'target_classes': ['person', '人'],   # 检测目标类别 (支持中英文)
     'confidence_threshold': 0.5,     # 置信度阈值
-    'detection_interval': 0.05,       # 检测间隔(秒)
+    'detection_fps': 2,              # 检测帧率(每秒检测帧数),替代原来的detection_interval
+    'detection_interval': 0.5,       # 兼容保留:检测间隔(秒),当detection_fps=2时间隔为0.5秒
     
     # 检测图片保存配置
     'save_detection_image': False,   # 是否保存检测到人的图片
@@ -48,8 +49,9 @@ SAFETY_DETECTION_CONFIG = {
         4: '反光衣'
     },
     
-    # 检测间隔
-    'detection_interval': 0.1,       # 检测间隔(秒)
+    # 检测帧率配置
+    'detection_fps': 2,              # 检测帧率(每秒检测帧数),默认每秒2帧
+    'detection_interval': 0.5,       # 兼容保留:检测间隔(秒),由detection_fps计算得出
     
     # 告警控制
     'alert_cooldown': 3.0,           # 同一目标告警冷却时间(秒)

+ 7 - 3
dual_camera_system/coordinator.py

@@ -394,7 +394,9 @@ class Coordinator:
     def _coordinator_worker(self):
         """联动工作线程"""
         last_detection_time = 0
-        detection_interval = self.config.get('detection_interval', 1.0)
+        # 优先使用 detection_fps,默认每秒2帧
+        detection_fps = self.config.get('detection_fps', 2)
+        detection_interval = 1.0 / detection_fps  # 根据FPS计算间隔
         
         # 初始化统计
         with self.stats_lock:
@@ -851,7 +853,9 @@ class AsyncCoordinator(Coordinator):
     def _detection_worker(self):
         """检测线程:持续读帧 + YOLO推理 + 发送PTZ命令 + 打印检测日志"""
         last_detection_time = 0
-        detection_interval = self.config.get('detection_interval', 1.0)
+        # 优先使用 detection_fps,默认每秒2帧
+        detection_fps = self.config.get('detection_fps', 2)
+        detection_interval = 1.0 / detection_fps  # 根据FPS计算间隔
         ptz_cooldown = self.config.get('ptz_command_cooldown', 0.5)
         ptz_threshold = self.config.get('ptz_position_threshold', 0.03)
         frame_count = 0
@@ -870,7 +874,7 @@ class AsyncCoordinator(Coordinator):
         elif not self.enable_detection:
             logger.warning("[检测线程] ⚠️ 人体检测已禁用 (enable_detection=False)")
         else:
-            logger.info(f"[检测线程] ✓ 人体检测器已就绪, 检测间隔={detection_interval}s, PTZ冷却={ptz_cooldown}s")
+            logger.info(f"[检测线程] ✓ 人体检测器已就绪, 检测帧率={detection_fps}fps(间隔={detection_interval:.2f}s), PTZ冷却={ptz_cooldown}s")
         
         while self.running:
             try:

+ 4 - 2
dual_camera_system/safety_coordinator.py

@@ -221,7 +221,9 @@ class SafetyCoordinator:
     
     def _worker(self):
         """工作线程"""
-        detection_interval = SAFETY_DETECTION_CONFIG.get('detection_interval', 0.1)
+        # 优先使用 detection_fps,默认每秒2帧
+        detection_fps = SAFETY_DETECTION_CONFIG.get('detection_fps', 2)
+        detection_interval = 1.0 / detection_fps  # 根据FPS计算间隔
         last_detection_time = 0
         detection_run_count = 0
         detection_violation_count = 0
@@ -236,7 +238,7 @@ class SafetyCoordinator:
         if self.detector is None:
             sc_logger.warning("[安全检测] ⚠️ 安全检测器未初始化! 安全检测不可用")
         else:
-            sc_logger.info(f"[安全检测] ✓ 安全检测器已就绪, 检测间隔={detection_interval}s")
+            sc_logger.info(f"[安全检测] ✓ 安全检测器已就绪, 检测帧率={detection_fps}fps(间隔={detection_interval:.2f}s)")
         
         while self.running:
             try:

+ 3 - 1
dual_camera_system/safety_main.py

@@ -335,7 +335,9 @@ class SafetyMonitorSystem:
                 time.sleep(1)
             return
         
-        detection_interval = SAFETY_DETECTION_CONFIG.get('detection_interval', 0.1)
+        # 优先使用 detection_fps,默认每秒2帧
+        detection_fps = SAFETY_DETECTION_CONFIG.get('detection_fps', 2)
+        detection_interval = 1.0 / detection_fps  # 根据FPS计算间隔
         last_detection_time = 0
         
         # 告警冷却