Пример #1
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);
                        }
                    }
                }
            }
        }
Пример #2
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);
            }
        }
Пример #3
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;
        }
Пример #4
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
             }
         );
 }
Пример #5
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;
        }
    // 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;
    }
Пример #8
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);
            }

        }
    }
Пример #9
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);
        }
Пример #10
0
        void InitializeGesture()
        {
            gestureFrameReaders = new VisualGestureBuilderFrameReader[BODY_COUNT];
            for ( int count =0; count < BODY_COUNT; count++ ) {
                VisualGestureBuilderFrameSource gestureFrameSource;
                gestureFrameSource = new VisualGestureBuilderFrameSource( kinect, 0 );
                gestureFrameReaders[count] = gestureFrameSource.OpenReader();
                gestureFrameReaders[count].FrameArrived += gestureFrameReaders_FrameArrived;
            }

            VisualGestureBuilderDatabase gestureDatabase;
            gestureDatabase = new VisualGestureBuilderDatabase( "SampleDatabase.gbd" );

            uint gestureCount;
            gestureCount = gestureDatabase.AvailableGesturesCount;
            gestures = gestureDatabase.AvailableGestures;
            for ( int count = 0; count<BODY_COUNT; count++ ) {
                VisualGestureBuilderFrameSource gestureFrameSource;
                gestureFrameSource = gestureFrameReaders[count].VisualGestureBuilderFrameSource;
                gestureFrameSource.AddGestures( gestures );
                foreach ( var g in gestures ) {
                    gestureFrameSource.SetIsEnabled( g, true );
                }
            }
        }
Пример #11
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;
        }
Пример #12
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;
        }
        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);
                }
            }
        }