Exemplo n.º 1
0
        /// <summary>
        /// 与手势框架源和阅读器一起初始化GestureDetector类的新实例
        /// </summary>
        /// <param name="kinectSensor">
        /// 启动的传感器,用来初始化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.ResultView = gestureResultView;

            // 创建vgb源文件,当一个有效的身体帧从传感器到达时,相关的身体跟踪ID将被设置。
            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;
            }

            // 从手势数据库加载手势
            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);
            }
        }
Exemplo n.º 2
0
        public GestureControl()
        {
            // 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>();

            for (int i = 0; i < kinectSensor.BodyFrameSource.BodyCount; ++i)
            {
                GestureResultView result   = new GestureResultView(i, false, false, 0.0f);
                GestureDetector   detector = new GestureDetector(kinectSensor, result);
                gestureDetectorList.Add(detector);
            }

            // 数据保留文件名 yyyy-MM-dd hh-mm-ss.txt
            string fileName = DateTime.Now.ToString("yyyy-MM-dd hh-mm-ss") + ".txt";

            streamWriter = new StreamWriter(fileName);
            kalmanFilter = new Commons.Filter.KalmanFilter(1e-6f, 4e-4f);
        }