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
| def detect_abnormal_posture(radar_point_cloud, seat_position): """ 异常姿态检测(OOP - Out of Position) Args: radar_point_cloud: 雷达点云数据 (N, 4) [x, y, z, velocity] seat_position: 座椅位置参考 Returns: is_oop: 是否异常姿态 posture_type: 姿态类型 """ from sklearn.cluster import DBSCAN clustering = DBSCAN(eps=0.1, min_samples=5).fit(radar_point_cloud[:, :3]) labels = clustering.labels_ unique_labels = set(labels) - {-1} if not unique_labels: return False, "NO_OCCUPANT" main_cluster = max(unique_labels, key=lambda l: np.sum(labels == l)) body_points = radar_point_cloud[labels == main_cluster] x_min, x_max = body_points[:, 0].min(), body_points[:, 0].max() y_min, y_max = body_points[:, 1].min(), body_points[:, 1].max() z_min, z_max = body_points[:, 2].min(), body_points[:, 2].max() height = z_max - z_min width = y_max - y_min in_seat = (x_min > seat_position['x_min'] and x_max < seat_position['x_max'] and y_min > seat_position['y_min'] and y_max < seat_position['y_max']) if not in_seat: return True, "OUT_OF_SEAT" if height < 0.3: return True, "RECLINED_EXCESSIVELY" if width > 0.8: return True, "LEANING_SIDEWAYS" return False, "NORMAL_POSTURE"
|