Advertisement
Guest User

S/O ? 19274287

a guest
Jun 3rd, 2014
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.03 KB | None | 0 0
  1.  
  2.         public byte[] depthFrame32;
  3.         public short[] depthPixelData;
  4.         const int BlueIndex = 0;
  5.         const int GreenIndex = 1;
  6.         const int RedIndex = 2;
  7.        
  8.         private byte[] ConvertDepthFrame(short[] depthFrame, DepthImageStream depthStream)
  9.         {
  10.             //Run through the depth frame making the correlation between the two arrays
  11.             for (int i16 = 0, i32 = 0; i16 < depthFrame.Length && i32 < this.depthFrame32.Length; i16++, i32 += 4)
  12.             {
  13.                 // Console.WriteLine(i16 + "," + i32);
  14.                 //We don’t care about player’s information here, so we are just going to rule it out by shifting the value.
  15.                 int realDepth = depthFrame[i16] >> DepthImageFrame.PlayerIndexBitmaskWidth;
  16.                 //We are left with 13 bits of depth information that we need to convert into an 8 bit number for each pixel.
  17.                 //There are hundreds of ways to do this. This is just the simplest one.
  18.                 //Lets create a byte variable called Distance.
  19.                 //We will assign this variable a number that will come from the conversion of those 13 bits.
  20.                 byte Distance = 0;
  21.                 //XBox Kinects (default) are limited between 800mm and 4096mm.
  22.                 int MinimumDistance = 800;
  23.                 int MaximumDistance = 4096;
  24.                 //XBox Kinects (default) are not reliable closer to 800mm, so let’s take those useless measurements out.
  25.                 //If the distance on this pixel is bigger than 800mm, we will paint it in its equivalent gray
  26.                 if (realDepth > MinimumDistance)
  27.                 {
  28.                     //Convert the realDepth into the 0 to 255 range for our actual distance.
  29.                     //Use only one of the following Distance assignments
  30.                     //White = Far
  31.                     //Black = Close
  32.                     //Distance = (byte)(((realDepth – MinimumDistance) * 255 / (MaximumDistance-MinimumDistance)));
  33.                     //White = Close
  34.                     //Black = Far
  35.                     Distance = (byte)(255 - ((realDepth - MinimumDistance) * 255 / (MaximumDistance - MinimumDistance)));
  36.                     //Use the distance to paint each layer (R G &  of the current pixel.
  37.                     //Painting R, G and B with the same color will make it go from black to gray
  38.                     this.depthFrame32[i32 + RedIndex] = (byte)(Distance);
  39.                     this.depthFrame32[i32 + GreenIndex] = (byte)(Distance);
  40.                     this.depthFrame32[i32 + BlueIndex] = (byte)(Distance);
  41.                 }
  42.                 //If we are closer than 800mm, the just paint it red so we know this pixel is not giving a good value
  43.                 else
  44.                 {
  45.                     this.depthFrame32[i32 + RedIndex] = 0;
  46.                     this.depthFrame32[i32 + GreenIndex] = 0;
  47.                     this.depthFrame32[i32 + BlueIndex] = 0;
  48.                 }
  49.             }
  50.             return depthFrame32;
  51.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement