Пример #1
0
        private void Clean()
        {
            if (_skeletonManager != null)
            {
                _skeletonManager = null;
            }

            if (_colorManager != null)
            {
                _colorManager = null;
            }

            if (_swipeGestureRecognizer != null)
            {
                _swipeGestureRecognizer.OnGestureDetected -= OnGestureDetected;
                _swipeGestureRecognizer = null;
            }

            if (_kinectSensor != null)
            {
                _kinectSensor.SkeletonStream.Disable();
                _kinectSensor.ColorStream.Disable();
                _kinectSensor.SkeletonFrameReady -= KinectSensor_SkeletonFrameReady;
                _kinectSensor.ColorFrameReady -= KinectSensor_ColorFrameReady;
                _kinectSensor.Stop();
                _kinectSensor = null;
            }
        }
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            sensor = KinectSensor.KinectSensors.FirstOrDefault();
            swipeGestureRecognizer = new SwipeGestureDetector();
            swipeGestureRecognizer.OnGestureDetected += swipeGestureRecognizer_OnGestureDetected;

            if (sensor == null)
            {
                MessageBox.Show("This application requires a Kinect sensor.");
                this.Close();
            }

            sensor.Start();

            sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
            sensor.ColorFrameReady += new EventHandler <ColorImageFrameReadyEventArgs>(sensor_ColorFrameReady);

            sensor.DepthStream.Enable(DepthImageFormat.Resolution320x240Fps30);
            sensor.SkeletonStream.Enable();
            sensor.SkeletonFrameReady += new EventHandler <SkeletonFrameReadyEventArgs>(sensor_SkeletonFrameReady);

            sensor.ElevationAngle = 0;

            Application.Current.Exit += new ExitEventHandler(Current_Exit);

            InitializeSpeechRecognition();
        }
        private void Initialize()
        {
            if (kinectSensor == null)
            {
                return;
            }

            audioManager = new AudioStreamManager(kinectSensor.AudioSource);
            audioBeamAngle.DataContext = audioManager;

            kinectSensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
            kinectSensor.ColorFrameReady += kinectRuntime_ColorFrameReady;

            kinectSensor.DepthStream.Enable(DepthImageFormat.Resolution320x240Fps30);
            kinectSensor.DepthFrameReady += kinectSensor_DepthFrameReady;

            kinectSensor.SkeletonStream.Enable(new TransformSmoothParameters
            {
                Smoothing          = 0.5f,
                Correction         = 0.5f,
                Prediction         = 0.5f,
                JitterRadius       = 0.05f,
                MaxDeviationRadius = 0.04f
            });
            kinectSensor.SkeletonFrameReady += kinectRuntime_SkeletonFrameReady;

            swipeGestureRecognizer = new SwipeGestureDetector();
            swipeGestureRecognizer.OnGestureDetected += OnGestureDetected;

            skeletonDisplayManager = new SkeletonDisplayManager(kinectSensor, kinectCanvas);

            kinectSensor.Start();

            LoadCircleGestureDetector();
            LoadLetterTPostureDetector();
            LoadTriGestureDetector();
            //Add Triangle

            nuiCamera = new BindableNUICamera(kinectSensor);

            elevationSlider.DataContext = nuiCamera;

            voiceCommander = new VoiceCommander("record", "stop");
            voiceCommander.OrderDetected += voiceCommander_OrderDetected;

            StartVoiceCommander();

            kinectDisplay.DataContext = colorManager;

            parallelCombinedGestureDetector = new ParallelCombinedGestureDetector();
            parallelCombinedGestureDetector.OnGestureDetected += OnGestureDetected;
            parallelCombinedGestureDetector.Add(swipeGestureRecognizer);
            parallelCombinedGestureDetector.Add(circleGestureRecognizer);
            parallelCombinedGestureDetector.Add(triangleGestureRecognizer);

            //Add Triangle
            //Media_Loaded();
            //btnVideo_Click();
        }
Пример #4
0
    /// this creates the correct object implementation of the tracker
    /// @return the tracker object. 
    protected override NIGestureTracker GetNewTrackerObject()
    {
        SwipeGestureDetector gestureTracker = new SwipeGestureDetector(m_swipeDirection, m_useRightHand,
            m_swipeMinimalLength, m_swipeMaximalHeight, m_swipeMininalDuration, m_swipeMaximalDuration,
            m_detectionThreshHold);

        return gestureTracker;
    }
