예제 #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, 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++;
                }
            }
        }
예제 #2
0
        public GestureDetector(KinectSensor kinectSensor, string dataBase, string gestureName, int refID, VirtualKeyCode key, float thresh)
        {
            if (kinectSensor == null)
            {
                throw new ArgumentNullException("kinectSensor");
            }


            gestureDatabase = dataBase;
            dataName        = gestureName;
            //pressKey = key;
            keyPress    = key;
            threshHold  = thresh;
            referenceID = refID;

            // 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 (gesture.Name.Equals(this.dataName))
                    {
                        this.vgbFrameSource.AddGesture(gesture);
                    }
                }
            }
        }
예제 #3
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;

            // 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 'all gestures' 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);
                    //System.Windows.MessageBox.Show("Detected");
                    //}
                }
            }
        }
예제 #4
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.ClosedHandState = false;

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

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

            // load all gestures from the gesture database
            using (var database = new VisualGestureBuilderDatabase(this.gestureDatabase))
            {
                this.vgbFrameSource.AddGestures(database.AvailableGestures);
            }

            // disable the set of gestures which determine the 'keep straight' behavior, we will use hand state instead

            /* foreach (var gesture in this.vgbFrameSource.Gestures)
             * {
             *   if (gesture.Name.Equals(this.Kill_gesture) || gesture.Name.Equals(this.Pray_gesture))
             *   {
             *       this.vgbFrameSource.SetIsEnabled(gesture, false);
             *   }
             * }*/
        }
예제 #5
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     this.kinect = KinectSensor.GetDefault();
     this.kinect.IsAvailableChanged += this.Sensor_IsAvailableChanged;
     this.StatusText  = this.kinect.IsAvailable ? "A Kinect está ativa." : "A Kinect está desativada!";
     this.GestureText = "Nenhum gesto detetado.";
     this.DataContext = this;
     _gm             = new GestureMod();
     bodyFrameReader = kinect.BodyFrameSource.OpenReader();
     bodyFrameReader.FrameArrived += bodyFrameArrived;
     bodyFrameReader.IsPaused      = false;
     vgbDb          = new VisualGestureBuilderDatabase(@"Gestures\IM_Gestures.gbd");
     vgbFrameSource = new VisualGestureBuilderFrameSource(KinectSensor.GetDefault(), 0);
     foreach (var g in vgbDb.AvailableGestures)
     {
         vgbFrameSource.AddGesture(g);
     }
     vgbFrameReader = vgbFrameSource.OpenReader();
     vgbFrameReader.FrameArrived += vgbFrameArrived;
     kinect.Open();
 }
예제 #6
0
        public Detector(KinectSensor kinectSensor)
        {
            this.vgbFrameSource = new VisualGestureBuilderFrameSource(kinectSensor, 0);
            // open the reader for the vgb frames
            this.vgbFrameReader = this.vgbFrameSource.OpenReader();
            if (this.vgbFrameReader != null)
            {
                this.vgbFrameReader.IsPaused      = true;
                this.vgbFrameReader.FrameArrived += this.vgbFramereader_FrameArrived;
            }

            using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(this.databaseLocation))
            {
                // 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)
                {
                    this.vgbFrameSource.AddGesture(gesture);
                }
            }
        }
예제 #7
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)
        {
            //LCE = new LifeCycleEvents("ASR", "FUSION", "speech-1", "acoustic", "command");
            //MMIC = new MmiCommunication("localhost", 9876, "User1", "ASR");
            LCE  = new LifeCycleEvents("TOUCH", "FUSION", "touch-1", "touch", "command");
            MMIC = new MmiCommunication("localhost", 9876, "User1", "TOUCH");           //CHANGED TO USER1
            //LCE = new LifeCycleEvents("KINECT", "FUSION", "kinect-1", "kinect", "command");
            //MMIC = new MmiCommunication("localhost", 9876, "User1", "KINECT");
            MMIC.Send(LCE.NewContextRequest());

            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))
            {
                this.vgbFrameSource.AddGestures(database.AvailableGestures); //load all gestures from the database
            }
        }
예제 #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>
        public GestureDetector(KinectSensor kinectSensor, MainWindow window)
        {
            if (kinectSensor == null)
            {
                throw new ArgumentNullException("kinectSensor");
            }

            this.mainWindow    = window;
            this.gFrameHandler = new GestureFrameHandler(window);
            this.gFrameHandler.load("gestures.json");

            serverPipe = new AppServer(window);
            serverPipe.run();

            //init LifeCycleEvents..
            //new LifeCycleEvents("GESTURES", "FUSION", "gesture-1", "haptics", "command")
            lce  = new LifeCycleEvents("TOUCH", "FUSION", "touch-1", "touch", "command"); // LifeCycleEvents(string source, string target, string id, string medium, string mode)
            mmic = new MmiCommunication("localhost", 9876, "User1", "TOUCH");             //PORT TO FUSION - uncomment this line to work with fusion later
            //mmic = new MmiCommunication("localhost", 8000, "User1", "GESTURES"); // MmiCommunication(string IMhost, int portIM, string UserOD, string thisModalityName)

            mmic.Send(lce.NewContextRequest());

            // 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 all gestures from the gesture database
            using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(GestureNames.gestureDatabase))
            {
                vgbFrameSource.AddGestures(database.AvailableGestures);
            }
        }
예제 #9
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, MainWindow main)
        {
            this.GestureResultView = gestureResultView;
            this.main = main;
            if (kinectSensor == null)
            {
                throw new ArgumentNullException("kinectSensor");
            }

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

            //Init lifeCycleEvents
            lce  = new LifeCycleEvents("ASR", "IM", "gestures-1", "acoustic", "command"); // LifeCycleEvents(string source, string target, string id, string medium, string mode)
            mmic = new MmiCommunication("localhost", 9876, "User1", "ASR");               // MmiCommunication(string IMhost, int portIM, string UserOD, string thisModalityName)
            mmic.Send(lce.NewContextRequest());

            // 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))
            {
                // 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
                this.vgbFrameSource.AddGestures(database.AvailableGestures);
            }
        }
예제 #10
0
        public MainWindow()
        {
            this.lastResult = 0;
            this.InitializeComponent();
            this.expression = "";
            this._calc      = new Calculator();
            this.gotResult  = false;

            this.lce  = new LifeCycleEvents("GESTURES", "FUSION", "gm-1", "gestures", "command");
            this.mmic = new MmiCommunication("localhost", 8000, "User1", "GESTURES");
            mmic.Send(lce.NewContextRequest());

            KinectRegion.SetKinectRegion(this, kinectRegion);
            App app = ((App)Application.Current);

            app.KinectRegion = kinectRegion;

            // Use the default sensor
            this.kinectRegion.KinectSensor = KinectSensor.GetDefault();
            this.kinectRegion.KinectSensor.Open();

            bodies = new Body[this.kinectRegion.KinectSensor.BodyFrameSource.BodyCount];

            gestureDatabase    = new VisualGestureBuilderDatabase(@"gestures.gbd");
            gestureFrameSource = new VisualGestureBuilderFrameSource(this.kinectRegion.KinectSensor, 0);

            foreach (var gesture in gestureDatabase.AvailableGestures)
            {
                this.gestureFrameSource.AddGesture(gesture);
            }

            gestureFrameSource.TrackingId    = 1;
            gestureFrameReader               = gestureFrameSource.OpenReader();
            gestureFrameReader.IsPaused      = true;
            gestureFrameReader.FrameArrived += gestureFrameReader_FrameArrived;

            multiFrameReader = this.kinectRegion.KinectSensor.OpenMultiSourceFrameReader(FrameSourceTypes.Body);
            multiFrameReader.MultiSourceFrameArrived += multiFrameReader_MultiSourceFrameArrived;
        }
    // Use this for initialization
    void Start()
    {
        _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);
            Debug.Log("Database path is: " + path);
            _Database = VisualGestureBuilderDatabase.Create(path);

            // Load all gestures
            IList <Gesture> gesturesList = _Database.AvailableGestures;
            for (int g = 0; g < gesturesList.Count; g++)
            {
                Gesture gesture = gesturesList[g];
                Debug.Log("Database name is: " + gesture.Name);
                _Source.AddGesture(gesture);
            }
        }

        OnGesture += ShowInText;
        instance   = this;
    }
        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);
                }
            }
        }
예제 #13
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);
            }
        }
    }
