Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. private void SensorDepthFrameReady(object sender, DepthImageFrameReadyEventArgs e){
  2. using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
  3. {
  4. if (depthFrame != null)
  5. {
  6. // Copy the pixel data from the image to a temporary array
  7. depthFrame.CopyDepthImagePixelDataTo(this.depthPixels);
  8.  
  9. // Get the min and max reliable depth for the current frame
  10. int minDepth = depthFrame.MinDepth;
  11. int maxDepth = depthFrame.MaxDepth;
  12.  
  13. // Convert the depth to RGB
  14. int colorPixelIndex = 0;
  15. for (int i = 0; i < this.depthPixels.Length; ++i)
  16. {
  17. // Get the depth for this pixel
  18. short depth = depthPixels[i].Depth;
  19.  
  20. if (depth > 2000) depth = 0; //ive put this here just to test background elimination
  21.  
  22. byte intensity = (byte)(depth >= minDepth && depth <= maxDepth ? depth : 0);
  23. //WHAT IS THIS LINE ABOVE DOING?
  24.  
  25. // Write out blue byte
  26. this.colorPixels[colorPixelIndex++] = intensity;
  27.  
  28. // Write out green byte
  29. this.colorPixels[colorPixelIndex++] = intensity;
  30.  
  31. // Write out red byte
  32. this.colorPixels[colorPixelIndex++] = intensity;
  33.  
  34. // We're outputting BGR, the last byte in the 32 bits is unused so skip it
  35. // If we were outputting BGRA, we would write alpha here.
  36.  
  37.  
  38. ++colorPixelIndex;
  39. }
  40. // Write the pixel data into our bitmap
  41. this.colorBitmap.WritePixels(
  42. new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),
  43. this.colorPixels,
  44. this.colorBitmap.PixelWidth * sizeof(int),
  45. 0);
  46. }
  47. }
  48. }
  49.  
  50. byte intensity = (byte)(depth >= minDepth && depth <= maxDepth ? depth : 0);
  51. //WHAT IS THIS LINE ABOVE DOING?
  52.  
  53. byte intensity;
  54.  
  55. if (depth >= minDepth && depth <= maxDepth)
  56. {
  57. intensity = (byte)depth;
  58. }
  59. else
  60. {
  61. intensity = 0;
  62. }
  63.  
  64. Color tint = Color.FromArgb(0, 255, 0) // Green
  65.  
  66. // Write out blue byte
  67. this.colorPixels[colorPixelIndex++] = intensity * tint.B;
  68.  
  69. // Write out green byte
  70. this.colorPixels[colorPixelIndex++] = intensity * tint.G;
  71.  
  72. // Write out red byte
  73. this.colorPixels[colorPixelIndex++] = intensity * tint.R;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement