/// <summary>
        /// Preps the kinect for color, depth, and skeleton if a sensor is detected. 
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            foreach (var sensor in KinectSensor.KinectSensors)
            {
                if (sensor.Status == KinectStatus.Connected)
                {
                    this.sensor = sensor;
                    break;
                }
            }

            if (this.sensor != null)
            {
                // Kinect settings
                this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);

                this.sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
                this.sensor.DepthStream.Range = DepthRange.Near;

                this.sensor.SkeletonStream.Enable(
                    new TransformSmoothParameters()
                    {
                        Smoothing = 0.5f,
                        Correction = 0.1f,
                        Prediction = 0.5f,
                        JitterRadius = 0.1f,
                        MaxDeviationRadius = 0.1f
                    });
                this.sensor.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated;
                this.sensor.SkeletonStream.EnableTrackingInNearRange = true;

                // Set up GestureRecognizer --> GestureMapper --> Action chain
                this.recognizer = new GestureRecognizer();
                Helper.LoadRecognizer(this.recognizer);
                this.mapper = new GestureMapper();
                this.recognizer.GestureReady += this.mapper.MapGesture2Action;

                // Allocate space to put the pixels we'll receive
                this.depthImageData = new DepthImagePixel[this.sensor.DepthStream.FramePixelDataLength];
                this.depthImageColor = new byte[this.sensor.DepthStream.FramePixelDataLength * sizeof(int)];
                this.surfaceMatrix = new int[this.sensor.DepthStream.FramePixelDataLength * sizeof(int)];

                // Initialize the bitmap we'll display on-screen
                this.depthBitmap = new WriteableBitmap(this.sensor.DepthStream.FrameWidth,
                                                       this.sensor.DepthStream.FrameHeight,
                                                       96.0,
                                                       96.0,
                                                       PixelFormats.Bgr32,
                                                       null);

                // Set the depth image we display to point to the bitmap where we'll put the image data
                this.depthImage.Source = this.depthBitmap;

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

                // Set up ActionArea
                Helper.LoadActionArea(this.actionArea);
                this.actionArea.maxLength = this.sensor.DepthStream.FramePixelDataLength;
                this.actionArea.ConfirmCallBack += actionArea_ConfirmCallBack;
                this.actionArea.InitActionArea();

                // Set up surface
                this.surfaceDetection.surface = Helper.LoadSurface();
                this.surfaceDetection.testSurface = false;
                fingerTracking.surface = surfaceDetection.surface;
                if (this.surfaceDetection.surface == null)
                {
                    InitializeEnvironmentButton_Click(null, null);
                }
                else
                {
                    DebugMsg(surfaceDetection.surface.ToString());
                    b_InitializeEnvironment = true;
                    this.sensor.DepthFrameReady += InitializeEnvironment;
                }

            }

            if (this.sensor == null)
            {
                DebugMsg("No Kinect ready. Please plug in a kinect");
            }
        }
Exemple #2
0
        /// <summary>
        /// Preps the kinect for color, depth, and skeleton if a sensor is detected.
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            foreach (var sensor in KinectSensor.KinectSensors)
            {
                if (sensor.Status == KinectStatus.Connected)
                {
                    this.sensor = sensor;
                    break;
                }
            }

            if (this.sensor != null)
            {
                // Kinect settings
                this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);

                this.sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
                this.sensor.DepthStream.Range = DepthRange.Near;

                this.sensor.SkeletonStream.Enable(
                    new TransformSmoothParameters()
                {
                    Smoothing          = 0.5f,
                    Correction         = 0.1f,
                    Prediction         = 0.5f,
                    JitterRadius       = 0.1f,
                    MaxDeviationRadius = 0.1f
                });
                this.sensor.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated;
                this.sensor.SkeletonStream.EnableTrackingInNearRange = true;

                // Set up GestureRecognizer --> GestureMapper --> Action chain
                this.recognizer = new GestureRecognizer();
                Helper.LoadRecognizer(this.recognizer);
                this.mapper = new GestureMapper();
                this.recognizer.GestureReady += this.mapper.MapGesture2Action;

                // Allocate space to put the pixels we'll receive
                this.depthImageData  = new DepthImagePixel[this.sensor.DepthStream.FramePixelDataLength];
                this.depthImageColor = new byte[this.sensor.DepthStream.FramePixelDataLength * sizeof(int)];
                this.surfaceMatrix   = new int[this.sensor.DepthStream.FramePixelDataLength * sizeof(int)];

                // Initialize the bitmap we'll display on-screen
                this.depthBitmap = new WriteableBitmap(this.sensor.DepthStream.FrameWidth,
                                                       this.sensor.DepthStream.FrameHeight,
                                                       96.0,
                                                       96.0,
                                                       PixelFormats.Bgr32,
                                                       null);

                // Set the depth image we display to point to the bitmap where we'll put the image data
                this.depthImage.Source = this.depthBitmap;

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

                // Set up ActionArea
                Helper.LoadActionArea(this.actionArea);
                this.actionArea.maxLength        = this.sensor.DepthStream.FramePixelDataLength;
                this.actionArea.ConfirmCallBack += actionArea_ConfirmCallBack;
                this.actionArea.InitActionArea();

                // Set up surface
                this.surfaceDetection.surface     = Helper.LoadSurface();
                this.surfaceDetection.testSurface = false;
                fingerTracking.surface            = surfaceDetection.surface;
                if (this.surfaceDetection.surface == null)
                {
                    InitializeEnvironmentButton_Click(null, null);
                }
                else
                {
                    DebugMsg(surfaceDetection.surface.ToString());
                    b_InitializeEnvironment      = true;
                    this.sensor.DepthFrameReady += InitializeEnvironment;
                }
            }

            if (this.sensor == null)
            {
                DebugMsg("No Kinect ready. Please plug in a kinect");
            }
        }