public Form1() { // only one sensor is currently supported this.kinectSensor = KinectSensor.GetDefault(); // set IsAvailableChanged event notifier this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged; // open the sensor this.kinectSensor.Open(); // open the reader for the body frames this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader(); // set the BodyFramedArrived event notifier this.bodyFrameReader.FrameArrived += this.Reader_BodyFrameArrived; // initialize the gesture detection objects for our gestures this.gestureDetectorList = new List <GestureDetector>(); InitializeComponent(); for (int i = 0; i < kinectSensor.BodyFrameSource.BodyCount; ++i) { GestureResultView result = new GestureResultView(i, false, false, 0.0f); GestureDetector detector = new GestureDetector(this.kinectSensor, result); gestureDetectorList.Add(detector); } }
/// <summary> /// Initializes a new instance of the GestureDetector class along with the gesture frame source and reader /// 与手势框架源和阅读器一起初始化GestureDetector类的新实例 /// </summary> /// <param name="kinectSensor"> /// Active sensor to initialize the VisualGestureBuilderFrameSource object with /// 启动的传感器,用来初始化VisualGestureBuilderFrameSource对象 /// </param> /// <param name="gestureResultView">GestureResultView object to store gesture results of a single body to</param> public GestureDetector(KinectSensor kinectSensor, GestureResultView gestureResultView) { if (kinectSensor == null) { throw new ArgumentNullException("kinectSensor"); } if (gestureResultView == null) { throw new ArgumentNullException("gestureResultView"); } this.GestureResultView = gestureResultView; // 创建vgb源文件,当一个有效的身体帧从传感器到达时,相关的身体跟踪ID将被设置。 // create the vgb source. The associated body tracking ID will be set when a valid body frame arrives from the sensor. this.vgbFrameSource = new VisualGestureBuilderFrameSource(kinectSensor, 0); this.vgbFrameSource.TrackingIdLost += this.Source_TrackingIdLost; // open the reader for the vgb frames this.vgbFrameReader = this.vgbFrameSource.OpenReader(); if (this.vgbFrameReader != null) { this.vgbFrameReader.IsPaused = true; this.vgbFrameReader.FrameArrived += this.Reader_GestureFrameArrived; } // 从手势数据库加载手势 // load a gesture from the gesture database using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(this.gestureDatabasePath)) { // 添加可用手势 // we could load all available gestures in the database with a call to vgbFrameSource.AddGestures(database.AvailableGestures), // but for this program, we only want to track one discrete gesture from the database, so we'll load it by name vgbFrameSource.AddGestures(database.AvailableGestures); } }