Exemplo n.º 1
0
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (studio != null)
            {
                studio.Stop();
                studio = null;
            }

            if (writer != null)
            {
                writer.Stop();
                writer = null;
            }

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

            if (kinect != null)
            {
                kinect.Close();
                kinect = null;
            }
        }
Exemplo n.º 2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                // Sensor
                kinect = KinectSensor.GetDefault();
                kinect.Open();

                // Coordinate Mapper
                coordinateMapper = kinect.CoordinateMapper;

                // Multi Reader
                FrameSourceTypes types = FrameSourceTypes.Color
                                         | FrameSourceTypes.Depth
                                         | FrameSourceTypes.Infrared
                                         | FrameSourceTypes.Body;
                multiFrameReader = kinect.OpenMultiSourceFrameReader(types);
                multiFrameReader.MultiSourceFrameArrived += MultiFrameArrived;

                // Description
                colorFrameDescription = kinect.ColorFrameSource.CreateFrameDescription(colorFormat);
                colorRect             = new Int32Rect(0, 0, colorFrameDescription.Width, colorFrameDescription.Height);
                colorStride           = colorFrameDescription.Width * (int)colorFrameDescription.BytesPerPixel;
                colorBuffer           = new byte[colorFrameDescription.LengthInPixels * colorFrameDescription.BytesPerPixel];

                depthFrameDescription = kinect.DepthFrameSource.FrameDescription;
                depthRect             = new Int32Rect(0, 0, depthFrameDescription.Width, depthFrameDescription.Height);
                depthStride           = depthFrameDescription.Width;
                depthBuffer           = new ushort[depthFrameDescription.LengthInPixels];
                buffer = new byte[depthFrameDescription.LengthInPixels];

                infraredFrameDescription = kinect.InfraredFrameSource.FrameDescription;
                infraredRect             = new Int32Rect(0, 0, infraredFrameDescription.Width, infraredFrameDescription.Height);
                infraredStride           = infraredFrameDescription.Width * (int)infraredFrameDescription.BytesPerPixel;
                infraredBuffer           = new ushort[infraredFrameDescription.LengthInPixels];

                bodies = new Body[kinect.BodyFrameSource.BodyCount];

                // Bitmap
                colorBitmap    = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96, 96, PixelFormats.Bgra32, null);
                depthBitmap    = new WriteableBitmap(depthFrameDescription.Width, depthFrameDescription.Height, 96, 96, PixelFormats.Gray8, null);
                infraredBitmap = new WriteableBitmap(infraredFrameDescription.Width, infraredFrameDescription.Height, 96, 96, PixelFormats.Gray16, null);

                Color.Source    = colorBitmap;
                Depth.Source    = depthBitmap;
                Infrared.Source = infraredBitmap;

                // Kinect Studio
                studio = new KinectStudio();

                // Data Writer
                writer = new DataWriter();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Close();
            }
        }