예제 #14
0
        private void OpenGesureReader()
        {
            this.gestureSource = new VisualGestureBuilderFrameSource(this.kinect, 0);

            Console.WriteLine(gestureSource.IsActive);
            //add
            this.gestureSource.AddGesture(db.AvailableGestures.Where(g => g.Name == "backward").Single());
            this.gestureSource.AddGesture(db.AvailableGestures.Where(g => g.Name == "forward").Single());
            this.gestureSource.AddGesture(db.AvailableGestures.Where(g => g.Name == "fullscreenOFF").Single());
            this.gestureSource.AddGesture(db.AvailableGestures.Where(g => g.Name == "fullscreenON").Single());
            this.gestureSource.AddGesture(db.AvailableGestures.Where(g => g.Name == "Pause").Single());
            this.gestureSource.AddGesture(db.AvailableGestures.Where(g => g.Name == "play").Single());
            this.gestureSource.AddGesture(db.AvailableGestures.Where(g => g.Name == "stop").Single());
            this.gestureSource.AddGesture(db.AvailableGestures.Where(g => g.Name == "volumeDOWN").Single());
            this.gestureSource.AddGesture(db.AvailableGestures.Where(g => g.Name == "volumeUP").Single());

            this.gestureSource.TrackingIdLost += OnTrackingIdLost;

            this.gestureReader               = this.gestureSource.OpenReader();
            this.gestureReader.IsPaused      = true;
            this.gestureReader.FrameArrived += OnGestureFrameArrived;
        }
    void CleanUnValidBody(Hashtable _Hashnewids)
    {
        if (_Hashnewids != null)
        {
            ArrayList key = new ArrayList(HashIdtb.Keys);
            foreach (ulong id in key)
            {
                if (!_Hashnewids.ContainsKey(id)) //use the pass IDlist to check if the new IDlist still has that value
                {
                    Dictionary <VisualGestureBuilderFrameSource, VisualGestureBuilderFrameReader> tempgroup = HashIdtb[id] as Dictionary <VisualGestureBuilderFrameSource, VisualGestureBuilderFrameReader>;
                    //this is our bodyid coorespond to the gesture result
                    foreach (VisualGestureBuilderFrameSource single_group in tempgroup.Keys) // we only have 1 group in this dictionary
                    {
                        disposesource = single_group;
                        disposereader = tempgroup[single_group];
                    }
                    tempgroup.Clear();
                    if (disposesource != null)
                    {
                        disposesource.Dispose();
                        disposesource = null;
                    }
                    if (disposereader != null)
                    {
                        disposereader.IsPaused = true;
                        // disposereader.FrameArrived-=GestureFrameArrived;


                        disposereader.Dispose();
                        disposereader = null;
                    }
                    HashIdtb.Remove(id); //Remove the Id from our trackedIDtable(the "HashIdtb")
                    PlayerArgs.Remove(id);
                    Debug.Log("Remove a " + id);
                }
            }
        }
    }
예제 #16
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="stadingResultView">GestureResultView object to store gesture results of a single body to</param>
        public GestureDetector(KinectSensor kinectSensor, StandingResultView standingResultView, ArmsCrossedResultView armsCrossedResultView)
        {
            if (kinectSensor == null)
            {
                throw new ArgumentNullException("kinectSensor");
            }

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

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

            this.StandingResultView    = standingResultView;
            this.ArmsCrossedResultView = armsCrossedResultView;

            // 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))
            {
                this.vgbFrameSource.AddGestures(database.AvailableGestures);
            }
        }
예제 #17
0
    //Methof to initialise your kinect
    void InitKinect()
    {
        _getsureBasePath = Path.Combine(Application.streamingAssetsPath, "GestureDB/JumpDB.gbd");
        _dbGestures      = VisualGestureBuilderDatabase.Create(_getsureBasePath);
        _bodies          = new Windows.Kinect.Body[6];
        _kinect          = Windows.Kinect.KinectSensor.GetDefault();
        _kinect.Open();
        _gestureFrameSource = VisualGestureBuilderFrameSource.Create(_kinect, 0);

        //for each gesture in trained database of custom gestures - add them to kinect frame source
        foreach (Gesture gest in _dbGestures.AvailableGestures)
        {
            _gestureFrameSource.AddGesture(gest);
            if (gest.Name == "Jump")
            {
                _jump = gest;
            }
            else if (gest.Name == "Lean_Left")
            {
                _moveLeft = gest;
            }
            else if (gest.Name == "Lean_Right")
            {
                _moveRight = gest;
            }
            else if (gest.Name == "Swing")
            {
                _swing = gest;
            }
        }
        _bodyFrameSource = _kinect.BodyFrameSource;
        _bodyFrameReader = _bodyFrameSource.OpenReader();
        _bodyFrameReader.FrameArrived += _bodyFrameReader_FrameArrived;

        _gestureFrameReader               = _gestureFrameSource.OpenReader();
        _gestureFrameReader.IsPaused      = true;
        _gestureFrameReader.FrameArrived += _gestureFrameReader_FrameArrived;
    }
