Example #1
0
 /// <summary>
 /// Constructor that allocates a pinned buffer
 /// </summary>
 /// <param name="dataFormat">
 /// A <see cref="VideoCamera.DataFormatOption"/>
 /// </param>
 /// <param name="allocateBuffer">
 /// 
 /// </param>
 internal ImageMap(VideoCamera.DataFormatOption dataFormat)
 {
     this.Width = VideoCamera.DataFormatDimensions[dataFormat].X;
     this.Height = VideoCamera.DataFormatDimensions[dataFormat].Y;
     this.DataFormat = dataFormat;
     this.Data = new byte[VideoCamera.DataFormatSizes[dataFormat]];
     this.dataHandle = GCHandle.Alloc(this.Data, GCHandleType.Pinned);
     this.DataPointer = this.dataHandle.AddrOfPinnedObject();
 }
Example #2
0
 /// <summary>
 /// Constructor where a buffer allocation isn't needed
 /// </summary>
 /// <param name="dataFormat">
 /// A <see cref="VideoCamera.DataFormatOption"/>
 /// </param>
 /// <param name="bufferPointer">
 /// A <see cref="IntPtr"/>
 /// </param>
 internal ImageMap(VideoCamera.DataFormatOption dataFormat, IntPtr bufferPointer)
 {
     this.Width = VideoCamera.DataFormatDimensions[dataFormat].X;
     this.Height = VideoCamera.DataFormatDimensions[dataFormat].Y;
     this.DataFormat = dataFormat;
     this.Data = null;
     this.dataHandle = default(GCHandle);
     this.DataPointer = bufferPointer;
 }
Example #3
0
 public static extern int freenect_set_video_format(IntPtr device, VideoCamera.DataFormatOption rgbFormat);
Example #4
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="sender">
		/// A <see cref="System.Object"/>
		/// </param>
		/// <param name="e">
		/// A <see cref="VideoCamera.DataReceivedEventArgs"/>
		/// </param>
		private void HandleKinectVideoCameraDataReceived (object sender, VideoCamera.DataReceivedEventArgs e)
		{
			this.previewControl.HandleVideoBackBufferUpdate();
			this.kinect.VideoCamera.DataBuffer = this.previewControl.VideoBackBuffer;
		}
		/// <summary>
		/// Sets the VideoCamera's data format. Support function for VideoCamera.DataFormat property.
		/// </summary>
		/// <param name="format">
		/// Format to change the video camera to
		/// </param>
		protected void SetDataFormat(VideoCamera.DataFormatOption format)
		{
			// change imagemap that's waiting cause format has changed
			this.UpdateNextFrameImageMap();
			
			// change format
			int result = KinectNative.freenect_set_video_format(this.parentDevice.devicePointer, format);
			if(result != 0)
			{
				throw new Exception("Could not switch to video format " + format + ". Error Code: " + result);
			}
			this.dataFormat = format;
		}
    void VideoCamera_DataReceived(object sender, VideoCamera.DataReceivedEventArgs e)
    {
      if (lockedRGB)
        return;

      //video camera runs at double the fps of the depth so we always have image data available.
      if (videoFrameCount % (30 / (frameRate * 2)) != 1)
      {
          videoFrameCount++;
          return;
      }

      lockedRGB = true;

      lastImageData = e.Image.Data;

      this.Dispatcher.Invoke(
        new Action(
          delegate()
          {
            _colorImage.Source = BitmapSource.Create(
              e.Image.Width, 
              e.Image.Height, 
              96, 
              96, 
              PixelFormats.Rgb24, 
              null, 
              e.Image.Data, 
              e.Image.Width * 3);
          }));

      videoFrameCount++;

      lockedRGB = false;
    }
Example #7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender">
        /// A <see cref="System.Object"/>
        /// </param>
        /// <param name="e">
        /// A <see cref="VideoCamera.DataReceivedEventArgs"/>
        /// </param>
        private void HandleVideoDataReceived(object sender, VideoCamera.DataReceivedEventArgs e)
        {
            if(this.kinect == null || this.kinect.IsOpen == false)
            {
                return;
            }
            if((DateTime.Now - this.videoLastFrame).TotalMilliseconds >= 1000)
            {
                this.videoFPS = this.videoFrameCount;
                this.videoFrameCount = 0;
                this.videoLastFrame = DateTime.Now;
            }
            else
            {
                this.videoFrameCount++;
            }

            // Swap mid and back
            GCHandle tmp = rgbHandleBack;
            rgbHandleMid = rgbHandleBack;
            rgbHandleBack = tmp;

            // Set kinect video camera's buffer to new back buffer
            this.kinect.VideoCamera.DataBuffer = rgbHandleBack.AddrOfPinnedObject();
        }