1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
| """ 海事 AI 值守疲劳监控系统 参考: Seafy 2026, Orca AI, Ideagen 2026
核心功能: 1. 持续生理监测(摄像头+心率传感器) 2. 疲劳风险评估(AI 模型分级绿/黄/红) 3. STCW 合规监测(工作/休息时间记录) 4. 预测性调度(基于疲劳周期) 5. COLREGS 辅助(碰撞风险+值守状态联动)
与汽车 DMS 的技术迁移: - 摄像头疲劳检测 → 直接复用 - PERCLOS → 直接复用 - 分级警告 → 类似触觉/听觉方案 - 多人监控 → 从单人到多人扩展 """
import numpy as np from dataclasses import dataclass from typing import List, Optional from datetime import datetime, timedelta
@dataclass class MaritimeWatchConfig: """海事值守配置""" max_work_hours: int = 14 min_rest_hours: int = 10 min_rest_block: int = 6 camera_fps: int = 15 alert_green_threshold: float = 0.3 alert_amber_threshold: float = 0.6 alert_red_threshold: float = 0.8 bnwas_interval_min: int = 15
class MaritimeAIWatchSystem: """ 海事 AI 值守系统 三级警报(参考 Seafy 2026): - 🟢 GREEN: 正常值守,疲劳分数 <0.3 - 🟡 AMBER: 轻度疲劳,疲劳分数 0.3-0.6 - 🔴 RED: 严重疲劳,疲劳分数 >0.6 系统组件: 1. 桥楼摄像头阵列(2-4个固定摄像头) 2. 心率传感器(可选穿戴式) 3. AI 边缘处理器(NPU加速) 4. STCW 合规记录器 5. 船舶运动传感器(IMU补偿) """ def __init__(self, config: MaritimeWatchConfig): self.config = config self.fatigue_score = 0.0 self.alert_level = 'GREEN' self.work_hours_today = 0.0 self.rest_hours_today = 0.0 self.last_rest_block = None def assess_fatigue(self, perclos: float, blink_duration_ms: float, head_nod_count: int, reaction_time_ms: int, work_duration_hours: float) -> dict: """ 综合疲劳评估 海事场景特殊因素: - 船舶摇摆(影响头部运动判断) - 长时间夜班(6/6轮班) - 孤独/隔离(心理疲劳) - 噪声/振动(船舱环境) Returns: assessment: {fatigue_score, alert_level, recommendation} """ perclos_score = min(1.0, perclos / 20.0) blink_score = min(1.0, (blink_duration_ms - 200) / 300.0) blink_score = max(0, blink_score) nod_score = min(1.0, head_nod_count / 10.0) reaction_baseline = 500 reaction_score = min(1.0, (reaction_time_ms - reaction_baseline) / 500.0) reaction_score = max(0, reaction_score) work_score = 0 if work_duration_hours > 8: work_score = (work_duration_hours - 8) / 6.0 work_score = min(1.0, work_score) self.fatigue_score = ( 0.30 * perclos_score + 0.20 * blink_score + 0.15 * nod_score + 0.15 * reaction_score + 0.20 * work_score ) if self.fatigue_score >= self.config.alert_red_threshold: self.alert_level = 'RED' recommendation = '立即换班+休息' elif self.fatigue_score >= self.config.alert_amber_threshold: self.alert_level = 'AMBER' recommendation = '准备换班+加强监控' else: self.alert_level = 'GREEN' recommendation = '正常值守' return { 'fatigue_score': self.fatigue_score, 'alert_level': self.alert_level, 'recommendation': recommendation, 'component_scores': { 'perclos': perclos_score, 'blink': blink_score, 'head_nod': nod_score, 'reaction': reaction_score, 'work_duration': work_score, }, 'stcw_compliant': work_duration_hours <= self.config.max_work_hours, 'work_hours': work_duration_hours, 'rest_needed_hours': max(0, self.config.min_rest_hours - self.rest_hours_today), } def check_stcw_compliance(self, work_log: List[dict]) -> dict: """ STCW 2025 疲劳管理合规检查 要求: - 24小时内休息≥10小时 - 休息可分为2段,最短6小时 - 任何24小时内工作不超过14小时 """ if len(work_log) < 24: return {'compliant': True, 'note': '数据不足'} last_24 = work_log[-24:] work_hours = sum(1 for h in last_24 if h.get('status') == 'work') rest_hours = sum(1 for h in last_24 if h.get('status') == 'rest') violations = [] if rest_hours < self.config.min_rest_hours: violations.append( f"休息时间不足: {rest_hours}h < {self.config.min_rest_hours}h" ) if work_hours > self.config.max_work_hours: violations.append( f"工作时间超标: {work_hours}h > {self.config.max_work_hours}h" ) max_rest_block = 0 current_block = 0 for h in last_24: if h.get('status') == 'rest': current_block += 1 max_rest_block = max(max_rest_block, current_block) else: current_block = 0 if max_rest_block < self.config.min_rest_block: violations.append( f"连续休息不足: {max_rest_block}h < {self.config.min_rest_block}h" ) return { 'compliant': len(violations) == 0, 'violations': violations, 'work_hours': work_hours, 'rest_hours': rest_hours, 'max_rest_block': max_rest_block, }
if __name__ == "__main__": config = MaritimeWatchConfig() system = MaritimeAIWatchSystem(config) print(f"=== 海事 AI 值守系统 ===") print(f"STCW: 24h内工作≤{config.max_work_hours}h, 休息≥{config.min_rest_hours}h") print(f"三级警报: 🟢<{config.alert_green_threshold} | " f"🟡{config.alert_amber_threshold} | 🔴>{config.alert_red_threshold}") print(f"\n=== 模拟4小时值守 ===") scenarios = [ ('第1小时(清醒', {'perclos': 3, 'blink_ms': 200, 'nod': 1, 'rt': 450, 'hours': 1}), ('第2小时(轻度疲劳', {'perclos': 8, 'blink_ms': 280, 'nod': 3, 'rt': 500, 'hours': 2}), ('第3小时(中度疲劳', {'perclos': 12, 'blink_ms': 350, 'nod': 6, 'rt': 600, 'hours': 3}), ('第4小时(严重疲劳', {'perclos': 18, 'blink_ms': 420, 'nod': 9, 'rt': 750, 'hours': 4}), ('第5小时(超时', {'perclos': 22, 'blink_ms': 500, 'nod': 12, 'rt': 900, 'hours': 5}), ] for name, data in scenarios: result = system.assess_fatigue( perclos=data['perclos'], blink_duration_ms=data['blink_ms'], head_nod_count=data['nod'], reaction_time_ms=data['rt'], work_duration_hours=data['hours'], ) level_emoji = {'GREEN': '🟢', 'AMBER': '🟡', 'RED': '🔴'} print(f"\n{name})") print(f" 疲劳分数: {result['fatigue_score']:.3f} " f"{level_emoji.get(result['alert_level'], '⚪')} {result['alert_level']}") print(f" 建议: {result['recommendation']}") print(f" STCW合规: {'是' if result['stcw_compliant'] else '否'} " f"(工作{result['work_hours']}h)") components = result['component_scores'] print(f" PERCLOS={components['perclos']:.2f} " f"眨眼={components['blink']:.2f} " f"点头={components['head_nod']:.2f} " f"反应={components['reaction']:.2f} " f"工时={components['work_duration']:.2f}") print(f"\n=== STCW 合规检查 ===") work_log = [] for h in range(24): if h < 2 or (h >= 6 and h < 8): work_log.append({'status': 'rest'}) else: work_log.append({'status': 'work'}) compliance = system.check_stcw_compliance(work_log) print(f"合规: {compliance['compliant']}") print(f"工作: {compliance['work_hours']}h, 休息: {compliance['rest_hours']}h") print(f"最长连续休息: {compliance['max_rest_block']}h") if compliance['violations']: for v in compliance['violations']: print(f" ⚠️ {v}") print(f"\n=== BNWAS vs AI 值守对比 ===") print(f"{'维度':<20} {'BNWAS':<30} {'AI 值守':<30}") print(f"{'检测方式':<20} {'定时按钮复位':<30} {'持续摄像头+AI':<30}") print(f"{'疲劳评估':<20} {'无':<30} {'多模态融合评分':<30}") print(f"{'预警':<20} {'事后警报':<30} {'三级预防性预警':<30}") print(f"{'伤亡降低':<20} {'74% (有BNWAS vs 无)':<30} {'预期进一步降低':<30}") print(f"{'STCW合规':<20} {'不监测':<30} {'自动记录+违规提醒':<30}") print(f"{'换班建议':<20} {'无':<30} {'基于疲劳周期预测':<30}") print(f"{'成本':<20} {'$500-2000/船':<30} {'$2000-5000/船':<30}")
|