void runtime_DepthFrameReady(object sender, Microsoft.Kinect.DepthImageFrameReadyEventArgs e)
 {
     using (DepthImageFrame frame = e.OpenDepthImageFrame())
     {
         if (frame != null)
         {
             try
             {
                 // Hand data to Interaction framework to be processed
                 this.stream.ProcessDepth(frame.GetRawPixelData(), frame.Timestamp);
             }
             catch (InvalidOperationException ex)
             {
                 // DepthFrame functions may throw when the sensor gets
                 // into a bad state.  Ignore the frame in that case.
             }
         }
     }
 }
Beispiel #2
0
        private void SensorOnDepthFrameReady(object sender, DepthImageFrameReadyEventArgs depthImageFrameReadyEventArgs)
        {
            using (DepthImageFrame depthFrame = depthImageFrameReadyEventArgs.OpenDepthImageFrame())
            {
                if (depthFrame == null)
                {
                    return;
                }

                try
                {
                    _interactionStream.ProcessDepth(depthFrame.GetRawPixelData(), depthFrame.Timestamp);
                }
                catch (InvalidOperationException)
                {
                    // If exception skip frame
                }
            }
        }
Beispiel #3
0
        private void kinect_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
        {
            using (DepthImageFrame frame = e.OpenDepthImageFrame())
            {
                if (frame != null)
                {
                    //Pass the data to the interaction frame for processing
                    if (interactStream != null && frame.Format == DepthImageFormat.Resolution640x480Fps30)
                    {
                        interactStream.ProcessDepth(frame.GetRawPixelData(), frame.Timestamp);
                    }

                    KinectBase.DepthFrameEventArgs depthE = new KinectBase.DepthFrameEventArgs();
                    depthE.kinectID      = this.kinectID;
                    depthE.perPixelExtra = 2;
                    depthE.width         = frame.Width;
                    depthE.height        = frame.Height;
                    depthE.bytesPerPixel = frame.BytesPerPixel;
                    depthE.reliableMin   = (float)frame.MinDepth / (float)ushort.MaxValue;
                    depthE.reliableMax   = (float)frame.MaxDepth / (float)ushort.MaxValue;
                    depthE.timeStamp     = new TimeSpan(frame.Timestamp * 10000); //Convert from milliseconds to ticks and set the time span

                    //The second 2 bytes of the DepthImagePixel structure hold the actual depth as a uint16, so lets get those, and put the data in the blue and green channel of the image
                    //depthE.image = new byte[frame.PixelDataLength * (depthE.perPixelExtra + depthE.bytesPerPixel)];
                    depthE.image = depthImagePool.GetObject();                                                        //Get an image array from the object pool
                    if (depthE.image.Length != frame.PixelDataLength * (depthE.perPixelExtra + depthE.bytesPerPixel)) //If the object is the wrong size, replace it with one that is the right size
                    {
                        depthE.image = new byte[frame.PixelDataLength * (depthE.perPixelExtra + depthE.bytesPerPixel)];
                    }
                    unsafe
                    {
                        //The sizeof() operation is unsafe in this instance, otherwise this would all be safe code
                        IntPtr depthImagePtr = Marshal.AllocHGlobal(sizeof(DepthImagePixel) * frame.PixelDataLength);
                        frame.CopyDepthImagePixelDataTo(depthImagePtr, frame.PixelDataLength);
                        Marshal.Copy(depthImagePtr, depthE.image, 2, depthE.image.Length - 2);
                        Marshal.FreeHGlobal(depthImagePtr);
                    }

                    OnDepthFrameReceived(depthE);
                }
            }
        }
        private void SensorOnDepthFrameReady(object sender, DepthImageFrameReadyEventArgs depthImageFrameReadyEventArgs)
        {
            using (DepthImageFrame depthFrame = depthImageFrameReadyEventArgs.OpenDepthImageFrame())
            {
                if (depthFrame == null)
                {
                    return;
                }

                try
                {
                    interactionStream.ProcessDepth(depthFrame.GetRawPixelData(), depthFrame.Timestamp);
                }
                catch (InvalidOperationException)
                {
                    // DepthFrame functions may throw when the sensor gets
                    // into a bad state.  Ignore the frame in that case.
                }
            }
        }