예제 #18
0
        void LoadGestures()
        {
            if (UserSettings.Instance.GESTURE_PATH.CompareTo("null") == 0)
            {
                return;
            }

            VisualGestureBuilderDatabase db = new VisualGestureBuilderDatabase(@UserSettings.Instance.GESTURE_PATH);

            this.openingGesture = db.AvailableGestures.Where(g => g.Name == "HandsApart").Single();
            this.closingGesture = db.AvailableGestures.Where(g => g.Name == "HandsTogether").Single();

            this._gestureSource = new VisualGestureBuilderFrameSource(this._sensor, 0);

            this._gestureSource.AddGesture(this.openingGesture);
            this._gestureSource.AddGesture(this.closingGesture);

            this._gestureSource.TrackingIdLost += OnTrackingIdLost;

            this._gestureReader               = this._gestureSource.OpenReader();
            this._gestureReader.IsPaused      = true;
            this._gestureReader.FrameArrived += OnGestureFrameArrived;
        }
 void InitializeGesture()
 {
     //ジェスチャーデータベースの初期設定、読み込み
     gestureDatabase    = new VisualGestureBuilderDatabase("dangerousmoves.gbd");
     gestureFrameSource = new VisualGestureBuilderFrameSource(kinect, 0);
     // 使用するジェスチャーをデータベースから取り出す
     foreach (var gesture in gestureDatabase.AvailableGestures)
     {
         if (gesture.Name == "wander")
         {
             wander = gesture;
         }
         else if (gesture.Name == "stare")
         {
             stare = gesture;
         }
         this.gestureFrameSource.AddGesture(gesture);
     }
     // ジェスチャーリーダーを開く
     gestureFrameReader               = gestureFrameSource.OpenReader();
     gestureFrameReader.IsPaused      = true;
     gestureFrameReader.FrameArrived += gestureFrameReader_FrameArrived;
 }
예제 #20
0
        void reader_FrameArrived(VisualGestureBuilderFrameReader sender, VisualGestureBuilderFrameArrivedEventArgs args)
        {
            using (var frame = args.FrameReference.AcquireFrame())
            {
                if (frame != null && frame.DiscreteGestureResults != null)
                {
                    var result = frame.DiscreteGestureResults[_salute];

                    if (result.Detected == true)
                    {
                        var progressResult = frame.ContinuousGestureResults[_saluteProgress];
                        Progress.Value = progressResult.Progress;
                    }
                    else
                    {
                        Progress.Value = 0.0;
                    }

                    GestureText.Text    = result.Detected ? "TRUE" : "FALSE";
                    ConfidenceText.Text = result.Confidence.ToString();
                }
            }
        }
예제 #21
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;
        }
예제 #22
0
        public GestureDetector(KinectSensor sensor, GestureResultView gestureResultView)
        {
            if (sensor == null)
            {
                throw new ArgumentNullException("sensor");
            }

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

            this.GestureResultView = gestureResultView;

            //Create the VGB source
            this.vgbFrameSource = new VisualGestureBuilderFrameSource(sensor, 0);
            this.vgbFrameSource.TrackingIdLost += this.Source_TrackingIdLost;

            this.vgbFrameReader = this.vgbFrameSource.OpenReader();
            if (this.vgbFrameReader != null)
            {
                this.vgbFrameReader.IsPaused      = true;
                this.vgbFrameReader.FrameArrived += this.Reader_GestureFrameArrived;
            }

            using (VisualGestureBuilderDatabase dB = new VisualGestureBuilderDatabase(this.gestureDatabase))
            {
                foreach (Gesture gesture in dB.AvailableGestures)
                {
                    if (gesture.Name.Equals(this.waveGestureName))
                    {
                        this.vgbFrameSource.AddGesture(gesture);
                    }
                }
            }
        }
예제 #23
0
        /// <summary>
        /// Initializes a new instance of the GestureDetector class along with the gesture frame source and reader
        /// 与手势框架源和阅读器一起初始化GestureDetector类的新实例
        /// </summary>
        /// <param name="kinectSensor">
        /// Active sensor to initialize the VisualGestureBuilderFrameSource object with
        /// 启动的传感器,用来初始化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.GestureResultView = gestureResultView;

            // 创建vgb源文件,当一个有效的身体帧从传感器到达时,相关的身体跟踪ID将被设置。
            // 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 a gesture from the gesture database
            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);
            }
        }
        /// <summary>
        ///Initialization of the gesture detector class. The GestureResultView has the discrete results for the gesture detector
        /// </summary>
        /// <param name="kinectSensor">The active Kinect Sensor</param>
        /// <param name="gestureResultView">It is an object which stores the gesture results</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 trained gesture using VGB from the gesture database
            using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(this.gestureDatabase))
            {
                // Load all available gestures in the database with a call to vgbFrameSource.AddGestures(database.AvailableGestures),
                foreach (Gesture gesture in database.AvailableGestures)
                {
                    this.vgbFrameSource.AddGesture(gesture);
                }
            }
        }