Пример #5
0
 /// <summary>
 /// This suite consolidates all of the detectors to one suite
 /// so clients only have to add one overall detector to get all of the
 /// gestures
 /// </summary>
 public GestureSuite()
 {
     _circleDetector = new CircleGestureDetector();
     _swipeGestureRecognizer = new SwipeGestureDetector();
     _twoHandedDetector = new TwoHandedGestureDetector(_algorithmicPostureRecognizer);
     _circleDetector.OnGestureDetected += GestureDelegate;
     _swipeGestureRecognizer.OnGestureDetected += GestureDelegate;
     _twoHandedDetector.OnGestureDetected += GestureDelegate;
     _prevGesture = DateTime.MinValue;
 }
Пример #6
0
 // Use this for initialization
 void Start()
 {
     animator             = GetComponent <Animator>();
     swipeGestureDetector = new SwipeGestureDetector();
     turnRight            = Animator.StringToHash("GoRight");
     turnLeft             = Animator.StringToHash("GoLeft");
     slide        = Animator.StringToHash("Slide");
     runSpeed     = Animator.StringToHash("RunSpeed");
     isRunning    = false;
     isPlayerDead = false;
     speed        = 1.0f;
 }
Пример #7
0
        private void InitializeKinectRegion()
        {
            // KinectRegion is an invisible control, so no use tabbing to it.
            this.IsTabStop = false;

            // TODO: Remove this code
            // Gesture recognition initialization
            //this.leftHandSwipeGestureRecogniser = new SwipeGestureDetector();
            this.rightHandSwipeGestureRecogniser = new SwipeGestureDetector();
            //this.leftHandSwipeGestureRecogniser.OnGestureDetected += SwipeGestureDetected;
            this.rightHandSwipeGestureRecogniser.OnGestureDetected += SwipeGestureDetected;

            this.kinectAdapter = new KinectAdapter(this);
            SetKinectRegion(this, this);
        }
Пример #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void SensorChooserOnKinectChanged(object sender, KinectChangedEventArgs args)
        {
            //MessageBox.Show(args.NewSensor == null ? "No Kinect" : args.NewSensor.Status.ToString());
            bool error = false;

            if (args.OldSensor != null)
            {
                try
                {
                    args.OldSensor.DepthStream.Range = DepthRange.Default;
                    args.OldSensor.SkeletonStream.EnableTrackingInNearRange = false;
                    args.OldSensor.DepthStream.Disable();
                    args.OldSensor.SkeletonStream.Disable();
                }
                catch (InvalidOperationException)
                {
                    error = true;
                }
            }
            if (args.NewSensor != null)
            {
                try
                {
                    args.NewSensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
                    args.NewSensor.SkeletonStream.Enable();
                    args.NewSensor.SkeletonFrameReady += this.SensorSkeletonFrameReady;
                    swipeGestureDetector = new SwipeGestureDetector();
                    swipeGestureDetector.OnGestureDetected += OnGestureDetectedSwipe;
                    using (Stream recordStream = File.Open(Path.Combine(Environment.CurrentDirectory, @"Datos\circleKB.save"), FileMode.Open))
                    {
                        circleGestureRecognizer = new TemplatedGestureDetector("Circle", recordStream);
                        circleGestureRecognizer.OnGestureDetected += OnGestureDetectedCircle;
                    }
                    sensor = args.NewSensor;
                }
                catch (InvalidOperationException)
                {
                    error = true;
                }
            }
            if (!error)
            {
                kinectRegion.KinectSensor = args.NewSensor;
            }
        }
