Ejemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        _kinect = KinectSensor.GetDefault();                                                                             // Recogemos el kinect por defecto

        _gestureDatabase    = VisualGestureBuilderDatabase.Create(Application.streamingAssetsPath + "/ImaGestures.gbd"); // Recoge la base de datos
        _gestureFrameSource = VisualGestureBuilderFrameSource.Create(_kinect, 0);                                        // Array de gestos ????

        if (_gestureDatabase != null)
        {
            Debug.Log("Base de datos cargada con �xito");
        }
        else
        {
            Debug.LogError("Error al cargar la base de datos");
        }

        /*
         *  Anyade los gestos
         *  TODO: DEFINIR LOS NOMBRES DE ESTOS GESTOS DE MIERDA
         */
        foreach (var gesture in _gestureDatabase.AvailableGestures)
        {
            _gestureFrameSource.AddGesture(gesture);

            switch (gesture.Name)
            {
            case "Menu_Right":
                _gesture1 = gesture;
                break;

            case "Alas":
                _gesture2 = gesture;
                break;

            default:
                Debug.Log(gesture.Name);
                break;
            }
        }

        _gestureFrameReader          = _gestureFrameSource.OpenReader();
        _gestureFrameReader.IsPaused = 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)
            {
                if (this.vgbFrameReader != null)
                {
                    this.vgbFrameReader.FrameArrived -= this.Reader_GestureFrameArrived;
                    this.vgbFrameReader.Dispose();
                    this.vgbFrameReader = null;
                }

                if (this.vgbFrameSource != null)
                {
                    this.vgbFrameSource.TrackingIdLost -= this.Source_TrackingIdLost;
                    this.vgbFrameSource.Dispose();
                    this.vgbFrameSource = null;
                }
            }
        }
Ejemplo n.º 3
0
    private void FinishVisualGestures()
    {
        if (vgbFrameReader != null)
        {
            vgbFrameReader.Dispose();
            vgbFrameReader = null;
        }

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

        if (gestureData != null)
        {
            gestureData.Clear();
        }
    }
Ejemplo n.º 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;

            // 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 (gestureNames.Contains(gesture.Name))
                    {
                        this.vgbFrameSource.AddGesture(gesture);
                    }
                }
            }
            //<~>
            mc = new MusicController(gestureNames);
        }
Ejemplo n.º 5
0
        private void InitializeGestureRecognition()
        {
            GestureFrameSource = new VisualGestureBuilderFrameSource(KinectConnection.KSensor, 0);
            GestureFrameSource.TrackingIdLost += OnTrackingIdLost;

            if (GestureFrameSource != null)
            {
                GestureFrameReader = GestureFrameSource.OpenReader();
                GestureFrameReader.FrameArrived += OnGestureFrameArrived;
            }

            using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(this.Database))
            {
                foreach (Gesture g in database.AvailableGestures)
                {
                    GestureFrameSource.AddGesture(g);
                    GesturesDictionary.Add(g.Name, g);
                }
            }
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="kinectSensor"></param>
        /// <param name="i"></param>
        /// <param name="c"></param>
        public PostureDetector(KinectSensor kinectSensor, int i, System.Windows.Controls.Canvas c)
        {
            index  = i;
            canvas = c;

            vgbFrameSource = new VisualGestureBuilderFrameSource(kinectSensor, 0);
            vgbFrameSource.TrackingIdLost += Source_TrackingIdLost;

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

            using (VisualGestureBuilderDatabase db = new VisualGestureBuilderDatabase(GESTURE_DB))
            {
                vgbFrameSource.AddGestures(db.AvailableGestures);
            }
        }
Ejemplo n.º 7
0
        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;
        }
Ejemplo n.º 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, 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);
             *   }
             * }*/
        }
Ejemplo n.º 9
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);
                    }
                }
            }
        }
Ejemplo n.º 10
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);
                }
            }
        }
Ejemplo n.º 11
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();
 }
