Пример #1
0
    /// <summary>
    /// Initializes a new instance of the GestureDetector class along with the gesture frame source and reader
    /// </summary>
    /// <param name="kinectSensor">Active sensor to initialize the VisualGestureBuilderFrameSource object with</param>
    /// <param name="gestureResultView">GestureResultView object to store gesture results of a single body to</param>
    public GestureDetector(KinectSensor kinectSensor, KinectManager kinectManager)
    {
        if (kinectSensor == null)
        {
            throw new ArgumentNullException("kinectSensor");
        }

        // create the vgb source. The associated body tracking ID will be set when a valid body frame arrives from the sensor.
        this.vgbFrameSource = VisualGestureBuilderFrameSource.Create(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 the 'Seated' gesture from the gesture database
        using (VisualGestureBuilderDatabase database =  VisualGestureBuilderDatabase.Create(this.gestureDatabase))
        {
            // 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
            foreach (Gesture gesture in database.AvailableGestures)
            {
                if (gesture.Name.Equals(this.shootingGestureName))
                {
                    this.vgbFrameSource.AddGesture(gesture);
                }
            }
        }
    }
Пример #2
0
        //Constractor
        public GestureDetector(KinectSensor _sensor, GestureAnalysis _gestureAnalysis, Exercise _currentExercise)
        {
            if (_sensor == null)
            {
                throw new ArgumentNullException("kinectSensor");
            }

            if (_gestureAnalysis == null)
            {
                throw new ArgumentNullException("gestureResultView");
            }

            this._sensor = _sensor;
            this._gestureAnalysis = _gestureAnalysis;

            // create the vgb source. The associated body tracking ID will be set when a valid body frame arrives from the sensor.
            vgbFrameSource = new VisualGestureBuilderFrameSource(_sensor, 0);
            //vgbFrameSource.TrackingIdLost += Source_TrackingIdLost;

            // open the reader for the vgb frames
            vgbFrameReader = vgbFrameSource.OpenReader();
            if (this.vgbFrameReader != null)
            {
                vgbFrameReader.IsPaused = true;
                vgbFrameReader.FrameArrived += VgbFrameReader_FrameArrived;
            }

            // load all gestures from the gesture database
            if (File.Exists(_currentExercise.DBPath))
            {
                using (var database = new VisualGestureBuilderDatabase(_currentExercise.DBPath))
                {
                    vgbFrameSource.AddGestures(database.AvailableGestures);

                    //setup the continuous gesture
                    foreach (var gesture in database.AvailableGestures)
                    {
                        if (gesture.Name.Equals(_currentExercise.ContinuousGestureName))
                        {
                            ContinuousGestureData = gesture;
                            break;
                        }
                    }
                }

                //todo - implmnt gesture disable
                foreach (var gesutre in this.vgbFrameSource.Gestures)
                {
                    foreach (var notTrackGesture in _currentExercise.VTGestureList)
                    {
                        if (gesutre.Name.Equals(notTrackGesture.GestureName) && !notTrackGesture.IsTrack)
                        {
                            vgbFrameSource.SetIsEnabled(gesutre, false);
                        }
                    }
                }
            }
        }
        public void Dispose()
        {
            _vgbFrameReader.IsPaused = true;
            _vgbFrameReader.Dispose();
            _vgbFrameReader = null;

            _vgbFrameSource.Dispose();
            _vgbFrameSource.Dispose();
        }
Пример #4
0
        public GestureTracker(KinectSensor sensor, string gesturesDB)
        {
            _gestureSource = new VisualGestureBuilderFrameSource(sensor, 0);
            _gestureReader = _gestureSource.OpenReader();

            IsPaused = true;

            using (VisualGestureBuilderDatabase db = new VisualGestureBuilderDatabase(gesturesDB))
            {
                _gestureSource.AddGestures(db.AvailableGestures);
            }
        }
Пример #5
0
        public void Dispose()
        {
            if (_gestureReader != null)
            {
                _gestureReader.Dispose();
            }
            _gestureReader = null;

            if (_gestureSource != null)
            {
                _gestureSource.Dispose();
            }
            _gestureSource = null;
        }
Пример #6
0
        //
        public GestureDetector(KinectSensor sensor, string databaseFilename)
        {
            // check
            if (sensor == null)
            {
                Debug.LogError("There is not Kinect Device.");
                return;
            }

            // 创建VGB帧数据源
            m_VGBSource = VisualGestureBuilderFrameSource.Create(sensor, 0);
            m_VGBSource.TrackingIdLost += this.Source_TrackingIdLost;

            // 获得VGB帧读取器
            m_VGBReader = m_VGBSource.OpenReader();

            // check
            if (m_VGBReader != null)
            {
                m_VGBReader.IsPaused = true;
                m_VGBReader.FrameArrived += GestureFrameArrived;
                //Debug.Log("VGBFrameReader is paused");
            } else
            {
                Debug.LogError("Can not get VGBReader.");
                return;
            }

            // 加载手势特征库
            var databasePath = Path.Combine(Application.streamingAssetsPath, databaseFilename);
            m_VGBDatabase = VisualGestureBuilderDatabase.Create(databasePath);

            if (m_VGBDatabase != null)
            {
                m_VGBGestures = m_VGBDatabase.AvailableGestures;
            } else
            {
                Debug.LogError("Can not load VGBDatabase.");
                return;
            }

            //
            m_bInit = true;
        }
Пример #7
0
 public GestureDetector(KinectSensor kinectSensor,GestureResultView gestureResultView)
 {
     if(kinectSensor == null)
     {
         throw new ArgumentException("Kinect sensor is null");
     }
     if(gestureResultView == null)
     {
         throw new ArgumentException("GestureResultView is null");
     }
     GestureResultView = gestureResultView;
     gestureFrameSource = new VisualGestureBuilderFrameSource(kinectSensor, 0);
     gestureFrameSource.TrackingIdLost += Source_TackingiIdLost;
     gestureFrameReader = gestureFrameSource.OpenReader();
     if(gestureFrameReader != null)
     {
         gestureFrameReader.IsPaused = true;
         gestureFrameReader.FrameArrived += GestureFrameArrived;
     }
     using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(GESTURE_DATABASE))
     {
         //load all available gesture from database
         //May need optimization when the gesture list gets really large
         gestureFrameSource.AddGestures(database.AvailableGestures);
     }
     
     gestureNameList = new ReadOnlyCollection<string>
         (
             new string[]
             {
                 WALKING_FORWARD_NAME,
                 JUMPING_GESTURE_NAME,
                 LEFT_CLICK_NAME,
                 RIGHT_CLICK_NAME,
                 OPEN_INVENTORY_NAME,
                 MOVE_MOUSE_LEFT,
                 MOVE_MOUSE_RIGHT,
                 MOVE_MOUSE_UP,
                 MOVE_MOUSE_DOWN,
                 STOP_GESTURE
             }
         );
 }
