Exemplo n.º 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>
        /// <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;
    }
Exemplo n.º 4
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);
            }

        }
    }
        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;
        }
        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);
                }
            }
        }