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
| class AutoAnnotator: """ 自动标注器 从仿真场景提取精确标注 """ def __init__(self): self.annotators = { 'bounding_box': self.annotate_bbox, 'keypoints': self.annotate_keypoints, 'segmentation': self.annotate_segmentation, 'depth': self.annotate_depth, 'gaze': self.annotate_gaze } def annotate(self, scene, frame): """ 自动标注 Args: scene: 仿真场景 frame: 渲染帧 Returns: annotations: 标注数据 """ annotations = {} for name, annotator in self.annotators.items(): annotations[name] = annotator(scene, frame) return annotations def annotate_keypoints(self, scene, frame): """ 关键点标注 提取人体/面部关键点 """ keypoints = {} body_keypoints = [ 'nose', 'left_eye', 'right_eye', 'left_ear', 'right_ear', 'left_shoulder', 'right_shoulder', 'left_elbow', 'right_elbow', 'left_wrist', 'right_wrist', 'left_hip', 'right_hip', 'left_knee', 'right_knee', 'left_ankle', 'right_ankle' ] for kp_name in body_keypoints: position_3d = scene.get_object_position(kp_name) position_2d = self.project_to_2d(position_3d, frame['camera']) keypoints[kp_name] = { '3d': position_3d, '2d': position_2d, 'visible': self.check_visibility(position_3d, frame['camera']) } return keypoints def annotate_gaze(self, scene, frame): """ 视线标注 提取视线方向和落点 """ gaze_origin = scene.get_gaze_origin() gaze_direction = scene.get_gaze_direction() gaze_target = self.compute_gaze_target( gaze_origin, gaze_direction, scene ) return { 'origin': gaze_origin, 'direction': gaze_direction, 'target': gaze_target, 'on_road': self.check_on_road(gaze_target, scene) }
|