diff --git a/biz/base_frame_processor.py b/biz/base_frame_processor.py index cf9335b..3642701 100644 --- a/biz/base_frame_processor.py +++ b/biz/base_frame_processor.py @@ -376,7 +376,7 @@ class BaseFrameProcessorWorker(threading.Thread): def _filter_duplicate_alerts(self, cam_id: int, alerts: list, current_time: float) -> list: """ - 过滤5秒内重复的告警 + 过滤重复告警,支持不同 action 使用不同频率 Args: cam_id: 摄像头ID @@ -392,11 +392,16 @@ class BaseFrameProcessorWorker(threading.Thread): push_actions = [] for alert in alerts: action = alert['action'] + + # 获取该 action 的推送间隔 + # 优先从配置中查找,没有则使用默认的 ALERT_PUSH_INTERVAL + push_interval = constants.ALERT_PUSH_INTERVALS.get(action, ALERT_PUSH_INTERVAL) + last_push = self.last_alert_push_time[cam_id].get(action, 0) - # 检查是否超过推送间隔 - if current_time - last_push >= ALERT_PUSH_INTERVAL: + + # 使用各自的推送间隔进行检查 + if current_time - last_push >= push_interval: push_actions.append(action) - # push_actions.append(get_alert_label(action)) # 更新该action的最后推送时间 self.last_alert_push_time[cam_id][action] = current_time diff --git a/common/constants.py b/common/constants.py index 1292867..7598e3d 100644 --- a/common/constants.py +++ b/common/constants.py @@ -11,6 +11,12 @@ HLS_ROOT_PATH = "" HLS_SEGMENT_PATTERN = "segment_%09d.ts" # TS文件命名模式 +# 默认告警推送间隔(秒) +ALERT_PUSH_INTERVAL = 5.0 + +# 各 action 的推送间隔配置 {action_code: interval_seconds} +ALERT_PUSH_INTERVALS = {} + # 视频剪辑配置 VIDEO_CLIP_OUTPUT_DIR = "" VIDEO_CLIP_DURATION_SECONDS = 30 @@ -27,6 +33,7 @@ def init_config(config_path: str = "config.yaml"): """ global ALERT_PUSH_URL, HLS_ROOT_PATH global VIDEO_CLIP_OUTPUT_DIR, VIDEO_CLIP_DURATION_SECONDS, VIDEO_CLIP_RETENTION_SECONDS, VIDEO_CLIP_DEFAULT_SEGMENT_DURATION + global ALERT_PUSH_INTERVALS try: with open(config_path, "r", encoding="utf-8") as f: @@ -41,6 +48,9 @@ def init_config(config_path: str = "config.yaml"): VIDEO_CLIP_RETENTION_SECONDS = cfg.get("video_clip_retention_seconds", 3600) VIDEO_CLIP_DEFAULT_SEGMENT_DURATION = cfg.get("video_clip_default_segment_duration", 2) + # 告警推送间隔配置 + ALERT_PUSH_INTERVALS = cfg.get("alert_push_intervals", {}) + logger.info(f"[INFO] Config initialized from {config_path}, alert_push_url={ALERT_PUSH_URL}") except Exception as e: diff --git a/config.yaml b/config.yaml index be1300d..b3f1cc5 100644 --- a/config.yaml +++ b/config.yaml @@ -49,16 +49,16 @@ video_clip_default_segment_duration: 2 # 默认分片 service_groups: - name: "kadian_group" # 服务组名称 - video_source_type: "rtsp" + video_source_type: "hls" ws_host: "0.0.0.0" # WebSocket 服务地址 ws_port: 8765 # WebSocket 服务端口 - algorithm: "corridor" # 算法类型 + algorithm: "checkpoint" # 算法类型 cameras: # 该组下的摄像头列表 - id: 8 index: "12345" name: Entrance params: - model_path: "Kadian.onnx" + model_path: "Kadian_sanshijiazi.onnx" roi_points: - [0.15, 0.001] - [0.5, 0.001] @@ -96,3 +96,12 @@ alert_types: "Playing Phone": "玩手机" "Smoke": "吸烟" "Nobody Checking": "无人在场" + +# 告警推送频率配置(可选,单位:秒) +# 如果某个 action 配置了,则使用配置的时间;否则使用默认的 ALERT_PUSH_INTERVAL(5秒) +alert_push_intervals: + "Unchecked Trunk": 30 # 未检查后备箱 - 10秒 + "Ignore": 30 # 漏检 - 3秒 + "Nobody": 600 # 无人在场 - 5秒 + "Only One": 120 +