Пример #9
0
        private void InitializeKinectManager()
        {
            if (kinectManager.KinectSensor != null && !kinectStartedSucessfully)
            {
                kinectManager.KinectSensor.ColorFrameReady += new EventHandler <ColorImageFrameReadyEventArgs>(KinectSensor_ColorFrameReady);

                this.colorPixels   = new byte[kinectManager.KinectSensor.ColorStream.FramePixelDataLength];
                this.colorBitmap   = new WriteableBitmap(kinectManager.KinectSensor.ColorStream.FrameWidth, kinectManager.KinectSensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);
                this.image1.Source = this.colorBitmap;

                kinectManager.PropertyChanged +=
                    new System.ComponentModel.PropertyChangedEventHandler(kinectManager_PropertyChanged);

                //kinectManager.KinectSensor.ElevationAngle = 15;

                textBoxMessagesCenter.Visibility = System.Windows.Visibility.Collapsed;
                kinectStartedSucessfully         = true;

                kinectManager.DetectMotion = true;
                kinectManager.MotionDetector.MotionDetected +=
                    new EventHandler(motionDetector_MotionDetected);

                kinectManager.FaceTracking = true;
                kinectManager.FaceTracker.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(FaceTracker_PropertyChanged);

                GestureDetector LeftHandSwipeGestureDetector =
                    new SwipeGestureDetector(Microsoft.Kinect.JointType.HandLeft);
                LeftHandSwipeGestureDetector.OnGestureDetected +=
                    new Action <string>(LeftHandSwipeGestureDetector_OnGestureDetected);
                kinectManager.GestureDetectors.Add(LeftHandSwipeGestureDetector);


                PostureDetector PostureDetector =
                    new AlgorithmicPostureDetector();
                PostureDetector.PostureDetected +=
                    new Action <string>(PostureDetector_PostureDetected);
                kinectManager.PostureDetectors.Add(PostureDetector);
            }

            if (!kinectStartedSucessfully)
            {
                textBoxMessagesCenter.Text       = "DISCONNECTED";
                textBoxMessagesCenter.Visibility = System.Windows.Visibility.Visible;
            }
        }
Пример #10
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            sensor = KinectSensor.KinectSensors.First();
            sensor.Start();
            sensor.ColorStream.Enable();
            sensor.DepthStream.Enable();
            sensor.SkeletonStream.Enable();
            Title = sensor.DeviceConnectionId;

            skeletonDisplayManager = new SkeletonDisplayManager(sensor, imageCanvas);

            gestureDetector = new SwipeGestureDetector();
            gestureDetector.DisplayCanvas = imageCanvas;
            gestureDetector.DisplayColor  = Colors.Red;


            sensor.AllFramesReady             += sensor_AllFramesReady;
            gestureDetector.OnGestureDetected += gestureDetector_OnGestureDetected;
        }
Пример #11
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            sensor = KinectSensor.KinectSensors.First();
            sensor.Start();
            sensor.ColorStream.Enable();
            sensor.DepthStream.Enable();
            sensor.SkeletonStream.Enable();
            Title = sensor.DeviceConnectionId;

            skeletonDisplayManager = new SkeletonDisplayManager(sensor, imageCanvas);

            gestureDetector = new ExtendedGestureDetector();
            gestureDetector.DisplayCanvas = mouseCanvas;
            gestureDetector.DisplayColor  = Colors.Red;

            postureDetector = new AlgorithmicPostureDetector();
            postureDetector.PostureDetected += postureDetector_PostureDetected;

            MouseController.Current.ClickGestureDetector = gestureDetector;
            MouseController.Current.ImpostorCanvas       = mouseCanvas;

            sensor.AllFramesReady             += sensor_AllFramesReady;
            gestureDetector.OnGestureDetected += gestureDetector_OnGestureDetected;
        }
Пример #12
0
        /// <summary>
        /// The default constructor.
        /// </summary>
        public SimpleKinectManager()
        {
            KinectManager = new KinectManager();

            KinectManager.PropertyChanged +=
                new System.ComponentModel.PropertyChangedEventHandler(kinectManager_PropertyChanged);

            KinectManager.DetectMotion = true;
            KinectManager.MotionDetector.MotionDetected +=
                new EventHandler(motionDetector_MotionDetected);

            KinectManager.FaceTracking = true;
            KinectManager.FaceTracker.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(FaceTracker_PropertyChanged);

            GestureDetector LeftHandSwipeGestureDetector =
                new SwipeGestureDetector(Microsoft.Kinect.JointType.HandLeft);

            LeftHandSwipeGestureDetector.OnGestureDetected +=
                new Action <string>(SwipeGestureDetector_OnGestureDetected);
            KinectManager.GestureDetectors.Add(LeftHandSwipeGestureDetector);

            GestureDetector RightHandSwipeGestureDetector =
                new SwipeGestureDetector(Microsoft.Kinect.JointType.HandRight);

            RightHandSwipeGestureDetector.OnGestureDetected +=
                new Action <string>(SwipeGestureDetector_OnGestureDetected);
            KinectManager.GestureDetectors.Add(RightHandSwipeGestureDetector);


            PostureDetector LeftHandOverHeadPostureDetector =
                new AlgorithmicPostureDetector();

            LeftHandOverHeadPostureDetector.PostureDetected +=
                new Action <string>(PostureDetector_OnPostureDetected);
            KinectManager.PostureDetectors.Add(LeftHandOverHeadPostureDetector);
        }
