public GestureDatabase(IList<string> dbList) { _gestures = new List<Gesture>(); _gestureImageDict = new Dictionary<string, ImageSource>(); foreach (var db in dbList) { using (var database = new VisualGestureBuilderDatabase(db)) { foreach (var gesture in database.AvailableGestures) { Log.InfoFormat("Adding gesture from db : {0}", gesture.Name); _gestures.Add(gesture); string uri = string.Concat("Images\\", gesture.Name, ".png"); if (CanLoadResource(new Uri(uri, UriKind.Relative))) { _gestureImageDict.Add(gesture.Name, new BitmapImage(new Uri(uri, UriKind.Relative))); } } } } _gestureImageDict.Add(Perception.GestureNames.None, new BitmapImage(new Uri(@"Images\None.png", UriKind.Relative))); _gestureImageDict.Add(Perception.GestureNames.NotTracked, new BitmapImage(new Uri(@"Images\NotTracked.png", UriKind.Relative))); }
//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 GestureManager(KinectSensor kinectSensor, string visualGestureBuilderDatabaseFileName) { _kinectSensor = kinectSensor; _visualGestureBuilderDatabase = new VisualGestureBuilderDatabase(visualGestureBuilderDatabaseFileName); _scans = new ConcurrentDictionary<ulong, GestureScan>(); _bodies = new List<Body>(_kinectSensor.BodyFrameSource.BodyCount); Delay = 4000; }
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); } }
/// <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 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 (gesture.Name.Equals(this.seatedGestureName)) // { // this.vgbFrameSource.AddGesture(gesture); // } //} // 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.handsAboveHeadGestureName)) { this.vgbFrameSource.AddGesture(gesture); } } } }
// 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; }
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 } ); }
/// <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, string name) { if (kinectSensor == null) { throw new ArgumentNullException("kinectSensor"); } gestureName = name; // 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 named gesture from the gesture database using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(this.gestureDatabase)) { bool found = false; // 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) { int i = 1; if (gesture.Name==this.gestureName) { this.vgbFrameSource.AddGesture(gesture); found = true; } } if(found == false) { throw new ArgumentNullException("gestureName"); } } }
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; }
/// <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); } } } }
// 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; }
// 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 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); }
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); } } }
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); } } }
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 ); } } }
/// <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; } } }
/// <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; }
private void Reset() { if (database != null) { this.database.Dispose(); this.database = 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); } }