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
| """ Camera + LiDAR + Radar 三传感器融合 LITEON Advanced Overhead Console 方案
融合策略: 1. Camera 主导:面部特征、表情、视线、疲劳 2. LiDAR 主导:3D 姿态、深度距离、空间关系 3. Radar 主导:CPD、生命体征、穿透遮挡 4. 三者交叉验证:乘员分类、占用确认 """
from typing import Optional, Tuple import numpy as np
class Point3D: """3D 点""" def __init__(self, x, y, z): self.x = x self.y = y self.z = z def distance_to(self, other): return np.sqrt( (self.x - other.x)**2 + (self.y - other.y)**2 + (self.z - other.z)**2 )
class OccupantPose3D: """乘员 3D 姿态估计""" def __init__(self): self.keypoints_3d = {} def estimate_from_lidar(self, point_cloud): """ 从 LiDAR 点云估计乘员姿态 Args: point_cloud: np.ndarray, shape=(N, 3) XYZ Returns: pose_estimate: 头部位置、躯干角度等 """ if len(point_cloud) < 50: return None head_idx = np.argmin(point_cloud[:, 1]) head_pos = point_cloud[head_idx] center = np.mean(point_cloud, axis=0) torso_vector = head_pos - center torso_angle = np.degrees( np.arctan2(torso_vector[2], np.sqrt(torso_vector[0]**2 + torso_vector[1]**2)) ) return { 'head_position': Point3D(*head_pos), 'torso_center': Point3D(*center), 'torso_angle_deg': torso_angle, 'point_count': len(point_cloud), 'confidence': min(len(point_cloud) / 200, 1.0) }
class TriModalFusion: """三模态传感器融合""" def __init__(self): self.pose_estimator = OccupantPose3D() def estimate_occupant_state(self, camera_data: dict, lidar_data: np.ndarray, radar_data: dict) -> dict: """ 融合三种传感器估计乘员状态 Args: camera_data: 摄像头输出 - face_detected: bool - gaze_direction: (pitch, yaw) - fatigue_level: float - emotion: str lidar_data: LiDAR 点云, shape=(N, 3) radar_data: 雷达输出 - presence: bool - breathing_rate: float - heart_rate: float - position: (x, y, z) Returns: fused_state: 融合后的乘员状态 """ result = { 'occupant_present': False, 'position_3d': None, 'posture': 'unknown', 'fatigue_level': 0.0, 'gaze': (0, 0), 'breathing_rate': 0, 'heart_rate': 0, 'emotion': 'neutral', 'confidence': 0.0, 'source': 'none' } lidar_pose = self.pose_estimator.estimate_from_lidar( lidar_data ) cam_face = camera_data.get('face_detected', False) radar_presence = radar_data.get('presence', False) lidar_present = lidar_pose is not None if cam_face and radar_presence and lidar_present: result['occupant_present'] = True result['position_3d'] = ( radar_data.get('position', (0, 0, 0)) ) result['posture'] = self._classify_posture( lidar_pose['torso_angle_deg'] ) result['fatigue_level'] = camera_data.get( 'fatigue_level', 0 ) result['gaze'] = camera_data.get( 'gaze_direction', (0, 0) ) result['breathing_rate'] = radar_data.get( 'breathing_rate', 0 ) result['heart_rate'] = radar_data.get( 'heart_rate', 0 ) result['emotion'] = camera_data.get('emotion', 'neutral') result['confidence'] = 0.95 result['source'] = 'all_three' elif cam_face and radar_presence: result['occupant_present'] = True result['fatigue_level'] = camera_data.get( 'fatigue_level', 0 ) result['breathing_rate'] = radar_data.get( 'breathing_rate', 0 ) result['confidence'] = 0.85 result['source'] = 'camera+radar' elif lidar_present and radar_presence: result['occupant_present'] = True result['posture'] = self._classify_posture( lidar_pose['torso_angle_deg'] ) result['breathing_rate'] = radar_data.get( 'breathing_rate', 0 ) result['confidence'] = 0.80 result['source'] = 'lidar+radar' elif radar_presence: result['occupant_present'] = True result['breathing_rate'] = radar_data.get( 'breathing_rate', 0 ) result['confidence'] = 0.70 result['source'] = 'radar_only' return result def _classify_posture(self, torso_angle): """根据躯干角度分类姿态""" if torso_angle < 10: return 'upright' elif torso_angle < 25: return 'slight_recline' elif torso_angle < 40: return 'reclined' else: return 'lying_down'
if __name__ == "__main__": fusion = TriModalFusion() cam1 = { 'face_detected': True, 'gaze_direction': (5, -2), 'fatigue_level': 0.15, 'emotion': 'neutral' } lidar1 = np.random.randn(300, 3) * 0.5 + np.array([0, -0.3, 1.5]) radar1 = { 'presence': True, 'breathing_rate': 16, 'heart_rate': 72, 'position': (0.0, -0.3, 1.5) } result1 = fusion.estimate_occupant_state(cam1, lidar1, radar1) print(f"场景1 - 驾驶员正常:") print(f" 存在: {result1['occupant_present']}, " f"姿态: {result1['posture']}, " f"置信度: {result1['confidence']:.2f}") print(f" 来源: {result1['source']}") cam2 = {'face_detected': False} lidar2 = np.random.randn(200, 3) * 0.5 + np.array([0.8, -0.2, 1.0]) radar2 = { 'presence': True, 'breathing_rate': 20, 'heart_rate': 90, 'position': (0.8, -0.2, 1.0) } result2 = fusion.estimate_occupant_state(cam2, lidar2, radar2) print(f"\n场景2 - 后座乘客:") print(f" 存在: {result2['occupant_present']}, " f"姿态: {result2['posture']}, " f"置信度: {result2['confidence']:.2f}") print(f" 来源: {result2['source']}")
|