Пример #13
0
 // Use this for initialization
 void Start()
 {
     transform.position   = new Vector3(0, transform.position.y, transform.position.z);
     swipeGestureDetector = new SwipeGestureDetector();
 }
Пример #14
0
        private void Initialize()
        {
            if (_kinectSensor == null)
                return;

            _colorManager = new KinectColorStreamManager();
            _skeletonManager = new KinectSkeletonDisplayManager(_kinectSensor, SkeletonCanvas);

            _swipeGestureRecognizer = new SwipeGestureDetector(GesturesCanvas);
            _swipeGestureRecognizer.OnGestureDetected += OnGestureDetected;

            _seated = true;

            KinectDisplay.DataContext = _colorManager;

            _kinectSensor.SkeletonStream.Enable();
            _kinectSensor.SkeletonStream.EnableTrackingInNearRange = _seated;
            _kinectSensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);

            _kinectSensor.SkeletonFrameReady += KinectSensor_SkeletonFrameReady;
            _kinectSensor.ColorFrameReady += KinectSensor_ColorFrameReady;
            _kinectSensor.Start();
        }
Пример #15
0
        /// <summary>
        ///     Execute startup tasks.
        /// </summary>
        /// <param name="sender"> Object sending the event. </param>
        /// <param name="e"> Event arguments. </param>
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            //********************TO DO*************************************
            // Instanciar reconocedores
            // Si es reconocedor Template_Based abrir fichero con templates.
            // Path.Combine(Environment.CurrentDirectory, @"Datos\circleKB.save")
            swipeGestureRecognizer = new SwipeGestureDetector();

            string circleKBPath = Path.Combine(Environment.CurrentDirectory, @"Datos\circleKB.save");

            using (Stream recordStream = File.Open(circleKBPath, FileMode.Open))
            {
                circleGestureRecognizer = new TemplatedGestureDetector("Circle", recordStream);
            }

            //********************TO DO*************************************
            // Añadir los manejadores como listeners de OnGestureDetected
            circleGestureRecognizer.OnGestureDetected += OnGestureDetectedCircle;
            swipeGestureRecognizer.OnGestureDetected  += OnGestureDetectedSwipe;

            // Create the drawing group we'll use for drawing.
            this.drawingGroup = new DrawingGroup();

            // Create an image source that we can use in our image control.
            this.imageSource = new DrawingImage(this.drawingGroup);

            // Display the drawing using our image control.
            Image.Source = this.imageSource;

            // Look through all sensors and start the first connected one.
            // This requires that a Kinect is connected at the time of app startup.
            // To make your app robust against plug/unplug,
            // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit.
            foreach (var potentialSensor in KinectSensor.KinectSensors)
            {
                if (potentialSensor.Status == KinectStatus.Connected)
                {
                    this.sensor = potentialSensor;
                    break;
                }
            }

            if (null != this.sensor)
            {
                this.SetupColorStream();
                this.SetupDepthStream();

                // Turn on the skeleton stream to receive skeleton frames.
                this.sensor.SkeletonStream.Enable();

                // Add an event handler to be called whenever there is new color frame data.
                this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady;

                // Start the sensor!
                try
                {
                    this.sensor.Start();
                }
                catch (IOException)
                {
                    this.sensor = null;
                }
            }

            this.ChangeBackground();

            if (null == this.sensor)
            {
                this.statusBarText.Text = Properties.Resources.NoKinectReady;
            }
        }
Пример #16
0
 // Gestures
 private void InitializeGestures()
 {
     swipeGestureRecognizer = new SwipeGestureDetector();
     swipeGestureRecognizer.OnGestureDetected += OnGestureDetected;
 }