Ejemplo n.º 12
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
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Initializes a new instance of the GestureDetector class along with the gesture frame source and reader
        /// </summary>
        /// <param name="kinectSensor">Active sensor to initialize the VisualGestureBuilderFrameSource object with</param>
        /// <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);
            }
        }
Ejemplo n.º 14
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;
        }
Ejemplo n.º 15
0
    // Use this for initialization
    void Start()
    {
        fasterhappened = false;
        slowerhappened = false;


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

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

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

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

            // Load all gestures
            IList <Gesture> gesturesList = _Database.AvailableGestures;
            for (int g = 0; g < gesturesList.Count; g++)
            {
                Gesture gesture = gesturesList[g];
                _Source.AddGesture(gesture);
            }
        }
    }
        internal override void 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);
                }
            }
        }
Ejemplo n.º 17
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;
        }
Ejemplo n.º 18
0
    // 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;
    }
Ejemplo n.º 19
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);
            }
        }
Ejemplo n.º 20
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;
    }
Ejemplo n.º 21
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);
            }
        }
    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);
                }
            }
        }
    }
Ejemplo n.º 23
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;
 }
Ejemplo n.º 25
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;
        }
Ejemplo n.º 26
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);
            }
        }
Ejemplo n.º 27
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);
                    }
                }
            }
        }
        /// <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);
                }
            }
        }
Ejemplo n.º 29
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;
            });
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Reads from the configuration file and returns a list of gestures that are linked together
        /// </summary>
        /// <param name="aVgbSource">A VGB frame source which stores references to gestures in a database</param>
        /// <returns>A list of PseudoGestures that represent Linked Gestures</returns>
        public List <PseudoGesture> linkGestures(VisualGestureBuilderFrameSource aVgbSource)
        {
            List <PseudoGesture> returnList = new List <PseudoGesture>();
            GestureLink          tempLink   = null;
            bool ignored = false;

            foreach (Gesture gest in aVgbSource.Gestures)
            {
                ignored  = false;
                tempLink = null;
                if (conf != null)
                {
                    //check if the current gesture should be ignored
                    foreach (string s in conf.ignoreList)
                    {
                        if (s.Equals(gest.Name))
                        {
                            ignored = true;
                            break;
                        }
                    }

                    //check if the current gesture from VGBsource is included in a link from the config
                    if (!ignored)
                    {
                        tempLink = conf.findGestureInLink(gest.Name);//null if not included
                    }
                }
                //was it included?
                if (tempLink != null)
                {
                    string gestureType = "Discrete";
                    if (gest.GestureType == GestureType.Continuous)
                    {
                        gestureType = "Continuous";
                    }
                    if (tempLink.gestureType != null)
                    {
                        //Make sure that the discrete gestures get added to discrete links, and continuous with continuous
                        if (gestureType.Equals(tempLink.gestureType, StringComparison.OrdinalIgnoreCase))
                        {
                            //check if any elements are added to the returnList incase of when the current link was already added
                            if (returnList.Count > 0)
                            {
                                //if the list doesn't contain a gesture that represents a link, add a gesture to work as the link
                                if (!returnList.Exists(x => x.gestureName.Equals(tempLink.commonName)))
                                {
                                    returnList.Add(new PseudoGesture(tempLink.commonName, gest.GestureType));
                                }
                            }
                            else
                            {
                                //if the returnList is empty, we don't have to check if the link already has been added as gesture
                                returnList.Add(new PseudoGesture(tempLink.commonName, gest.GestureType));
                            }
                        }
                        else
                        {
                            System.Console.WriteLine("Configuration error, a discrete gesture was added to a continuous link or vice versa.");
                            evHandler.raiseMessageEvent(1, "Configuration error, a discrete gesture was added to a continuous link or vice versa.");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Configuration error, a link didn't have a defined gestureType.");
                        evHandler.raiseMessageEvent(1, "Configuration error, a link didn't have a defined gestureType.");
                    }
                }
                else
                {
                    //if the gesture wasn't included in a link, we can add it directly to the returnlist
                    if (!ignored)
                    {
                        returnList.Add(new PseudoGesture(gest.Name, gest.GestureType));
                    }
                }
            }
            return(returnList);
        }