예제 #25
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(KinectModel model, KinectSensor kinectSensor)
        {
            this.kinectModel = model;

            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 = 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)
                {
                    //	TODO: MH - Add all gestures.
                    if (gesture.Name.Equals(this.waveGestureName))
                    {
                        this.vgbFrameSource.AddGesture(gesture);
                    }
                }
            }
        }
예제 #26
0
        public VgbGesturesEmiter(IObservable <KinectChanged> kinectChanged, IObservable <TrackedBodyReady> trackedBody)
        {
            kinectChanged.Subscribe(e =>
            {
                if (e.NewSeonsor != null)
                {
                    var dbFileName = GetDbFileName();
                    Console.WriteLine("DB file: " + dbFileName);
                    _gestureDatabase    = new VisualGestureBuilderDatabase(dbFileName);
                    _gestureFrameSource = new VisualGestureBuilderFrameSource(e.NewSeonsor, 0);

                    // Add all gestures in the database to the framesource..
                    _gestureFrameSource.AddGestures(_gestureDatabase.AvailableGestures);

                    foreach (var gesture in _gestureDatabase.AvailableGestures)
                    {
                        if (gesture.Name == "SwipeToLeft")
                        {
                            _states.Add(gesture.Name, new GestureState(gesture, 0.7f, OnGestureDetected));
                        }
                        else if (gesture.Name == "SwipeToRight")
                        {
                            _states.Add(gesture.Name, new GestureState(gesture, 1f, OnGestureDetected));
                        }
                    }

                    _gestureFrameReader = _gestureFrameSource.OpenReader();
                    _gestureFrameReader.FrameArrived += Reader_FrameArrived;
                }
            });

            trackedBody.Subscribe(e =>
            {
                _gestureFrameSource.TrackingId = e.Body.TrackingId;
            });
        }
