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
| """ rPPG + 雷达 心率融合框架 视觉和雷达的心率估计融合 """
import numpy as np from dataclasses import dataclass from typing import Optional
@dataclass class HeartRateEstimate: """心率估计结果""" hr_bpm: float confidence: float snr_db: float
def fuse_heart_rate(rppg: HeartRateEstimate, radar: HeartRateEstimate) -> HeartRateEstimate: """ 融合 rPPG 和雷达心率估计 策略: 1. 两者都高置信度 → 加权平均 2. rPPG 高置信度、雷达低 → 以 rPPG 为主 3. 雷达高置信度、rPPG 低 → 以雷达为主(遮挡场景) 4. 两者都低 → 不确定 """ if rppg.confidence < 0.3 and radar.confidence < 0.3: return HeartRateEstimate(0, 0, -10) w_rppg = rppg.confidence / (rppg.confidence + radar.confidence + 1e-6) w_radar = 1 - w_rppg fused_hr = w_rppg * rppg.hr_bpm + w_radar * radar.hr_bpm fused_conf = max(rppg.confidence, radar.confidence) fused_snr = max(rppg.snr_db, radar.snr_db) if abs(rppg.hr_bpm - radar.hr_bpm) < 10 and \ rppg.confidence > 0.5 and radar.confidence > 0.5: fused_conf = min(fused_conf + 0.1, 1.0) elif abs(rppg.hr_bpm - radar.hr_bpm) > 20: fused_conf *= 0.8 return HeartRateEstimate( round(fused_hr, 1), round(fused_conf, 2), round(fused_snr, 1) )
if __name__ == "__main__": rppg = HeartRateEstimate(72, 0.85, 8.5) radar = HeartRateEstimate(73, 0.75, 5.2) fused = fuse_heart_rate(rppg, radar) print(f"正常场景: rPPG={rppg.hr_bpm}, 雷达={radar.hr_bpm} → 融合={fused.hr_bpm} (conf={fused.confidence})") rppg = HeartRateEstimate(0, 0.1, -5) radar = HeartRateEstimate(68, 0.70, 4.8) fused = fuse_heart_rate(rppg, radar) print(f"遮挡场景: rPPG={rppg.hr_bpm}, 雷达={radar.hr_bpm} → 融合={fused.hr_bpm} (conf={fused.confidence})") rppg = HeartRateEstimate(75, 0.3, 2) radar = HeartRateEstimate(80, 0.35, 1.5) fused = fuse_heart_rate(rppg, radar) print(f"不确定场景: rPPG={rppg.hr_bpm}, 雷达={radar.hr_bpm} → 融合={fused.hr_bpm} (conf={fused.confidence})")
|