Exemplo n.º 1
0
 public DepthDataChangedEvent DepthDataChanged; // Depth data change
 protected virtual void DepthDataChange(DepthDataChangeEventArgs e)
 {
     if (DepthDataChanged != null)
     {
         DepthDataChanged(this, e);
     }
 }
Exemplo n.º 2
0
 // Event Handler for DepthFrameReady events
 // (A new frame of DepthStream data is available)
 private void KinectDepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
 {
     // Get the current DepthImageFrame
     using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
     {
         if (depthFrame != null)
         {
             try
             {
                 // Get the depth data from the DepthImageFrame
                 depthFrame.CopyDepthImagePixelDataTo(depthStreamData);
                 int minDepth = depthFrame.MinDepth;
                 int maxDepth = depthFrame.MaxDepth;
                 // Loop through each pixel and convert to RGB
                 int colorPixelIndex = 0;
                 for (int i = 0; i < depthStreamData.Length; ++i)
                 {
                     short depth     = depthStreamData[i].Depth;
                     byte  intensity = (byte)(depth >= minDepth && depth <= maxDepth ? depth : 0);
                     depthRgbData[colorPixelIndex++] = intensity;
                     depthRgbData[colorPixelIndex++] = intensity;
                     depthRgbData[colorPixelIndex++] = intensity;
                     colorPixelIndex++;
                 }
                 // Write the converted depth data to the depthBitmap image
                 depthBitmap.WritePixels(new Int32Rect(0, 0, depthBitmap.PixelWidth, depthBitmap.PixelHeight), depthRgbData, depthBitmap.PixelWidth * sizeof(int), 0);
                 // Dispatch the DepthDataChange event
                 DepthDataChangeEventArgs d = new DepthDataChangeEventArgs(depthStreamData, depthRgbData);
                 DepthDataChange(d);
             }
             catch (NullReferenceException ex)
             {
                 Console.WriteLine(ex.TargetSite + " - " + ex.Message);
             }
         }
     }
 }
Exemplo n.º 3
0
 // Event Handler for DepthFrameReady events
 // (A new frame of DepthStream data is available)
 private void KinectDepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
 {
     // Get the current DepthImageFrame
     using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
     {
         if (depthFrame != null)
         {
             try
             {
                 // Get the depth data from the DepthImageFrame
                 depthFrame.CopyDepthImagePixelDataTo(depthStreamData);
                 int minDepth = depthFrame.MinDepth;
                 int maxDepth = depthFrame.MaxDepth;
                 // Loop through each pixel and convert to RGB
                 int colorPixelIndex = 0;
                 for (int i = 0; i < depthStreamData.Length; ++i)
                 {
                     short depth = depthStreamData[i].Depth;
                     byte intensity = (byte)(depth >= minDepth && depth <= maxDepth ? depth : 0);
                     depthRgbData[colorPixelIndex++] = intensity;
                     depthRgbData[colorPixelIndex++] = intensity;
                     depthRgbData[colorPixelIndex++] = intensity;
                     colorPixelIndex++;
                 }
                 // Write the converted depth data to the depthBitmap image
                 depthBitmap.WritePixels(new Int32Rect(0, 0, depthBitmap.PixelWidth, depthBitmap.PixelHeight), depthRgbData, depthBitmap.PixelWidth * sizeof(int), 0);
                 // Dispatch the DepthDataChange event
                 DepthDataChangeEventArgs d = new DepthDataChangeEventArgs(depthStreamData, depthRgbData);
                 DepthDataChange(d);
             }
             catch (NullReferenceException ex)
             {
                 Console.WriteLine(ex.TargetSite + " - " + ex.Message);
             }
         }
     }
 }
Exemplo n.º 4
0
 protected virtual void DepthDataChange(DepthDataChangeEventArgs e)
 {
     if (DepthDataChanged != null)
     {
         DepthDataChanged(this, e);
     }
 }
Exemplo n.º 5
0
 // Event Handler for changes in Depth data
 // Allows for direct access to the depth (and converted RGB) data
 private void DepthDataChange(object sender, DepthDataChangeEventArgs e)
 {
     // TO-DO: Is the rgbData returning anything useful?
     Console.WriteLine("Here's the first depth (rgb) byte: " + e.rgbData[e.rgbData.Length/4].ToString());
 }
Exemplo n.º 6
0
 // Event Handler for changes in Depth data
 // Allows for direct access to the depth (and converted RGB) data
 private void DepthDataChange(object sender, DepthDataChangeEventArgs e)
 {
     // TO-DO: Is the rgbData returning anything useful?
     Console.WriteLine("Here's the first depth (rgb) byte: " + e.rgbData[e.rgbData.Length / 4].ToString());
 }