예제 #27
0
    void Start()
    {
        _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 gesture from the gesture database
            string path = System.IO.Path.Combine(Application.streamingAssetsPath, databasePath);
            _Database1  = VisualGestureBuilderDatabase.Create(path + "/Intro.gbd");
            _Database2  = VisualGestureBuilderDatabase.Create(path + "/Onigiri.gbd");
            _Database3  = VisualGestureBuilderDatabase.Create(path + "/Move_on.gbd");
            _Database4  = VisualGestureBuilderDatabase.Create(path + "/Naja.gbd");
            _Database5  = VisualGestureBuilderDatabase.Create(path + "/Bangloey.gbd");
            _Database6  = VisualGestureBuilderDatabase.Create(path + "/Nidnid.gbd");
            _Database7  = VisualGestureBuilderDatabase.Create(path + "/ChoeyMoey.gbd");
            _Database8  = VisualGestureBuilderDatabase.Create(path + "/TakeUpArm.gbd");
            _Database9  = VisualGestureBuilderDatabase.Create(path + "/DrawBigHeart.gbd");
            _Database10 = VisualGestureBuilderDatabase.Create(path + "/Yeah.gbd");
            _Database11 = VisualGestureBuilderDatabase.Create(path + "/TourPai.gbd");
            _Database12 = VisualGestureBuilderDatabase.Create(path + "/Tummada.gbd");
            _Database13 = VisualGestureBuilderDatabase.Create(path + "/Move_down.gbd");
            _Database14 = VisualGestureBuilderDatabase.Create(path + "/Down_leg.gbd");
            _Database15 = VisualGestureBuilderDatabase.Create(path + "/LoveorNot.gbd");
            _Database16 = VisualGestureBuilderDatabase.Create(path + "/ComeOn.gbd");
            _Database17 = VisualGestureBuilderDatabase.Create(path + "/LetsCookie.gbd");
            _Database18 = VisualGestureBuilderDatabase.Create(path + "/Koisuru.gbd");
            _Database19 = VisualGestureBuilderDatabase.Create(path + "/FurtuneCookies.gbd");
            _Database20 = VisualGestureBuilderDatabase.Create(path + "/LetsWish.gbd");
            _Database21 = VisualGestureBuilderDatabase.Create(path + "/HenWing.gbd");
            _Database22 = VisualGestureBuilderDatabase.Create(path + "/Heyhey.gbd");
            _Database23 = VisualGestureBuilderDatabase.Create(path + "/Clap.gbd");
            _Database24 = VisualGestureBuilderDatabase.Create(path + "/Up_down.gbd");
            _Database25 = VisualGestureBuilderDatabase.Create(path + "/Hairoo.gbd");
            _Database26 = VisualGestureBuilderDatabase.Create(path + "/Rotate.gbd");
            _Database27 = VisualGestureBuilderDatabase.Create(path + "/End.gbd");
            _Database28 = VisualGestureBuilderDatabase.Create(path + "/Point.gbd");
            _Database29 = VisualGestureBuilderDatabase.Create(path + "/Side.gbd");


            // Load all gestures
            IList <Gesture> gesturesList1  = _Database1.AvailableGestures;
            IList <Gesture> gesturesList2  = _Database2.AvailableGestures;
            IList <Gesture> gesturesList3  = _Database3.AvailableGestures;
            IList <Gesture> gesturesList4  = _Database4.AvailableGestures;
            IList <Gesture> gesturesList5  = _Database5.AvailableGestures;
            IList <Gesture> gesturesList6  = _Database6.AvailableGestures;
            IList <Gesture> gesturesList7  = _Database7.AvailableGestures;
            IList <Gesture> gesturesList8  = _Database8.AvailableGestures;
            IList <Gesture> gesturesList9  = _Database9.AvailableGestures;
            IList <Gesture> gesturesList10 = _Database10.AvailableGestures;
            IList <Gesture> gesturesList11 = _Database11.AvailableGestures;
            IList <Gesture> gesturesList12 = _Database12.AvailableGestures;
            IList <Gesture> gesturesList13 = _Database13.AvailableGestures;
            IList <Gesture> gesturesList14 = _Database14.AvailableGestures;
            IList <Gesture> gesturesList15 = _Database15.AvailableGestures;
            IList <Gesture> gesturesList16 = _Database16.AvailableGestures;
            IList <Gesture> gesturesList17 = _Database17.AvailableGestures;
            IList <Gesture> gesturesList18 = _Database18.AvailableGestures;
            IList <Gesture> gesturesList19 = _Database19.AvailableGestures;
            IList <Gesture> gesturesList20 = _Database20.AvailableGestures;
            IList <Gesture> gesturesList21 = _Database21.AvailableGestures;
            IList <Gesture> gesturesList22 = _Database22.AvailableGestures;
            IList <Gesture> gesturesList23 = _Database23.AvailableGestures;
            IList <Gesture> gesturesList24 = _Database24.AvailableGestures;
            IList <Gesture> gesturesList25 = _Database25.AvailableGestures;
            IList <Gesture> gesturesList26 = _Database26.AvailableGestures;
            IList <Gesture> gesturesList27 = _Database27.AvailableGestures;
            IList <Gesture> gesturesList28 = _Database28.AvailableGestures;
            IList <Gesture> gesturesList29 = _Database29.AvailableGestures;


            for (int x = 0; x < gesturesList1.Count; x++)
            {
                Gesture g1 = gesturesList1[x];
                if (g1.Name.Equals("Intro_Right"))
                {
                    _Source.AddGesture(g1);
                }
                if (g1.Name.Equals("Intro_Left"))
                {
                    _Source.AddGesture(g1);
                }
            }

            for (int x = 0; x < gesturesList2.Count; x++)
            {
                Gesture g2 = gesturesList2[x];
                if (g2.Name.Equals("Onigiri_Right"))
                {
                    _Source.AddGesture(g2);
                }
                if (g2.Name.Equals("Onigiri_Left"))
                {
                    _Source.AddGesture(g2);
                }
            }

            for (int x = 0; x < gesturesList3.Count; x++)
            {
                Gesture g3 = gesturesList3[x];
                if (g3.Name.Equals("Move_on_Right"))
                {
                    _Source.AddGesture(g3);
                }
                if (g3.Name.Equals("Move_on_Left"))
                {
                    _Source.AddGesture(g3);
                }
            }

            for (int x = 0; x < gesturesList4.Count; x++)
            {
                Gesture g4 = gesturesList4[x];
                if (g4.Name.Equals("Naja"))
                {
                    _Source.AddGesture(g4);
                }
            }

            for (int x = 0; x < gesturesList5.Count; x++)
            {
                Gesture g5 = gesturesList5[x];
                if (g5.Name.Equals("Bangloey"))
                {
                    _Source.AddGesture(g5);
                }
            }

            for (int x = 0; x < gesturesList6.Count; x++)
            {
                Gesture g6 = gesturesList6[x];
                if (g6.Name.Equals("Nidnid"))
                {
                    _Source.AddGesture(g6);
                }
            }

            for (int x = 0; x < gesturesList7.Count; x++)
            {
                Gesture g7 = gesturesList7[x];
                if (g7.Name.Equals("ChoeyMoey"))
                {
                    _Source.AddGesture(g7);
                }
            }

            for (int x = 0; x < gesturesList8.Count; x++)
            {
                Gesture g8 = gesturesList8[x];
                if (g8.Name.Equals("TakeUpArm_Right"))
                {
                    _Source.AddGesture(g8);
                }
                if (g8.Name.Equals("TakeUpArm_Left"))
                {
                    _Source.AddGesture(g8);
                }
            }

            for (int x = 0; x < gesturesList9.Count; x++)
            {
                Gesture g9 = gesturesList9[x];
                if (g9.Name.Equals("DrawBigHeart"))
                {
                    _Source.AddGesture(g9);
                }
            }

            for (int x = 0; x < gesturesList10.Count; x++)
            {
                Gesture g10 = gesturesList10[x];
                if (g10.Name.Equals("Yeah"))
                {
                    _Source.AddGesture(g10);
                }
            }

            for (int x = 0; x < gesturesList11.Count; x++)
            {
                Gesture g11 = gesturesList11[x];
                if (g11.Name.Equals("TourPai"))
                {
                    _Source.AddGesture(g11);
                }
            }

            for (int x = 0; x < gesturesList12.Count; x++)
            {
                Gesture g12 = gesturesList12[x];
                if (g12.Name.Equals("Tummada"))
                {
                    _Source.AddGesture(g12);
                }
            }

            for (int x = 0; x < gesturesList13.Count; x++)
            {
                Gesture g13 = gesturesList13[x];
                if (g13.Name.Equals("Move_down_Left"))
                {
                    _Source.AddGesture(g13);
                }
                if (g13.Name.Equals("Move_down_Right"))
                {
                    _Source.AddGesture(g13);
                }
            }

            for (int x = 0; x < gesturesList14.Count; x++)
            {
                Gesture g14 = gesturesList14[x];
                if (g14.Name.Equals("Down_leg_Left"))
                {
                    _Source.AddGesture(g14);
                }
                if (g14.Name.Equals("Down_leg_Right"))
                {
                    _Source.AddGesture(g14);
                }
            }

            for (int x = 0; x < gesturesList15.Count; x++)
            {
                Gesture g15 = gesturesList15[x];
                if (g15.Name.Equals("LoveorNot_Left"))
                {
                    _Source.AddGesture(g15);
                }
            }

            for (int x = 0; x < gesturesList16.Count; x++)
            {
                Gesture g16 = gesturesList16[x];
                if (g16.Name.Equals("ComeOn"))
                {
                    _Source.AddGesture(g16);
                }
            }

            for (int x = 0; x < gesturesList17.Count; x++)
            {
                Gesture g17 = gesturesList17[x];
                if (g17.Name.Equals("LetsCookie"))
                {
                    _Source.AddGesture(g17);
                }
            }

            for (int x = 0; x < gesturesList18.Count; x++)
            {
                Gesture g18 = gesturesList18[x];
                if (g18.Name.Equals("Koisuru_Left"))
                {
                    _Source.AddGesture(g18);
                }
                if (g18.Name.Equals("Koisuru_Right"))
                {
                    _Source.AddGesture(g18);
                }
            }

            for (int x = 0; x < gesturesList19.Count; x++)
            {
                Gesture g19 = gesturesList19[x];
                if (g19.Name.Equals("FurtuneCookies"))
                {
                    _Source.AddGesture(g19);
                }
            }

            for (int x = 0; x < gesturesList20.Count; x++)
            {
                Gesture g20 = gesturesList20[x];
                if (g20.Name.Equals("LetsWish_Left"))
                {
                    _Source.AddGesture(g20);
                }
                if (g20.Name.Equals("LetsWish_Right"))
                {
                    _Source.AddGesture(g20);
                }
            }

            for (int x = 0; x < gesturesList21.Count; x++)
            {
                Gesture g21 = gesturesList21[x];
                if (g21.Name.Equals("HenWing"))
                {
                    _Source.AddGesture(g21);
                }
            }

            for (int x = 0; x < gesturesList22.Count; x++)
            {
                Gesture g22 = gesturesList22[x];
                if (g22.Name.Equals("Heyhey"))
                {
                    _Source.AddGesture(g22);
                }
            }

            for (int x = 0; x < gesturesList23.Count; x++)
            {
                Gesture g23 = gesturesList23[x];
                if (g23.Name.Equals("Clap"))
                {
                    _Source.AddGesture(g23);
                }
            }

            for (int x = 0; x < gesturesList24.Count; x++)
            {
                Gesture g24 = gesturesList24[x];
                if (g24.Name.Equals("Up_down"))
                {
                    _Source.AddGesture(g24);
                }
            }

            for (int x = 0; x < gesturesList25.Count; x++)
            {
                Gesture g25 = gesturesList25[x];
                if (g25.Name.Equals("Hairoo"))
                {
                    _Source.AddGesture(g25);
                }
            }

            for (int x = 0; x < gesturesList26.Count; x++)
            {
                Gesture g26 = gesturesList26[x];
                if (g26.Name.Equals("Rotate"))
                {
                    _Source.AddGesture(g26);
                }
            }

            for (int x = 0; x < gesturesList27.Count; x++)
            {
                Gesture g27 = gesturesList27[x];
                if (g27.Name.Equals("End"))
                {
                    _Source.AddGesture(g27);
                }
            }

            for (int x = 0; x < gesturesList28.Count; x++)
            {
                Gesture g28 = gesturesList28[x];
                if (g28.Name.Equals("Point_Left"))
                {
                    _Source.AddGesture(g28);
                }
                if (g28.Name.Equals("Point_Right"))
                {
                    _Source.AddGesture(g28);
                }
            }

            for (int x = 0; x < gesturesList29.Count; x++)
            {
                Gesture g29 = gesturesList29[x];
                if (g29.Name.Equals("Side"))
                {
                    _Source.AddGesture(g29);
                }
            }
        }
    }