Пример #17
0
        /// <summary>
        /// Execute startup tasks
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            //********************TO DO*************************************
            // Instanciar reconocedores
            // Si es reconocedor Template_Based abrir fichero con templates
            // circleKBPath = Path.Combine(Environment.CurrentDirectory, @"Datos\circleKB.save");
            swipeGestureRecognizer = new SwipeGestureDetector();
            using (Stream recordStream = File.Open(circleKBPath, FileMode.Open))
            {
                circleGestureRecognizer = new TemplatedGestureDetector("Circle", recordStream);
                circleGestureRecognizer.OnGestureDetected += OnGestureDetectedCircle;
            }

            //********************TO DO*************************************
            // Añadir los manejadores como listeners de OnGestureDetected
            swipeGestureRecognizer.OnGestureDetected += OnGestureDetectedSwipe;

            // Create the drawing group we'll use for drawing
            this.drawingGroup = new DrawingGroup();

            // Create an image source that we can use in our image control
            this.imageSource = new DrawingImage(this.drawingGroup);

            // Display the drawing using our image control
            Image_Skeleton.Source = this.imageSource;

            // Look through all sensors and start the first connected one.
            // This requires that a Kinect is connected at the time of app startup.
            // To make your app robust against plug/unplug,
            // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit
            foreach (var potentialSensor in KinectSensor.KinectSensors)
            {
                if (potentialSensor.Status == KinectStatus.Connected)
                {
                    this.sensor = potentialSensor;
                    if (sensor != null)
                    {
                        colorPixels = new byte[sensor.ColorStream.FramePixelDataLength];
                        colorBitmap = new WriteableBitmap(sensor.ColorStream.FrameWidth, sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);
                        sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
                        sensor.ColorFrameReady += SensorColorFrameReady;
                    }
                    break;
                }
            }

            if (null != this.sensor)
            {
                // Turn on the skeleton stream to receive skeleton frames
                this.sensor.SkeletonStream.Enable();

                // Add an event handler to be called whenever there is new color frame data
                this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady;

                try
                {
                    // Iniciamos el sensor
                    this.sensor.Start();
                }
                catch (IOException)
                {
                    this.sensor = null;
                }
            }

            if (null == this.sensor)
            {
                this.statusBarText.Text = Properties.Resources.NoKinectReady;
            }
        }
        /// <summary>
        /// Called at the start when the window is loaded
        /// </summary>
        private void InitializeKinect()
        {
            using (Stream recordStream = File.Open(@"circleKB.save", FileMode.OpenOrCreate))
            {
                this.circleDetector = new TemplatedGestureDetector("Circle", recordStream);
                this.circleDetector.DisplayCanvas      = videoCanvas;
                this.circleDetector.OnGestureDetected += OnHandGesture;
            }

            this.gestureDetector = new SwipeGestureDetector();
            this.gestureDetector.DisplayCanvas      = videoCanvas;
            this.gestureDetector.OnGestureDetected += OnHandGesture;
            ParallelCombinedGestureDetector parallelCombinedGestureDetector = new ParallelCombinedGestureDetector();

            parallelCombinedGestureDetector.OnGestureDetected += OnHandGesture;
            parallelCombinedGestureDetector.DisplayCanvas      = videoCanvas;
            parallelCombinedGestureDetector.Add(circleDetector);
            parallelCombinedGestureDetector.Add(gestureDetector);

            foreach (var potentialSensor in KinectSensor.KinectSensors)
            {
                if (potentialSensor.Status == KinectStatus.Connected)
                {
                    this.kinectSensor = potentialSensor;
                    break;
                }
            }

            if (null != this.kinectSensor)
            {
                // Turning on skeleton stream
                this.kinectSensor.SkeletonStream.Enable();
                this.kinectSensor.SkeletonFrameReady += this.SensorSkeletonFrameReady;

                // Turn on the color stream to receive color frames
                this.kinectSensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);

                // Allocate space to put the pixels we'll receive
                this.colorPixels = new byte[this.kinectSensor.ColorStream.FramePixelDataLength];

                // This is the bitmap we'll display on-screen
                this.colorBitmap = new WriteableBitmap(this.kinectSensor.ColorStream.FrameWidth, this.kinectSensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);

                // Set the image we display to point to the bitmap where we'll put the image data
                this.Image.Source = this.colorBitmap;

                // Add an event handler to be called whenever there is new color frame data
                this.kinectSensor.ColorFrameReady += this.SensorColorFrameReady;

                this.kinectSensor.Start();
            }

            if (null == this.kinectSensor)
            {
                // Connection is failed
                return;
            }

            this.speech = new Speech(this.kinectSensor, grammar, this);
            this.speech.Start();
        }