Пример #8
0
        /// <summary>
        /// Initializes a new instance of the GestureDetector class along with the gesture frame source and reader
        /// </summary>
        /// <param name="kinectSensor">Active sensor to initialize the VisualGestureBuilderFrameSource object with</param>
        /// <param name="gestureResultView">GestureResultView object to store gesture results of a single body to</param>
        /// <param name="database"></param>
        public GestureDetector(KinectSensor kinectSensor, GestureResultView gestureResultView, GestureDatabase database)
        {
            try
            {
                if (kinectSensor == null)
                {
                    throw new ArgumentNullException("kinectSensor");
                }

                if (gestureResultView == null)
                {
                    throw new ArgumentNullException("gestureResultView");
                }

                GestureResultView = gestureResultView;

                // create the vgb source. The associated body tracking ID will be set when a valid body frame arrives from the sensor.
                _vgbFrameSource = new VisualGestureBuilderFrameSource(kinectSensor, 0);
                _vgbFrameSource.TrackingIdLost += Source_TrackingIdLost;

                // open the reader for the vgb frames
                _vgbFrameReader = _vgbFrameSource.OpenReader();
                if (_vgbFrameReader != null)
                {
                    _vgbFrameReader.IsPaused = true;
                    _vgbFrameReader.FrameArrived += Reader_GestureFrameArrived;
                }

                if (database != null)
                {
                    _gestures.AddRange(database.GestureNames);
                    foreach (var gesture in database.Gestures)
                    {
                        _vgbFrameSource.AddGesture(gesture);
                        //_vgbFrameSource.SetIsEnabled(gesture, true);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Warn(ex.Message);
            }
        }
        public GestureScan(KinectSensor kinectSensor, ulong trackingId, VisualGestureBuilderDatabase visualGestureBuilderDatabase)
        {
            TrackingId = trackingId;

            _vgbFrameSource = new VisualGestureBuilderFrameSource(kinectSensor, 0);

            _vgbFrameSource.TrackingIdLost += OnTrackingIdLost;

            _vgbFrameReader = _vgbFrameSource.OpenReader();
            _vgbFrameReader.IsPaused = true;
            _vgbFrameReader.FrameArrived += OnFrameArrived;

            foreach (var gesture in visualGestureBuilderDatabase.AvailableGestures)
            {
                _vgbFrameSource.AddGesture(gesture);
            }

            _vgbFrameSource.TrackingId = trackingId;
            _vgbFrameReader.IsPaused = false;
        }
Пример #10
0
        /// <summary>
        /// Initializes a new instance of the GestureDetector class along with the gesture frame source and reader
        /// </summary>
        /// <param name="kinectSensor">Active sensor to initialize the VisualGestureBuilderFrameSource object with</param>
        /// <param name="gestureResultView">GestureResultView object to store gesture results of a single body to</param>
        public GestureDetector(KinectSensor kinectSensor)
        {
            if (kinectSensor == null)
            {
                throw new ArgumentNullException("kinectSensor");
            }

            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(500);
            timer.Tick += (sender, args) =>
            {
                isCoolingDown = false;
                timer.Stop();
            };

            // 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 the 'Seated' gesture from the gesture database
            using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(this.gestureDatabase))
            {
                // 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
                foreach (Gesture gesture in database.AvailableGestures)
                {
                    if (this.gestureNames.Contains(gesture.Name))
                    {
                        this.vgbFrameSource.AddGesture(gesture);
                    }
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Initializes a new instance of the GestureDetector class along with the gesture frame source and reader
        /// </summary>
        /// <param name="kinectSensor">Active sensor to initialize the VisualGestureBuilderFrameSource object with</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;
            this.GestureResultView.setNumGestures(this.num_gestures);
            this.num_gestures = 0;
            // 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 the 'Seated' gesture from the gesture database
            System.Diagnostics.Debug.WriteLine(this.gestureDatabase);
            using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(this.gestureDatabase))
            {
                // 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);
                foreach (Gesture gesture in database.AvailableGestures)
                {
                    this.vgbFrameSource.AddGesture(gesture);
                    this.num_gestures++;
                }
            }
        }
    // Use this for initialization
    void Start()
    {
        _kinect = KinectSensor.GetDefault();

        _gestureDatabase = VisualGestureBuilderDatabase.Create(Application.streamingAssetsPath + "/squat.gba");
        _gestureFrameSource = VisualGestureBuilderFrameSource.Create(_kinect, 0);

        foreach (var gesture in _gestureDatabase.AvailableGestures)
        {
            _gestureFrameSource.AddGesture(gesture);

            if (gesture.Name == "Squat")
            {
                _squat = gesture;
            }
        }

        _gestureFrameReader = _gestureFrameSource.OpenReader();
        _gestureFrameReader.IsPaused = true;
        _gestureFrameReader.FrameArrived += _gestureFrameReader_FrameArrived;
    }
Пример #13
0
    /// <summary>
    /// Initializes a new instance of the GestureDetector class along with the gesture frame source and reader
    /// </summary>
    /// <param name="kinectSensor">Active sensor to initialize the VisualGestureBuilderFrameSource object with</param>
    public GestureDetector(KinectSensor kinectSensor, KinectManager kinectManager)
    {
        Debug.Log ("got to GestureDetector method");
        this.kinectManager = kinectManager;

        if (kinectSensor == null)
        {
            throw new ArgumentNullException("kinectSensor");
        }

        // create the vgb source. The associated body tracking ID will be set when a valid body frame arrives from the sensor.
        this.vgbFrameSource = VisualGestureBuilderFrameSource.Create(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 the 'Magic101' gesture from the gesture database
        var databasePath = Path.Combine(Application.streamingAssetsPath, this.gestureDatabase);
        using (VisualGestureBuilderDatabase database = VisualGestureBuilderDatabase.Create(databasePath))
        {
            // 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
            foreach (Gesture gesture in database.AvailableGestures)
            {
                if(gesture.Name == "stretch")
                {
                    this.vgbFrameSource.AddGesture(gesture);
                }
            }
        }
    }
Пример #14
0
    // Use this for initialization
    void Start()
    {
        fasterhappened = false;
        slowerhappened = false;

        _Sensor = KinectSensor.GetDefault();
        if(_Sensor != null)
        {

            if(!_Sensor.IsOpen)
            {
                _Sensor.Open();
            }

            // Set up Gesture Source
            _Source = VisualGestureBuilderFrameSource.Create(_Sensor, 0);

            // open the reader for the vgb frames
            _Reader = _Source.OpenReader();
            if(_Reader != null)
            {
                _Reader.IsPaused = true;
                _Reader.FrameArrived += GestureFrameArrived;
            }

            // load the 'Seated' gesture from the gesture database
            string path = System.IO.Path.Combine(Application.streamingAssetsPath, databasePath);
            // TODO path irgendwann nicht mehr hardcoden
            _Database = VisualGestureBuilderDatabase.Create("Assets/Streaming Assets/gestures.gbd");

            // Load all gestures
            IList<Gesture> gesturesList = _Database.AvailableGestures;
            for(int g = 0; g < gesturesList.Count; g++)
            {
                Gesture gesture = gesturesList[g];
                _Source.AddGesture(gesture);
            }

        }
    }
        internal override void OnStop()
        {
            if (_frameReader != null)
            {
                _frameReader.FrameArrived -= FrameArrived;
                _frameReader.Dispose();
                _frameReader = null;
            }

            if (_frameSource != null)
            {
                _frameSource.Dispose();
                _frameSource = null;
            }
        }
        internal override void OnStart()
        {
            // Create the vgb source. The associated body tracking ID will be set when a valid body frame arrives from the sensor.
            _frameSource = new VisualGestureBuilderFrameSource(Manager.Sensor, 0);

            // Open the reader for the vgb frames
            _frameReader = _frameSource.OpenReader();
            if (_frameReader != null)
            {
                _frameReader.FrameArrived += FrameArrived;
            }

            // Load all gestures
            using (var database = new VisualGestureBuilderDatabase(DatabasePath))
            {
                foreach (var gesture in database.AvailableGestures)
                {
                    Console.WriteLine("Adding gesture {0} {1}", gesture.Name, gesture.GestureType);
                    _frameSource.AddGesture(gesture);
                }
            }
        }
        private void OnTrackingIdLost(object sender, TrackingIdLostEventArgs e)
        {
            _vgbFrameReader.IsPaused = true;
            _vgbFrameReader.Dispose();
            _vgbFrameReader = null;

            _vgbFrameSource.Dispose();
            _vgbFrameSource.Dispose();

            var tmpTrackingIdLost = TrackingIdLost;

            if (tmpTrackingIdLost != null)
                tmpTrackingIdLost(this, EventArgs.Empty);
        }
Пример #18
0
 void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (multiFrameReader != null)
     {
         multiFrameReader.Dispose();
         multiFrameReader = null;
     }
     if (gestureFrameReader != null)
     {
         gestureFrameReader.Dispose();
         gestureFrameReader = null;
     }
     if (kinect != null)
     {
         kinect.Close();
         kinect = null;
     }
 }
Пример #19
0
 /// <summary>
 /// Dispose the frame and reader objects
 /// </summary>
 /// <param name="disposing">True if this method is directly called,false if the GC handles the disposing</param>
 public virtual void Dispose(bool disposing)
 {
     if(disposing)
     {
         if(gestureFrameReader !=  null)
         {
             gestureFrameReader.FrameArrived -= GestureFrameArrived;
             gestureFrameReader.Dispose();
             gestureFrameReader = null;
         }
         if(gestureFrameSource != null)
         {
             gestureFrameSource.TrackingIdLost -= Source_TackingiIdLost;
             gestureFrameSource.Dispose();
             gestureFrameSource = null;
         }
     }
 }
Пример #20
0
        private void FinishVisualGestures()
        {
            if (vgbFrameReader != null)
            {
                vgbFrameReader.Dispose();
                vgbFrameReader = null;
            }

            if (vgbFrameSource != null)
            {
                vgbFrameSource.Dispose();
                vgbFrameSource = null;
            }

            if (gestureData != null)
            {
                gestureData.Clear();
            }
        }
Пример #21
0
        private void InitKinect()
        {
            Size displaySize = new Size(0, 0);
            this.kinectSensor = KinectSensor.GetDefault();

            if (this.kinectSensor != null)
            {
                this.kinectSensor.Open();

                var frameDescription = this.kinectSensor.DepthFrameSource.FrameDescription;
                displaySize.Width= frameDescription.Width;
                displaySize.Height = frameDescription.Height;
                gestureDatabase = new VisualGestureBuilderDatabase(@"../../../Gestures/gestures.gbd");
                gestureFrameSource = new VisualGestureBuilderFrameSource(this.kinectSensor, 0);
                this.discreteGestures = new List<Gesture>();
                this.continuousGestures = new List<Gesture>();

                foreach (Gesture gesture in gestureDatabase.AvailableGestures)
                {
                    if (gesture.GestureType == GestureType.Discrete)
                    {
                        this.discreteGestures.Add(gesture);
                    }
                    else if (gesture.GestureType == GestureType.Continuous)
                    {
                        this.continuousGestures.Add(gesture);
                    }

                    this.gestureFrameSource.AddGesture(gesture);
                }

                this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader();
                this.gestureFrameReader = gestureFrameSource.OpenReader();
                this.gestureFrameReader.IsPaused =true;
                this.gestureFrameReader.FrameArrived += gestureFrameReader_FrameArrived;

                this.UptimeText = Properties.Resources.InitializingStatusTextFormat;

            }
            else
            {
                this.UptimeText = Properties.Resources.NoSensorFoundText;
            }

            this.kinectCanvas = new KinectCanvas(this.kinectSensor, displaySize);
        }
Пример #22
0
        public void Evaluate(int SpreadMax)
        {
            if (this.FInvalidateConnect)
            {
                if (runtime != null)
                {
                    this.runtime.SkeletonFrameReady -= SkeletonReady;
                    if (this.vgbFrameReader != null)
                    {
                        this.vgbFrameReader.FrameArrived -= vgbFrameReader_FrameArrived;
                        this.vgbFrameReader.Dispose();
                        this.vgbFrameReader = null;
                    }
                    if (this.vgbFrameSource != null)
                    {
                        this.vgbFrameSource.Dispose();
                        this.vgbFrameSource = null;
                    }
                }

                if (this.FInRuntime.PluginIO.IsConnected)
                {
                    //Cache runtime node
                    this.runtime = this.FInRuntime[0];

                    if (runtime != null)
                    {
                        this.vgbFrameSource = new VisualGestureBuilderFrameSource(this.runtime.Runtime, 0);
                        this.vgbFrameReader = this.vgbFrameSource.OpenReader();
                        this.vgbFrameReader.FrameArrived += vgbFrameReader_FrameArrived;
                        this.runtime.SkeletonFrameReady += SkeletonReady;
                    }

                }
                this.FInvalidateConnect = false;
            }

            if (this.gesturefile.IsChanged)
            {
                string s = this.gesturefile[0];

                this.Reset();

                try
                {
                    this.database = new VisualGestureBuilderDatabase(s);

                    this.gesturenames.SliceCount = (int)this.database.AvailableGesturesCount;
                    this.gesturetype.SliceCount = this.gesturenames.SliceCount;
                    this.gesturedetected.SliceCount = this.gesturenames.SliceCount;
                    this.gestureconfidence.SliceCount = this.gesturenames.SliceCount;
                    this.gestureprogress.SliceCount = this.gesturenames.SliceCount;

                    int cnt = 0;
                    foreach (Gesture g in database.AvailableGestures)
                    {
                        this.gesturenames[cnt] = g.Name;
                        this.gesturetype[cnt] = g.GestureType;
                        this.vgbFrameSource.AddGesture(g);
                        cnt++;
                    }
                }
                catch (Exception ex)
                {
                    this.logger.Log(ex);
                }
            }
        }
Пример #23
0
        /// <summary>
        /// 初期設定
        /// </summary>
        private void Initialize()
        {
            // ColorImageの初期設定
            colorFrameDescription = kinect.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);
            colorImage = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96, 96, PixelFormats.Bgra32, null);
            ImageColor.Source = colorImage;

            // Bodyの初期設定
            bodies = new Body[kinect.BodyFrameSource.BodyCount];

            // Gesturesの初期設定
            gestureDatabase = new VisualGestureBuilderDatabase(@"../../Gestures/Jump.gbd");
            gestureFrameSource = new VisualGestureBuilderFrameSource(kinect, 0);

            // 使用するジェスチャーをデータベースから取り出す
            foreach (var gesture in gestureDatabase.AvailableGestures)
            {
                if (gesture.Name == "Jump")
                {
                    jump = gesture;
                }
                if (gesture.Name == "JumpProgress")
                {
                    jumpProgress = gesture;
                }
                this.gestureFrameSource.AddGesture(gesture);
            }

            // ジェスチャーリーダーを開く
            gestureFrameReader = gestureFrameSource.OpenReader();
            gestureFrameReader.IsPaused = true;
            gestureFrameReader.FrameArrived += gestureFrameReader_FrameArrived;

            // フレームリーダーを開く (Color / Body)
            multiFrameReader = kinect.OpenMultiSourceFrameReader(FrameSourceTypes.Color | FrameSourceTypes.Body);
            multiFrameReader.MultiSourceFrameArrived += multiFrameReader_MultiSourceFrameArrived;
        }
Пример #24
0
        private bool InitVisualGestures()
        {
            KinectManager kinectManager = KinectManager.Instance;
            KinectInterop.SensorData sensorData = kinectManager != null ? kinectManager.GetSensorData() : null;

            Kinect2Interface kinectInterface = sensorData.sensorInterface as Kinect2Interface;
            KinectSensor kinectSensor = kinectInterface != null ? kinectInterface.kinectSensor : null;

            if (kinectSensor == null)
                return false;

            if (gestureDatabase == string.Empty)
            {
                Debug.LogError("Please specify gesture database file!");
                return false;
            }

            // copy the gesture database file from Resources, if available
            if (!File.Exists(gestureDatabase))
            {
                TextAsset textRes = Resources.Load(gestureDatabase, typeof(TextAsset)) as TextAsset;

                if (textRes != null && textRes.bytes.Length != 0)
                {
                    File.WriteAllBytes(gestureDatabase, textRes.bytes);
                }
            }

            // create the vgb source
            vgbFrameSource = VisualGestureBuilderFrameSource.Create(kinectSensor, 0);

            // open the reader
            vgbFrameReader = vgbFrameSource != null ? vgbFrameSource.OpenReader() : null;
            if (vgbFrameReader != null)
            {
                vgbFrameReader.IsPaused = true;
            }

            using (VisualGestureBuilderDatabase database = VisualGestureBuilderDatabase.Create(gestureDatabase))
            {
                if (database == null)
                {
                    Debug.LogError("Gesture database not found: " + gestureDatabase);
                    return false;
                }

                // check if we need to load all gestures
                bool bAllGestures = (gestureNames.Count == 0);

                foreach (Gesture gesture in database.AvailableGestures)
                {
                    bool bAddGesture = bAllGestures || gestureNames.Contains(gesture.Name);

                    if (bAddGesture)
                    {
                        string sGestureName = gesture.Name;
                        vgbFrameSource.AddGesture(gesture);

                        if (!gestureNames.Contains(sGestureName))
                        {
                            gestureNames.Add(sGestureName);
                        }

                        if (!gestureData.ContainsKey(sGestureName))
                        {
                            VisualGestureData data = new VisualGestureData();
                            data.gestureName = sGestureName;
                            data.isDiscrete = (gesture.GestureType == GestureType.Discrete);
                            data.isContinuous = (gesture.GestureType == GestureType.Continuous);
                            data.timestamp = Time.realtimeSinceStartup;

                            gestureData.Add(sGestureName, data);
                        }
                    }
                }
            }

            return true;
        }
