コード例 #1
0
 void LoadTriGestureDetector()
 {
     using (Stream recordStream = File.Open(triKBPath, FileMode.OpenOrCreate))
     {
         triangleGestureRecognizer = new TemplatedGestureDetector("Triangle", recordStream);
         triangleGestureRecognizer.DisplayCanvas      = gesturesCanvas;
         triangleGestureRecognizer.OnGestureDetected += OnGestureDetected;
     }
 }
コード例 #2
0
        void LoadCircleGestureDetector()
        {
            Stream recordStream = File.Open(circleKBPath, FileMode.OpenOrCreate);

            circleGestureRecognizer = new TemplatedGestureDetector("Circle", recordStream);
            circleGestureRecognizer.TraceTo(gesturesCanvas, Colors.Red);
            circleGestureRecognizer.OnGestureDetected += OnGestureDetected;

            templates.ItemsSource = circleGestureRecognizer.LearningMachine.Paths;
        }
コード例 #3
0
        void LoadCircleGestureDetector()
        {
            using (Stream recordStream = File.Open(circleKBPath, FileMode.OpenOrCreate))
            {
                circleGestureRecognizer = new TemplatedGestureDetector("Circle", recordStream);
                circleGestureRecognizer.DisplayCanvas      = gesturesCanvas;
                circleGestureRecognizer.OnGestureDetected += OnGestureDetected;

                MouseController.Current.ClickGestureDetector = circleGestureRecognizer;
            }
        }
コード例 #4
0
        void LoadEatDetector()
        {
            using (Stream recordStream = File.Open(eatPath, FileMode.OpenOrCreate))
            {
                eatRecognizer = new TemplatedGestureDetector("재미있다", recordStream);
                eatRecognizer.DisplayCanvas      = gesturesCanvas;
                eatRecognizer.OnGestureDetected += OnGestureDetected;

                MouseController.Current.ClickGestureDetector = eatRecognizer;
            }
        }
コード例 #5
0
        void LoadGoDetector()
        {
            using (Stream recordStream = File.Open(goKBPath, FileMode.OpenOrCreate))
            {
                goRecognizer = new TemplatedGestureDetector("가다", recordStream);
                goRecognizer.DisplayCanvas      = gesturesCanvas;
                goRecognizer.OnGestureDetected += OnGestureDetected;

                MouseController.Current.ClickGestureDetector = goRecognizer;
            }
        }
コード例 #6
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;
            }
        }
コード例 #7
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;
            }
        }
コード例 #8
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;
            }
        }
コード例 #9
0
        /// <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();
        }