示例#1
0
 protected virtual void OnDepthFrameReceived(KinectBase.DepthFrameEventArgs e)
 {
     if (DepthFrameReceived != null)
     {
         DepthFrameReceived(this, e);
     }
 }
示例#2
0
        protected virtual void OnDepthFrameReceived(KinectBase.DepthFrameEventArgs e)
        {
            if (DepthFrameReceived != null)
            {
                DepthFrameReceived(this, e);
            }

            //Put the image array back in the image pool
            depthImagePool.PutObject(e.image);
        }
示例#3
0
        void depthReader_FrameArrived(object sender, DepthFrameArrivedEventArgs e)
        {
            using (DepthFrame depthFrame = e.FrameReference.AcquireFrame())
            {
                if (depthFrame != null)
                {
                    FrameDescription desc = depthFrame.FrameDescription;

                    KinectBase.DepthFrameEventArgs depthE = new KinectBase.DepthFrameEventArgs();
                    depthE.bytesPerPixel = 2;  //This is fixed to 2 because we are using a ushort to hold the depth image
                    depthE.perPixelExtra = 2;  //We always have an extra two bytes per pixel because we are storing a Gray16 in a bgr32 format
                    depthE.height        = desc.Height;
                    depthE.width         = desc.Width;
                    depthE.kinectID      = kinectID;
                    depthE.timeStamp     = depthFrame.RelativeTime;
                    depthE.reliableMin   = (float)depthFrame.DepthMinReliableDistance / (float)ushort.MaxValue;
                    depthE.reliableMax   = (float)depthFrame.DepthMaxReliableDistance / (float)ushort.MaxValue;

                    //Get all the data for the depth, and store the bytes for the Gray16 in the blue and green channels of a bgr32
                    IntPtr depthImagePtr = Marshal.AllocHGlobal((int)(depthE.bytesPerPixel * desc.LengthInPixels));
                    depthFrame.CopyFrameDataToIntPtr(depthImagePtr, (uint)depthE.bytesPerPixel * desc.LengthInPixels);
                    //depthE.image = new byte[desc.LengthInPixels * (depthE.perPixelExtra + depthE.bytesPerPixel)];
                    depthE.image = depthImagePool.GetObject();
                    unsafe
                    {
                        fixed(byte *pDst = depthE.image)
                        {
                            ushort *pD = (ushort *)pDst;
                            ushort *pS = (ushort *)depthImagePtr.ToPointer();

                            for (int n = 0; n < desc.LengthInPixels; n++)
                            {
                                *pD = *pS;
                                pD += 2;
                                pS++;
                            }
                        }
                    }
                    Marshal.FreeHGlobal(depthImagePtr);

                    OnDepthFrameReceived(depthE);
                }
            }
        }
示例#4
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);
                }
            }
        }
示例#5
0
        void depthReader_FrameArrived(object sender, DepthFrameArrivedEventArgs e)
        {
            using (DepthFrame depthFrame = e.FrameReference.AcquireFrame())
            {
                if (depthFrame != null)
                {
                    FrameDescription desc = depthFrame.FrameDescription;

                    KinectBase.DepthFrameEventArgs depthE = new KinectBase.DepthFrameEventArgs();
                    depthE.bytesPerPixel = 2;  //This is fixed to 2 because we are using a ushort to hold the depth image
                    depthE.perPixelExtra = 2;  //We always have an extra two bytes per pixel because we are storing a Gray16 in a bgr32 format
                    depthE.height = desc.Height;
                    depthE.width = desc.Width;
                    depthE.kinectID = kinectID;
                    depthE.timeStamp = depthFrame.RelativeTime;
                    depthE.reliableMin = (float)depthFrame.DepthMinReliableDistance / (float)ushort.MaxValue;
                    depthE.reliableMax = (float)depthFrame.DepthMaxReliableDistance / (float)ushort.MaxValue;

                    //Get all the data for the depth, and store the bytes for the Gray16 in the blue and green channels of a bgr32
                    IntPtr depthImagePtr = Marshal.AllocHGlobal((int)(depthE.bytesPerPixel * desc.LengthInPixels));
                    depthFrame.CopyFrameDataToIntPtr(depthImagePtr, (uint)depthE.bytesPerPixel * desc.LengthInPixels);
                    //depthE.image = new byte[desc.LengthInPixels * (depthE.perPixelExtra + depthE.bytesPerPixel)];
                    depthE.image = depthImagePool.GetObject();
                    unsafe
                    {
                        fixed (byte* pDst = depthE.image)
                        {
                            ushort* pD = (ushort*)pDst;
                            ushort* pS = (ushort*)depthImagePtr.ToPointer();

                            for (int n = 0; n < desc.LengthInPixels; n++)
                            {
                                *pD = *pS;
                                pD += 2;
                                pS++;
                            }
                        }
                    }
                    Marshal.FreeHGlobal(depthImagePtr);

                    OnDepthFrameReceived(depthE);
                }
            }
        }
示例#6
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);
                }
            }
        }