예제 #28
0
    //public event EventHandler<GestureEventArgs> onGestureDetectedProgress;

    /// <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)
    {
        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
        //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.Equals(this.seatedGestureName))
        //        {
        //            this.vgbFrameSource.AddGesture(gesture);
        //        }
        //    }
        //}
        //var databasePath = Path.Combine(Application.streamingAssetsPath, this.Level1DB);
        //using (VisualGestureBuilderDatabase database = VisualGestureBuilderDatabase.Create(databasePath))
        //{
        //    foreach (Gesture gesture in database.AvailableGestures)
        //    {

        //        if (gesture.Name.Equals(this.SeedName))
        //        {
        //            this.vgbFrameSource.AddGesture(gesture);
        //        }

        //        if (gesture.Name.Equals(this.RainName))
        //        {
        //            this.vgbFrameSource.AddGesture(gesture);
        //        }
        //    }
        //}
        var databasePath2 = Path.Combine(Application.streamingAssetsPath, this.Level1DB2);

        using (VisualGestureBuilderDatabase database = VisualGestureBuilderDatabase.Create(databasePath2))
        {
            foreach (Gesture gesture in database.AvailableGestures)
            {
                if (gesture.Name.Equals(this.PutName))
                {
                    this.vgbFrameSource.AddGesture(gesture);
                }

                if (gesture.Name.Equals(this.DigName))
                {
                    this.vgbFrameSource.AddGesture(gesture);
                }

                if (gesture.Name.Equals(this.SeedName))
                {
                    this.vgbFrameSource.AddGesture(gesture);
                }

                if (gesture.Name.Equals(this.RainName))
                {
                    this.vgbFrameSource.AddGesture(gesture);
                }
            }
        }

        /*
         * var databasePath3 = Path.Combine(Application.streamingAssetsPath, this.BridgeDB);
         * using (VisualGestureBuilderDatabase database = VisualGestureBuilderDatabase.Create(databasePath3))
         * {
         *  // 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.BridgeName))
         *      {
         *          this.vgbFrameSource.AddGesture(gesture);
         *      }
         *
         *      if (gesture.Name.Equals(this.BridgeDownName))
         *      {
         *          this.vgbFrameSource.AddGesture(gesture);
         *      }
         *
         *      if (gesture.Name.Equals(this.BridgeProgressName))
         *      {
         *          this.vgbFrameSource.AddGesture(gesture);
         *      }
         *  }
         * }
         */
    }
예제 #29
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;

            // 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 (gesture.Name.Equals(this.seatedGestureName))
             *      {
             *          this.vgbFrameSource.AddGesture(gesture);
             *      }
             *  }
             * }
             */

            using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(this.gestureDatabase))
            {
                Console.WriteLine("read success");
                // 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
                //this.vgbFrameSource.AddGestures(database.AvailableGestures);
                Console.WriteLine(database.AvailableGesturesCount);

                foreach (Gesture gesture in database.AvailableGestures)
                {
                    Console.WriteLine(gesture.Name);
                    if (gesture.Name.Equals(this.waveGestureName))
                    {
                        Console.WriteLine("wave");
                        this.vgbFrameSource.AddGesture(gesture);
                    }
                    if (gesture.Name.Equals(this.paperGestureName))
                    {
                        Console.WriteLine("paper");
                        this.vgbFrameSource.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.timestamp   = Time.realtimeSinceStartup;

                        data.isDiscrete   = (gesture.GestureType == GestureType.Discrete);
                        data.isContinuous = (gesture.GestureType == GestureType.Continuous);

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

        return(true);
    }