Exemplo n.º 1
0
        void DepthCamera_DataReceived(object sender, DepthCamera.DataReceivedEventArgs e)
        {
            if (lockedDepth)
            {
                return;
            }

            if (depthFrameCount % (30 / frameRate) != 1)
            {
                depthFrameCount++;
                return;
            }

            lockedDepth = true;

            short[] image = new short[e.DepthMap.Width * e.DepthMap.Height];
            short[] depth = new short[e.DepthMap.Width * e.DepthMap.Height];
            int     idx   = 0;

            for (int i = 0; i < e.DepthMap.Width * e.DepthMap.Height * 2; i += 2)
            {
                short pixel = Marshal.ReadInt16(e.DepthMap.DataPointer, i);
                depth[idx] = pixel;
                // Convert to little endian.
                pixel        = IPAddress.HostToNetworkOrder(pixel);
                image[idx++] = pixel;
            }

            this.Dispatcher.Invoke(
                new Action(
                    delegate()
            {
                _depthImage.Source = BitmapSource.Create(
                    e.DepthMap.Width,
                    e.DepthMap.Height,
                    96,
                    96, PixelFormats.Gray16, null, image, e.DepthMap.Width * 2);
            }));

            this.kinectWriterQueue.Enqueue(new Tuple <KinectRawCompositeFrame, DateTime>(new KinectRawCompositeFrame(depth, lastImageData), DateTime.Now));

            depthFrameCount++;

            lockedDepth = false;
        }
Exemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender">
 /// A <see cref="System.Object"/>
 /// </param>
 /// <param name="e">
 /// A <see cref="DepthCamera.DataReceivedEventArgs"/>
 /// </param>
 private void HandleKinectDepthCameraDataReceived(object sender, DepthCamera.DataReceivedEventArgs e)
 {
     this.previewControl.HandleDepthBackBufferUpdate();
     this.kinect.DepthCamera.DataBuffer = this.previewControl.DepthBackBuffer;
 }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender">
        /// A <see cref="System.Object"/>
        /// </param>
        /// <param name="e">
        /// A <see cref="DepthCamera.DataReceivedEventArgs"/>
        /// </param>
        private void HandleDepthDataReceived(object sender, DepthCamera.DataReceivedEventArgs e)
        {
            if (this.kinect == null || this.kinect.IsOpen == false)
            {
                return;
            }
            if ((DateTime.Now - this.depthLastFrame).TotalMilliseconds >= 1000)
            {
                this.depthFPS        = this.depthFrameCount;
                this.depthFrameCount = 0;
                this.depthLastFrame  = DateTime.Now;
            }
            else
            {
                this.depthFrameCount++;
            }

            try
            {
                // Swap mid and back
                unsafe
                {
                    byte * ptrMid  = (byte *)this.depthHandleMid.AddrOfPinnedObject();
                    Int16 *ptrBack = (Int16 *)this.depthHandleBack.AddrOfPinnedObject();
                    int    dim     = 640 * 480;
                    int    i       = 0;
                    for (i = 0; i < dim; i++)
                    {
                        Int16 pval = (Int16)this.gamma[ptrBack[i]];
                        Int16 lb   = (Int16)(pval & 0xff);
                        switch (pval >> 8)
                        {
                        case 0:
                            *ptrMid++ = 255;
                            *ptrMid++ = (byte)(255 - lb);
                            *ptrMid++ = (byte)(255 - lb);
                            break;

                        case 1:
                            *ptrMid++ = 255;
                            *ptrMid++ = (byte)lb;
                            *ptrMid++ = 0;
                            break;

                        case 2:
                            *ptrMid++ = (byte)(255 - lb);
                            *ptrMid++ = 255;
                            *ptrMid++ = 0;
                            break;

                        case 3:
                            *ptrMid++ = 0;
                            *ptrMid++ = 255;
                            *ptrMid++ = (byte)lb;
                            break;

                        case 4:
                            *ptrMid++ = 0;
                            *ptrMid++ = (byte)(255 - lb);
                            *ptrMid++ = 255;
                            break;

                        case 5:
                            *ptrMid++ = 0;
                            *ptrMid++ = 0;
                            *ptrMid++ = (byte)(255 - lb);
                            break;

                        default:
                            *ptrMid++ = 0;
                            *ptrMid++ = 0;
                            *ptrMid++ = 0;
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }