Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void SensorDepthFrameReady(object sender, DepthImageFrameReadyEventArgs e){
- using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
- {
- if (depthFrame != null)
- {
- // Copy the pixel data from the image to a temporary array
- depthFrame.CopyDepthImagePixelDataTo(this.depthPixels);
- // Get the min and max reliable depth for the current frame
- int minDepth = depthFrame.MinDepth;
- int maxDepth = depthFrame.MaxDepth;
- // Convert the depth to RGB
- int colorPixelIndex = 0;
- for (int i = 0; i < this.depthPixels.Length; ++i)
- {
- // Get the depth for this pixel
- short depth = depthPixels[i].Depth;
- if (depth > 2000) depth = 0; //ive put this here just to test background elimination
- byte intensity = (byte)(depth >= minDepth && depth <= maxDepth ? depth : 0);
- //WHAT IS THIS LINE ABOVE DOING?
- // Write out blue byte
- this.colorPixels[colorPixelIndex++] = intensity;
- // Write out green byte
- this.colorPixels[colorPixelIndex++] = intensity;
- // Write out red byte
- this.colorPixels[colorPixelIndex++] = intensity;
- // We're outputting BGR, the last byte in the 32 bits is unused so skip it
- // If we were outputting BGRA, we would write alpha here.
- ++colorPixelIndex;
- }
- // Write the pixel data into our bitmap
- this.colorBitmap.WritePixels(
- new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),
- this.colorPixels,
- this.colorBitmap.PixelWidth * sizeof(int),
- 0);
- }
- }
- }
- byte intensity = (byte)(depth >= minDepth && depth <= maxDepth ? depth : 0);
- //WHAT IS THIS LINE ABOVE DOING?
- byte intensity;
- if (depth >= minDepth && depth <= maxDepth)
- {
- intensity = (byte)depth;
- }
- else
- {
- intensity = 0;
- }
- Color tint = Color.FromArgb(0, 255, 0) // Green
- // Write out blue byte
- this.colorPixels[colorPixelIndex++] = intensity * tint.B;
- // Write out green byte
- this.colorPixels[colorPixelIndex++] = intensity * tint.G;
- // Write out red byte
- this.colorPixels[colorPixelIndex++] = intensity * tint.R;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement