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
| """ NVIDIA Jetson AGX Orin集成方案 """
import jetson.inference import jetson.utils
class DMSJetsonPipeline: """ 基于Jetson AGX Orin的DMS管道 硬件配置: - STURDeCAM57摄像头(GMSL2接口) - Jetson AGX Orin 64GB - IR补光灯(940nm) """ def __init__(self): self.camera = jetson.utils.gstCamera( 2848, 1864, '0' ) self.dms_net = jetson.inference.detectNet( 'dms-model.onnx', threshold=0.5 ) self.display = jetson.utils.glDisplay() def capture_frame(self) -> np.ndarray: """采集帧""" frame, width, height = self.camera.CaptureRGBA() frame_np = jetson.utils.cudaToNumpy(frame, width, height, 4) frame_rgb = frame_np[:, :, :3] return frame_rgb def process_frame(self, frame: np.ndarray) -> dict: """处理帧""" detections = self.dms_net.Detect(frame, overlay='box,labels,conf') results = { 'faces': [], 'eye_closure': 0.0, 'gaze_direction': (0, 0), 'head_pose': (0, 0, 0) } for d in detections: if d.ClassID == 1: results['faces'].append({ 'bbox': (d.Left, d.Top, d.Right, d.Bottom), 'confidence': d.Confidence }) return results def run(self): """主循环""" while self.display.IsOpen(): frame = self.capture_frame() results = self.process_frame(frame) self.display.RenderOnce(frame, frame.shape[1], frame.shape[0]) print(f"检测到 {len(results['faces'])} 个面部")
|