示例#1
0
 /// <summary>
 /// Constructor where a buffer allocation isn't needed
 /// </summary>
 /// <param name="dataFormat">
 /// A <see cref="DepthCamera.DataFormatOption"/>
 /// </param>
 /// <param name="bufferPointer">
 /// A <see cref="IntPtr"/>
 /// </param>
 internal DepthMap(DepthCamera.DataFormatOption dataFormat, IntPtr bufferPointer)
 {
     this.Width = DepthCamera.DataFormatDimensions[dataFormat].X;
     this.Height = DepthCamera.DataFormatDimensions[dataFormat].Y;
     this.DataFormat = dataFormat;
     this.Data = null;
     this.dataHandle = default(GCHandle);
     this.DataPointer = bufferPointer;
 }
示例#2
0
 /// <summary>
 /// Constructor that allocates a pinned buffer
 /// </summary>
 /// <param name="dataFormat">
 /// A <see cref="DepthCamera.DataFormatOption"/>
 /// </param>
 /// <param name="allocateBuffer">
 /// 
 /// </param>
 internal DepthMap(DepthCamera.DataFormatOption dataFormat)
 {
     this.Width = DepthCamera.DataFormatDimensions[dataFormat].X;
     this.Height = DepthCamera.DataFormatDimensions[dataFormat].Y;
     this.DataFormat = dataFormat;
     this.Data = new byte[DepthCamera.DataFormatSizes[dataFormat]];
     this.dataHandle = GCHandle.Alloc(this.Data, GCHandleType.Pinned);
     this.DataPointer = this.dataHandle.AddrOfPinnedObject();
 }
示例#3
0
 public static extern int freenect_set_depth_format(IntPtr device, DepthCamera.DataFormatOption depthFormat);
示例#4
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;
		}
示例#5
0
		/// <summary>
		/// Sets the DepthCameras's data format. Support function for DepthCamera.DataFormat
		/// </summary>
		/// <param name="format">
		/// A <see cref="DepthCamera.DataFormatOptions"/>
		/// </param>
		private void SetDataFormat(DepthCamera.DataFormatOption format)
		{
			// change depth map that's waiting cause format has changed
			this.UpdateNextFrameDepthMap();
			
			int result = KinectNative.freenect_set_depth_format(this.parentDevice.devicePointer, format);
			if(result != 0)
			{
				throw new Exception("Could not switch to depth format " + format + ". Error Code: " + result);
			}
			this.dataFormat = format;
		}
示例#6
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;
    }
示例#7
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());
            }
        }