title: Get Pixel Color From Kinect Depth Stream
body: <p>I am currently having a bit of difficulty trying to find the color of a specific pixel from a Kinect Depth Stream.  The code below is what I am using to calculate the color of the pixel at (100, 100).</p>
  
  <p>I have a feeling that my logic is flawed somewhere (perhaps when calculating the index into colorPixels that I want)</p>
  
  <p>colorPixels and depthPixels are declared as follows:</p>
  
  <pre><code>colorFrame.CopyPixelDataTo(colorPixels); //colorPixels is a byte[]
  depthFrame.CopyDepthImagePixelDataTo(depthPixels); //depthPixels is a DepthImagePixel[]
  </code></pre>
  
  <p>I calculate the rgb value of the pixel at 100,100 in the depth stream as follows:</p>
  
  <pre><code>DepthImagePoint ballDepthPoint = new DepthImagePoint();
  int ballPosX = 100;
  int ballPosY = 100;
  int blueTotal = 0, greenTotal = 0, redTotal = 0;
  
  ColorImagePoint ballColorPoint;
  
  //build a depth point to translate to a color point
  ballDepthPoint.X = ballPosX;
  ballDepthPoint.Y = ballPosY;
  ballDepthPoint.Depth = this.depthPixels[ballDepthPoint.X * ballDepthPoint.Y].Depth;
  
  //work out the point on the color image from this depth point
  ballColorPoint = this.sensor.CoordinateMapper.MapDepthPointToColorPoint(this.sensor.DepthStream.Format, ballDepthPoint, this.sensor.ColorStream.Format);
  
  //extract the rgb values form the color pixels array
  blueTotal += (int)colorPixels[(ballColorPoint.X * ballColorPoint.Y * colorFrame.BytesPerPixel)];
  greenTotal += (int)colorPixels[(ballColorPoint.X * ballColorPoint.Y * colorFrame.BytesPerPixel) + 1];
  redTotal += (int)colorPixels[(ballColorPoint.X * ballColorPoint.Y * colorFrame.BytesPerPixel) + 2];
  
  System.Console.WriteLine("The ball found is " + redTotal + "," + blueTotal + "," + greenTotal + " which is " + Helper.ColorChooser(redTotal, greenTotal, blueTotal)); 
  </code></pre>
  
  <p>The ColorChooser method is as follows:</p>
  
  <pre><code>public static String ColorChooser(int r, int g, int b)
      {
  
          if (r &gt;= g &amp;&amp; r &gt;= b)
          {
              return "RED";
          }
          else if (b &gt;= g &amp;&amp; b &gt;= r)
          {
              return "BLUE";
          }
          else
              return "GREEN";
      }
  </code></pre>
  
  <p>If you need any more information/code let me know.</p>
  
  <p>Many Thanks,</p>
  
  <p>Dave McB</p>