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
| import numpy as np
class SensorFusionOMS: """ 传感器融合乘员监控系统 """ def __init__(self, calibrations): """ 初始化 Args: calibrations: 各传感器标定参数 """ self.calibrations = calibrations self.seat_regions = self.define_seat_regions() def define_seat_regions(self): """ 定义座位区域(3D空间) Returns: regions: 各座位的3D边界框 """ regions = { "seat_1": {"x": (-0.5, 0), "y": (0.3, 0.6), "z": (0.5, 1.0)}, "seat_2": {"x": (0, 0.5), "y": (0.3, 0.6), "z": (0.5, 1.0)}, "seat_3": {"x": (-0.5, 0), "y": (-0.3, 0), "z": (0.5, 1.0)}, "seat_4": {"x": (0, 0.5), "y": (-0.3, 0), "z": (0.5, 1.0)}, "seat_5": {"x": (-0.5, 0), "y": (-0.9, -0.6), "z": (0.5, 1.0)}, "seat_6": {"x": (0, 0.5), "y": (-0.9, -0.6), "z": (0.5, 1.0)} } return regions def fuse_2d_3d(self, image_2d, depth_map, seat_id): """ 融合2D图像和3D深度 Args: image_2d: 2D图像 depth_map: 深度图 seat_id: 座位ID Returns: occupant_data: 乘员数据 """ region = self.seat_regions[seat_id] roi_2d = self.extract_roi_2d(image_2d, region) roi_3d = self.extract_roi_3d(depth_map, region) detection_2d = self.detect_occupant_2d(roi_2d) detection_3d = self.detect_occupant_3d(roi_3d) occupant_data = self.merge_detections(detection_2d, detection_3d) return occupant_data def detect_occupant_2d(self, roi_2d): """ 2D检测 Returns: detection: 2D检测结果 """ faces = self.detect_faces(roi_2d) keypoints = self.detect_keypoints(roi_2d, faces) gaze = self.estimate_gaze(roi_2d, keypoints) return { "faces": faces, "keypoints": keypoints, "gaze": gaze } def detect_occupant_3d(self, roi_3d): """ 3D检测 Returns: detection: 3D检测结果 """ points = self.segment_points(roi_3d) skeleton_3d = self.estimate_skeleton_3d(points) posture = self.classify_posture(skeleton_3d) return { "point_cloud": points, "skeleton": skeleton_3d, "posture": posture } def merge_detections(self, det_2d, det_3d): """ 融合检测结果 """ return { "presence": len(det_2d["faces"]) > 0 or len(det_3d["point_cloud"]) > 100, "head_pose": det_3d["skeleton"]["head_pose"] if det_3d["skeleton"] else None, "gaze": det_2d["gaze"], "posture": det_3d["posture"], "confidence": 0.9 }
if __name__ == "__main__": system = SensorFusionOMS(calibrations={}) image_2d = np.random.randint(0, 255, (720, 1280, 3), dtype=np.uint8) depth_map = np.random.rand(720, 1280) * 2 + 0.5 for seat_id in ["seat_1", "seat_2", "seat_3", "seat_4", "seat_5", "seat_6"]: data = system.fuse_2d_3d(image_2d, depth_map, seat_id) print(f"{seat_id}: 存在={data['presence']}, 姿态={data['posture']}")
|