Пример #25
0
        /// <summary>
        /// Disposes the VisualGestureBuilderFrameSource and VisualGestureBuilderFrameReader objects
        /// </summary>
        /// <param name="disposing">True if Dispose was called directly, false if the GC handles the disposing</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (this.vgbFrameReader != null)
                {
                    this.vgbFrameReader.FrameArrived -= this.Reader_GestureFrameArrived;
                    this.vgbFrameReader.Dispose();
                    this.vgbFrameReader = null;
                }

                if (this.vgbFrameSource != null)
                {
                    this.vgbFrameSource.TrackingIdLost -= this.Source_TrackingIdLost;
                    this.vgbFrameSource.Dispose();
                    this.vgbFrameSource = null;
                }
            }
        }
Пример #26
0
        private void MainWindow_Closing(object sender, CancelEventArgs e)
        {
            if (this.bodyFrameReader != null)
            {
                this.bodyFrameReader.Dispose();
                this.bodyFrameReader = null;
            }

            if (this.kinectSensor != null)
            {
                this.kinectSensor.Close();
                this.kinectSensor = null;
            }

            if (this.gestureFrameReader != null)
            {
                this.gestureFrameReader.Dispose();
                this.gestureFrameReader = null;
            }
        }
            /// <summary>
            /// Initializes a new instance of the GestureDetector class along with the gesture frame source and reader
            /// </summary>
            /// <param name="kinectSensor">Active sensor to initialize the VisualGestureBuilderFrameSource object with</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;

                // 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 the gestures from the gesture database
                using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(this.gestureDatabase))
                {
                    vgbFrameSource.AddGestures(database.AvailableGestures);
                }
            }
Пример #28
0
        /// <summary>
        /// Disposes the VisualGestureBuilderFrameSource and VisualGestureBuilderFrameReader objects
        /// </summary>
        /// <param name="disposing">True if Dispose was called directly, false if the GC handles the disposing</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                //
                m_VGBGestures = null;

                //
                if (m_VGBReader != null)
                {
                    m_VGBReader.FrameArrived -= GestureFrameArrived;
                    m_VGBReader.Dispose();
                    m_VGBReader = null;
                }

                //
                if (m_VGBSource != null)
                {
                    m_VGBSource.TrackingIdLost -= Source_TrackingIdLost;
                    m_VGBSource.Dispose();
                    m_VGBSource = null;
                }

                //
                if (m_VGBDatabase != null)
                {
                    m_VGBDatabase.Dispose();
                    m_VGBDatabase = null;
                }
            }
        }