Beispiel #5
0
        private void OnDepthFrameReady(object o, DepthImageFrameReadyEventArgs df)
        {
            // Console.WriteLine("DepthFrame");
            using (DepthImageFrame depthFrame = df.OpenDepthImageFrame())
            {
                if (depthFrame == null)
                {
                    return;
                }

                try
                {
                    inter_stream.ProcessDepth(depthFrame.GetRawPixelData(), depthFrame.Timestamp);
                }
                catch (InvalidOperationException)
                {
                    // depth frame weirdnesshen the sensor gets
                    Console.WriteLine("Depth Problems");
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// 深度图
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
        {
            if (this.kinectDevice != sender)
            {
                return;
            }

            using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
            {
                if (null != depthFrame)
                {
                    ////深度方块(显示)
                    short[] depthPixelDate = new short[depthFrame.PixelDataLength];
                    depthFrame.CopyPixelDataTo(depthPixelDate);
                    depthImageBitMap.WritePixels(depthImageBitmapRect, depthPixelDate, depthImageStride, 0);
                    // PlayerDepthImage(depthFrame, depthPixelDate);
                    // Hand data to Interaction framework to be processed
                    this.interactionStream.ProcessDepth(depthFrame.GetRawPixelData(), depthFrame.Timestamp);
                }
            }
        }
        /// <summary>
        /// Fires when a depth frame is captured by the Kinect's depth sensor
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void depthSensor_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
        {
            using (DepthImageFrame frame = e.OpenDepthImageFrame())//Opens the depth frame sent along with the event argument
            {
                //Reads out all of the captured depth image pixels to an array
                DepthImagePixel[] depthImagePixels = frame.GetRawPixelData();

                for (int i = 0; i < depthImagePixels.Length; i++)//Loops the captured depth image pixel array 
                {
                    if (depthImagePixels[i].Depth == DefaultDepth)//If the depth (the distance, in millimeters, from the image pixel to the sensor) meets the configured value, then:
                    {
                        //Generates an unqiue obejct ID for the current object
                        DataIdentifier dataIdentifier = new DataIdentifier() { DataUniqueID = Guid.NewGuid().ToString()};

                        //Notifies the receivers
                        base.Notify(dataIdentifier);

                        //break;
                    }
                }
            }
        }
Beispiel #8
0
        void ProcessDepthFrame()
        {
            using (DepthImageFrame dif = this.Chooser.Sensor.DepthStream.OpenNextFrame(0))
            {
                if (dif != null && Chooser != null && Chooser.intStream != null)
                {
                    this.Chooser.intStream.ProcessDepth(dif.GetRawPixelData(), dif.Timestamp);
                }

                if (Chooser != null && dif != null)
                {
                    if (null == this.depthComponent.depthData)
                    {
                        this.depthComponent.depthData = new short[dif.PixelDataLength];

                        this.depthComponent.depthTexture = new Texture2D(
                            this.GraphicsDevice,
                            dif.Width,
                            dif.Height,
                            false,
                            SurfaceFormat.Bgra4444);

                        this.depthComponent.backBuffer = new RenderTarget2D(
                            this.GraphicsDevice,
                            dif.Width,
                            dif.Height,
                            false,
                            SurfaceFormat.Color,
                            DepthFormat.None,
                            this.GraphicsDevice.PresentationParameters.MultiSampleCount,
                            RenderTargetUsage.PreserveContents);
                    }

                    dif.CopyPixelDataTo(this.depthComponent.depthData);
                    this.depthComponent.needToRedrawBackBuffer = true;
                }
            }
        }
        /// <summary>
        /// Process a frame and write it to the bitmap.
        /// </summary>
        public void WriteToBitmap(DepthImageFrame frame)
        {
            if ((null == this.depthBuffer) || (this.depthBuffer.Length != frame.PixelDataLength))
            {
                this.depthBuffer = new DepthImagePixel[frame.PixelDataLength];
                this.colorizedDepthBuffer = new byte[frame.PixelDataLength * 4];
            }

            if (null == WriteableBitmap || WriteableBitmap.Format != PixelFormats.Bgra32)
            {
                this.CreateWriteableBitmap(frame);
            }

            this.depthBuffer = frame.GetRawPixelData();
            
            this.colorizerStrategy.ColorizeDepthPixels(this, this.depthBuffer, this.colorizedDepthBuffer, frame.Width, frame.Height, (int)(frame.Width / WriteableBitmap.Width));

            this.WriteableBitmap.WritePixels(
                new Int32Rect(0, 0, WriteableBitmap.PixelWidth, WriteableBitmap.PixelHeight),
                this.colorizedDepthBuffer,
                (int)(WriteableBitmap.Width * 4),
                0);

            this.SendDepthImageReady(this.WriteableBitmap);
        }